Skip to content

Commit

Permalink
chore: split dialect-specific syntax handling into discrete method fo…
Browse files Browse the repository at this point in the history
…r `UPDATE ... FROM ...` behavior
  • Loading branch information
the-wondersmith committed Dec 29, 2024
1 parent 2df8b6b commit 6533421
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/backend/mysql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ impl QueryBuilder for MysqlQueryBuilder {
"ROW"
}

fn prepare_update_from_table_refs(&self, _: &[TableRef], _: &mut dyn SqlWriter) {
todo!(r#""UPDATE ... FROM ..." syntax not yet supported for MySQL backend"#)
}

fn prepare_select_distinct(&self, select_distinct: &SelectDistinct, sql: &mut dyn SqlWriter) {
match select_distinct {
SelectDistinct::All => write!(sql, "ALL").unwrap(),
Expand Down
27 changes: 17 additions & 10 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::*;
use std::ops::Deref;

use crate::*;

const QUOTE: Quote = Quote(b'"', b'"');

pub trait QueryBuilder:
Expand Down Expand Up @@ -211,15 +212,7 @@ pub trait QueryBuilder:
});

if !update.from.is_empty() {
write!(sql, " FROM ").unwrap();

update.from.iter().fold(true, |first, table_ref| {
if !first {
write!(sql, ", ").unwrap()
}
self.prepare_table_ref(table_ref, sql);
false
});
self.prepare_update_from_table_refs(&update.from, sql);
}

self.prepare_output(&update.returning, sql);
Expand All @@ -233,6 +226,20 @@ pub trait QueryBuilder:
self.prepare_returning(&update.returning, sql);
}

fn prepare_update_from_table_refs(&self, from: &[TableRef], sql: &mut dyn SqlWriter) {
write!(sql, " FROM ").unwrap();

from.iter().fold(true, |first, table_ref| {
if !first {
write!(sql, ", ").unwrap()
}

self.prepare_table_ref(table_ref, sql);

false
});
}

/// Translate ORDER BY expression in [`UpdateStatement`].
fn prepare_update_order_by(&self, update: &UpdateStatement, sql: &mut dyn SqlWriter) {
if !update.orders.is_empty() {
Expand Down

0 comments on commit 6533421

Please sign in to comment.