Skip to main content

ISqlGenerator

Trait ISqlGenerator 

Source
pub trait ISqlGenerator: Send + Sync {
Show 17 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 uses_numbered_placeholders(&self) -> bool { ... } 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§

Source

fn select(&self, table: &str, columns: &[&str]) -> String

Generates a SELECT statement.

Source

fn insert(&self, table: &str, columns: &[&str], returning: bool) -> String

Generates an INSERT statement.

Source

fn update( &self, table: &str, set_columns: &[&str], where_clause: &str, ) -> String

Generates an UPDATE statement.

Source

fn delete(&self, table: &str, where_clause: &str) -> String

Generates a DELETE statement.

Source

fn create_table(&self, table: &str, columns: &[(String, String)]) -> String

Generates a CREATE TABLE statement.

Source

fn drop_table(&self, table: &str) -> String

Generates a DROP TABLE statement.

Source

fn pagination(&self, skip: Option<usize>, take: Option<usize>) -> String

Generates a pagination clause.

Source

fn parameter_placeholder(&self, index: usize) -> String

Returns the parameter placeholder (e.g., $1 for PG, ? for MySQL).

Source

fn quote_identifier(&self, identifier: &str) -> String

Returns the identifier quoting character (e.g., " for PG, ` for MySQL).

Source

fn auto_increment_syntax(&self) -> &'static str

Returns the dialect-specific auto-increment syntax.

Provided Methods§

Source

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).

Source

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_clause params (PK IN-list + optional filter)
Source

fn uses_numbered_placeholders(&self) -> bool

Whether the dialect uses numbered placeholders (e.g. PostgreSQL $1, $2) where the index depends on position within the full statement.

When false (SQLite/MySQL ?), compiled filter SQL fragments are index-independent and can be cached across batches. When true, each batch must recompile the filter because placeholder numbering shifts.

Source

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.

Source

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)
Source

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.

Source

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".

Implementors§