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
Support Joins and Using syntax for PostgreSQL Delete Statement (#4591) #4800
Support Joins and Using syntax for PostgreSQL Delete Statement (#4591) #4800
Conversation
const withSQL = this.with(); | ||
const wheres = this.where(); | ||
// Joins in PG with delete it's not valid, we throw an error and ask to use 'using' | ||
if (this.join().length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converting joins to using transparently is not feasible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean use the joins logic by add 'using' joins types with the 'using()' syntax ?
I think about that but with that implementation I cant throw an error here.
Also we have a join with using syntax inside and I quite afraid about some misunderstand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still on the fence about this, TBH. Considering that many multi-db systems use knex specifically to abstract away db differences, transforming joins to using
here would allow them to avoid having some conditional logic. Is it possible to always transform join
into using
, or you see certain case where that would fail and user would be forced to use using
explicitly anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the argument. I start on 'using' function because of an argument in the original PR about avoid silent converting operations. But in fact, we always do "silent" operations in Knex, especially with oracle, when converting limit/offset functions...
I will rework it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should also keep using
syntax for those who want to be explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I push with implicit joins to 'using' + 'where's syntax and I also keep the actual using syntax too.
@elhigu - are you going to review this? |
ok i just added the fix to local project. |
Would also be helpful to update existing |
I push with more integration tests + one unit test (mixed joins + using notation). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outstanding work on this one!
So implicit method, with usual join methods work:
and will generate the query with 'using' and 'where' to work in PostgreSQL.
It will general the same query that explicit form:
I dont want to go in intrusive and complex implementation (no new kind of joins...) so I just add small using method in querybuilder and make all the specific logic in PG files.Finally I implements both implicit joins conversion and explicit form.I choose to make a specific implement of Delete that dont allow joins in Delete and throw an error when user try to make the joins with Delete statement => "Joins with delete query isn't valid in PostgreSQL, use 'using' with 'where' functions instead."Specific implement of Delete for PostgreSQL that convert joins in 'using' + 'wheres'