Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knex('table').having({ field: 'value' }).del() silently deletes ALL rows! #4070

Open
reza-akbari opened this issue Oct 20, 2020 · 1 comment

Comments

@reza-akbari
Copy link

Environment

Knex version: 0.21.5
Database + version: postgres 13.0
OS: alpine

Bug

Explain what kind of behaviour you are getting and how you think it should do:

running

knex('table').having('some_relation_count', '>', 0).del()

silently removes "having" and results in

delete from "table"

I executed a similar select query to check the effected rows and then executed the delete query.
fortunately I had backups!

I think knex could throw an error or let the database throw a syntax error by not removing the "having" part
Thank you for this great project

@elhigu
Copy link
Member

elhigu commented Oct 21, 2020

This actually might be a bug... I suppose knex should compile something like:

delete from "table" having "some_relation_count" > 0;

even if query would be invalid. At least with select when one uses having it is included to the query https://runkit.com/embed/bsltlf434drq

That error throwing might be potential feature request. Knex maybe could throw an error if query contains parts that were ignored in compilation... though I'm not sure if that is viable to implement, since compilers should then keep track which parts were actually used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants