I'm a PHP Developer and for a new project I decided to use a node.js backend. So I'm quite new to that.
I'm using knex.js to handle my database connection and manipulate the data. F.ex I have the following query:
let gastronomies = await knex
.from('user')
.innerJoin('profile', 'user.id', 'profile.user_id')
.where('user.status', 1);
If the client passes an additional variable to the function it should be used as another query param
if(args.lat) {
gastronomies = await knex
.from('user')
.innerJoin('profile', 'user.id', 'profile.user_id')
.where('user.status', 1)
.where('lat', 'like', args.lat); //there it is
}
I'd like to chain the methods but it is not working at all. This is what I came up with:
let gastronomies = await knex
.from('user')
.select('*', {key: 'user.id'})
.innerJoin('profile', 'user.id', 'profile.user_id')
.where('user.status', 1);
if(args.lat)
gastronomies.where('lat', 'like', args.lat);
But it says that gastronomies does not have a method called "where". Any suggestions?