I am trying to create the following query using knex:
SELECT * FROM users group by users.location having users.photo is not null
knex("users").groupBy("users.location").having("users.photo", "IS NOT", "Null")
The operator IS NOT is not permitted
According to the docs, .havingRaw is what you need:
knex("users").groupBy("users.location").havingRaw("users.photo IS NOT ?, [null]);
On the other hand, do a knex.raw at once unless there is any remaining advantage using the builder on this specific case.