Skip to content

Commit

Permalink
Support join clause in UPDATE statement (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanzaku authored Oct 25, 2023
1 parent 857b29d commit b93cb59
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/uroborosql-fmt/src/visitor/clause/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{

impl Visitor {
/// JOIN句
pub(crate) fn visit_join_cluase(
pub(crate) fn visit_join_clause(
&mut self,
cursor: &mut TreeCursor,
src: &str,
Expand Down
2 changes: 1 addition & 1 deletion crates/uroborosql-fmt/src/visitor/statement/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Visitor {
statement.add_clause(clause);
}
"join_clause" => {
let clauses = self.visit_join_cluase(cursor, src)?;
let clauses = self.visit_join_clause(cursor, src)?;
clauses.into_iter().for_each(|c| statement.add_clause(c));
}
"UNION" | "INTERSECT" | "EXCEPT" => {
Expand Down
4 changes: 4 additions & 0 deletions crates/uroborosql-fmt/src/visitor/statement/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ impl Visitor {
let clause = self.visit_from_clause(cursor, src)?;
statement.add_clause(clause);
}
"join_clause" => {
let clause = self.visit_join_clause(cursor, src)?;
statement.add_clauses(clause);
}
"where_clause" => {
let clause = self.visit_where_clause(cursor, src)?;
statement.add_clause(clause);
Expand Down
13 changes: 13 additions & 0 deletions crates/uroborosql-fmt/testfiles/dst/update/join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
update /* _SQL_ID_ */
tbl t
set
t.col2 = a.col2
, t.col3 = a.col3
from
tbl_a a
left outer join
tbl_b b
on
a.col1 = b.col1
where
t.id = a.id
4 changes: 4 additions & 0 deletions crates/uroborosql-fmt/testfiles/src/update/join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
update /* _SQL_ID_ */
tbl t set t.col2 = a.col2, t.col3 = a.col3
from tbl_a a
left outer join tbl_b b on a.col1 = b.col1 where t.id = a.id

0 comments on commit b93cb59

Please sign in to comment.