-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
…TE statements (#1289) * fix(compiler): Support references to columns in joined tables in UPDATE statements
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE primary_table ( | ||
id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | ||
user_id bigint(20) unsigned NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE join_table ( | ||
id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | ||
primary_table_id bigint(20) unsigned NOT NULL, | ||
other_table_id bigint(20) unsigned NOT NULL, | ||
is_active tinyint(1) NOT NULL DEFAULT '0', | ||
PRIMARY KEY (id) | ||
); | ||
|
||
-- name: UpdateJoin :exec | ||
UPDATE join_table as jt | ||
JOIN primary_table as pt | ||
ON jt.primary_table_id = pt.id | ||
SET jt.is_active = ? | ||
WHERE jt.id = ? | ||
AND pt.user_id = ?; | ||
|
||
-- name: UpdateLeftJoin :exec | ||
UPDATE join_table as jt | ||
LEFT JOIN primary_table as pt | ||
ON jt.primary_table_id = pt.id | ||
SET jt.is_active = ? | ||
WHERE jt.id = ? | ||
AND pt.user_id = ?; | ||
|
||
-- name: UpdateRightJoin :exec | ||
UPDATE join_table as jt | ||
RIGHT JOIN primary_table as pt | ||
ON jt.primary_table_id = pt.id | ||
SET jt.is_active = ? | ||
WHERE jt.id = ? | ||
AND pt.user_id = ?; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "1", | ||
"packages": [ | ||
{ | ||
"path": "db", | ||
"engine": "mysql", | ||
"schema": "query.sql", | ||
"queries": "query.sql" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE TABLE primary_table ( | ||
id INT PRIMARY KEY, | ||
user_id INT NOT NULL | ||
); | ||
|
||
CREATE TABLE join_table ( | ||
id INT PRIMARY KEY, | ||
primary_table_id INT NOT NULL, | ||
other_table_id INT NOT NULL, | ||
is_active BOOLEAN NOT NULL | ||
); | ||
|
||
-- name: UpdateJoin :exec | ||
UPDATE join_table | ||
SET is_active = $1 | ||
FROM primary_table | ||
WHERE join_table.id = $2 | ||
AND primary_table.user_id = $3 | ||
AND join_table.primary_table_id = primary_table.id; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "1", | ||
"packages": [ | ||
{ | ||
"path": "db", | ||
"engine": "postgresql", | ||
"schema": "query.sql", | ||
"queries": "query.sql" | ||
} | ||
] | ||
} |