add support for joins on delete #89

Closed
imle wants to merge 1 commits from add-delete-join-support into master
Contributor
No description provided.
Author
Contributor

@lunny is the failing build due to something I've done? It looks like the build is not respecting the go.mod go version?

@lunny is the failing build due to something I've done? It looks like the build is not respecting the go.mod go version?
Owner

Looks like golang.org/x/tools v0.1.12 now require go 1.18

Looks like golang.org/x/tools v0.1.12 now require go 1.18
Author
Contributor

Should I address that in this PR or would you rather it be addressed in a separate PR and I rebase onto that?

Should I address that in this PR or would you rather it be addressed in a separate PR and I rebase onto that?
lunny reviewed 2022-08-10 03:55:51 +00:00
@ -25,2 +26,3 @@
return b.cond.WriteTo(w)
if len(b.joins) > 0 {
parts := strings.Split(b.from, " ")
Owner

b.from?

b.from?
Author
Contributor

The goal here is when one or more joins are specified, we want to get the table alias or name for the following syntax:

DELETE t1 FROM table1 t1 LEFT JOIN t2 ON t1.id = t2.id WHERE t2.id IS NULL;
DELETE table1 FROM table1 LEFT JOIN t2 ON table1.id = t2.id WHERE t2.id IS NULL;

It is required to specify the table you want the deletes to occur in when referencing multiple tables.
https://dev.mysql.com/doc/refman/8.0/en/delete.html

In this line of code, I am getting the last part of the b.from (which is the table name or its alias) and specifying to use it for deletes.

This approach means there is no way to specify that you want to delete from t1 and t2, but short of changing the Delete() definition and behavior, I don't see a great way to do so.

The goal here is when one or more joins are specified, we want to get the table alias or name for the following syntax: ``` DELETE t1 FROM table1 t1 LEFT JOIN t2 ON t1.id = t2.id WHERE t2.id IS NULL; DELETE table1 FROM table1 LEFT JOIN t2 ON table1.id = t2.id WHERE t2.id IS NULL; ``` It is required to specify the table you want the deletes to occur in when referencing multiple tables. https://dev.mysql.com/doc/refman/8.0/en/delete.html In this line of code, I am getting the last part of the `b.from` (which is the table name or its alias) and specifying to use it for deletes. This approach means there is no way to specify that you want to delete from `t1` and `t2`, but short of changing the `Delete()` definition and behavior, I don't see a great way to do so.
Owner

Is this a standard SQL syntax? Where could I find some related articles?

Is this a standard SQL syntax? Where could I find some related articles?
Author
Contributor

It seems to be supported in MySQL, MSSQL.
https://www.educba.com/sql-delete-join/

However, it does not seem to be supported in Postgres, SQLite, or Oracle.

It seems to be supported in MySQL, MSSQL. https://www.educba.com/sql-delete-join/ However, it does not seem to be supported in Postgres, SQLite, or Oracle.
Owner

I sent #90, let's wait it's merged.

I sent #90, let's wait it's merged.
Owner

I sent #90, let's wait it's merged.

You can rebase now since #90 merged.

> I sent #90, let's wait it's merged. You can rebase now since #90 merged.
imle force-pushed add-delete-join-support from 85bf0f0c36 to ae37c24c1e 2022-08-10 06:50:32 +00:00 Compare
Author
Contributor

@lunny have you had a chance to review this PR?

@lunny have you had a chance to review this PR?
imle closed this pull request 2022-09-27 18:32:48 +00:00
All checks were successful
continuous-integration/drone/pr Build is passing

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/builder#89
No description provided.