pub trait ISqlGenerator: Send + Sync {
Show 16 methods
// Required methods
fn select(&self, table: &str, columns: &[&str]) -> String;
fn insert(&self, table: &str, columns: &[&str], returning: bool) -> String;
fn update(
&self,
table: &str,
set_columns: &[&str],
where_clause: &str,
) -> String;
fn delete(&self, table: &str, where_clause: &str) -> String;
fn create_table(&self, table: &str, columns: &[(String, String)]) -> String;
fn drop_table(&self, table: &str) -> String;
fn pagination(&self, skip: Option<usize>, take: Option<usize>) -> String;
fn parameter_placeholder(&self, index: usize) -> String;
fn quote_identifier(&self, identifier: &str) -> String;
fn auto_increment_syntax(&self) -> &'static str;
// Provided methods
fn insert_batch(
&self,
table: &str,
columns: &[&str],
row_count: usize,
) -> String { ... }
fn update_batch(
&self,
table: &str,
set_columns: &[&str],
pk_col: &str,
row_count: usize,
where_clause: &str,
) -> String { ... }
fn supports_returning(&self) -> bool { ... }
fn last_insert_id_sql(&self) -> Option<&'static str> { ... }
fn last_insert_id_returns_first(&self) -> bool { ... }
fn upsert_batch(
&self,
table: &str,
columns: &[&str],
conflict_cols: &[&str],
row_count: usize,
) -> String { ... }
}Expand description
Represents a SQL dialect with specific syntax for common operations.
Required Methods§
Sourcefn insert(&self, table: &str, columns: &[&str], returning: bool) -> String
fn insert(&self, table: &str, columns: &[&str], returning: bool) -> String
Generates an INSERT statement.
Sourcefn update(
&self,
table: &str,
set_columns: &[&str],
where_clause: &str,
) -> String
fn update( &self, table: &str, set_columns: &[&str], where_clause: &str, ) -> String
Generates an UPDATE statement.
Sourcefn create_table(&self, table: &str, columns: &[(String, String)]) -> String
fn create_table(&self, table: &str, columns: &[(String, String)]) -> String
Generates a CREATE TABLE statement.
Sourcefn drop_table(&self, table: &str) -> String
fn drop_table(&self, table: &str) -> String
Generates a DROP TABLE statement.
Sourcefn pagination(&self, skip: Option<usize>, take: Option<usize>) -> String
fn pagination(&self, skip: Option<usize>, take: Option<usize>) -> String
Generates a pagination clause.
Sourcefn parameter_placeholder(&self, index: usize) -> String
fn parameter_placeholder(&self, index: usize) -> String
Returns the parameter placeholder (e.g., $1 for PG, ? for MySQL).
Sourcefn quote_identifier(&self, identifier: &str) -> String
fn quote_identifier(&self, identifier: &str) -> String
Returns the identifier quoting character (e.g., " for PG, ` for MySQL).
Sourcefn auto_increment_syntax(&self) -> &'static str
fn auto_increment_syntax(&self) -> &'static str
Returns the dialect-specific auto-increment syntax.
Provided Methods§
Sourcefn insert_batch(
&self,
table: &str,
columns: &[&str],
row_count: usize,
) -> String
fn insert_batch( &self, table: &str, columns: &[&str], row_count: usize, ) -> String
Generates a multi-row INSERT statement with row_count value groups
(INSERT INTO t (c1, c2) VALUES (?, ?), (?, ?), ...). Placeholders
follow the dialect’s numbering (? for SQLite/MySQL, $n for PG).
Sourcefn update_batch(
&self,
table: &str,
set_columns: &[&str],
pk_col: &str,
row_count: usize,
where_clause: &str,
) -> String
fn update_batch( &self, table: &str, set_columns: &[&str], pk_col: &str, row_count: usize, where_clause: &str, ) -> String
Generates a batch UPDATE using CASE pk_col WHEN ? THEN ? for
row_count rows, reducing N round trips to 1.
The SET clause uses 2 * set_columns.len() * row_count placeholders
(numbered from 1). The caller-built where_clause must number its
placeholders starting from 2 * set_columns.len() * row_count + 1.
Parameter layout (caller must arrange params in this order):
- For each set column, for each row:
[pk_value, col_value] - Then the
where_clauseparams (PK IN-list + optional filter)
Sourcefn supports_returning(&self) -> bool
fn supports_returning(&self) -> bool
Whether insert_batch includes a RETURNING * clause (PostgreSQL).
When true, execute_inserts uses query() to read back generated PKs
directly from the INSERT result set.
Sourcefn last_insert_id_sql(&self) -> Option<&'static str>
fn last_insert_id_sql(&self) -> Option<&'static str>
SQL that retrieves the auto-increment key generated by the most recent
batch INSERT. Returns None when the dialect uses RETURNING instead.
- SQLite:
SELECT last_insert_rowid()(returns the LAST rowid) - MySQL:
SELECT LAST_INSERT_ID()(returns the FIRST generated ID)
Sourcefn last_insert_id_returns_first(&self) -> bool
fn last_insert_id_returns_first(&self) -> bool
Whether last_insert_id_sql() returns the FIRST (MySQL) or LAST
(SQLite) generated ID in a batch INSERT. The executor uses this to
compute the full key sequence: first_id..first_id+N or
last_id-N+1..last_id.
Sourcefn upsert_batch(
&self,
table: &str,
columns: &[&str],
conflict_cols: &[&str],
row_count: usize,
) -> String
fn upsert_batch( &self, table: &str, columns: &[&str], conflict_cols: &[&str], row_count: usize, ) -> String
Generates a batch UPSERT statement (row_count value groups).
- SQLite/PostgreSQL:
INSERT INTO t (cols) VALUES (...) ON CONFLICT(conflict_cols) DO UPDATE SET ... - MySQL:
INSERT INTO t (cols) VALUES (...) ON DUPLICATE KEY UPDATE ...
columns are the INSERT columns (excluding auto-increment).
conflict_cols are the PK (or unique constraint) column names used as
the conflict target. The UPDATE SET clause is generated for all
columns that are NOT in conflict_cols.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".