I'm building a node js app with Objection + knex. I was wondering if that is possible to access the declared property in the Model when doing the request ? That way, TS is everywhere. In the doc, every time the Model property are inside string.
Here is my model
export class AgencyModel extends BaseModel {
static tableName = 'agency'
readonly id!: number
agency_name!: string
}
Here is the way im requesting it for eg
return AgencyModel.query()
.modify((queryBuilder) => {
if(agencyParameters.search) {
const searchFilter = (agencyParameters.search).toLowerCase()
queryBuilder.where('agency_name', 'ILike', `%${searchFilter}%`)
}
})
.paginate(agencyParameters.getLimit(), agencyParameters.getOffset())
But we can see that I have to write 'agency_name' in string. I would like to be able to do something like this
queryBuilder.where(AgencyModel.agency_name, 'ILike', `%${searchFilter}%`)
Is there a way I can achieve this ? That way, the day made a change in my DB, one column name, I can update the model and all the code will follow + i have typescript to avoid make mistake inside my requests.
Thanks for reading.