I am trying to create the following query using knex:
SELECT * FROM users group by users.location having users.photo is not null
as follows:
knex("users").groupBy("users.location").having("users.photo", "IS NOT", "Null")
I am getting the following error on this:
The operator IS NOT is not permitted
I've gone through their documentation and couldn't find anything useful.
Knex. raw insert does not return a number of rows inserted to the table. It returns empty array [] But knex.
Knex.js (pronounced /kəˈnɛks/) is a "batteries included" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use.
Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM.
Knex is a SQL query builder, mainly used for Node. js applications with built in model schema creation, table migrations, connection pooling and seeding.
Have you tried:
knex("users").whereNotNull("photo").groupBy("location")
The docs have the answers. There is whereNull
, whereNotNull
, havingNull
, havingNotNull
and so on.
From the DOCS:
havingNull — .havingNull(column)
Adds a havingNull clause to the query.
knex.select('*').from('users').havingNull('email')
Outputs:
select * from `users` having `email` is null
havingNotNull — .havingNotNull(column)
Adds a havingNotNull clause to the query.
knex.select('*').from('users').havingNotNull('email')
Outputs:
select * from `users` having `email` is not null
Give it a try using the knex query lab: http://michaelavila.com/knex-querylab/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With