Skip to main content

SqlDialect

Trait SqlDialect 

Source
pub trait SqlDialect:
    Send
    + Sync
    + Sealed {
Show 13 methods // Required methods fn placeholder(&self, i: usize) -> String; fn returning_clause(&self, cols: &str) -> String; fn quote_ident(&self, ident: &str) -> String; fn upsert_clause(&self, conflict_cols: &[&str], update_set: &str) -> String; // Provided methods fn supports_distinct_on(&self) -> bool { ... } fn insert_has_returning(&self) -> bool { ... } fn supports_sql_emission(&self) -> bool { ... } fn supports_upsert(&self) -> bool { ... } fn upsert_do_nothing_clause(&self, _conflict_cols: &[&str]) -> String { ... } fn like_escape_clause(&self) -> &'static str { ... } fn begin_sql(&self) -> &'static str { ... } fn commit_sql(&self) -> &'static str { ... } fn rollback_sql(&self) -> &'static str { ... }
}
Expand description

Cross-dialect SQL emission helpers.

Implementations describe a single database backend’s syntax choices. Engines return &dyn SqlDialect from QueryEngine::dialect().

Required Methods§

Source

fn placeholder(&self, i: usize) -> String

Emit the 1-indexed parameter placeholder for position i.

Source

fn returning_clause(&self, cols: &str) -> String

Emit the clause (leading space included) that requests the given columns be returned after an INSERT/UPDATE/DELETE. Postgres/SQLite/MySQL emit RETURNING cols; MSSQL emits OUTPUT INSERTED.cols.

Source

fn quote_ident(&self, ident: &str) -> String

Quote a table/column identifier for safe interpolation.

Source

fn upsert_clause(&self, conflict_cols: &[&str], update_set: &str) -> String

Emit the ON CONFLICT / ON DUPLICATE KEY clause (leading space included) that converts an INSERT into an upsert.

Identifier convention: identifiers in conflict_cols MUST be passed unquoted (raw column names). Implementations are responsible for quoting them per dialect via self.quote_ident.

Provided Methods§

Source

fn supports_distinct_on(&self) -> bool

Whether the dialect supports SELECT DISTINCT ON (cols) (Postgres-only among our backends today).

Source

fn insert_has_returning(&self) -> bool

Whether an INSERT statement can use the dialect’s returning clause to retrieve inserted rows in-place.

Source

fn supports_sql_emission(&self) -> bool

Whether this dialect supports SQL emission for upsert / nested-write generation. Returns false for document-store dialects (NotSql) that unimplemented!() on quote_ident / placeholder / upsert_clause. Callers must check this before issuing any SQL via the dialect.

Source

fn supports_upsert(&self) -> bool

True if this dialect’s upsert_clause can produce a usable single-statement INSERT ... ON CONFLICT/ON DUPLICATE form, and (separately) if placeholder and quote_ident are real implementations. False for document-store/NotSql dialects whose SQL-emitting methods are unimplemented!().

Source

fn upsert_do_nothing_clause(&self, _conflict_cols: &[&str]) -> String

Emit a DO NOTHING/insert-ignore clause for the conflict target. Default empty (fallback dialects skip the single-statement path entirely). PG/SQLite/DuckDB return ON CONFLICT (...) DO NOTHING; MySQL returns ON DUPLICATE KEY UPDATE id = id (no-op self-assign).

Inputs are raw identifiers; the dialect quotes them internally.

Source

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

LIKE-pattern escape clause (leading space included) appended to <col> LIKE <placeholder> when the pattern carries backslash-escaped user input. Postgres/SQLite/MSSQL accept ESCAPE '\'; MySQL treats backslash as a string-literal escape character, so its spelling must double the backslash (ESCAPE '\\') — the single-backslash form is an unterminated literal there.

Source

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

SQL keyword that begins a transaction. Defaults to BEGIN.

Source

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

SQL keyword that commits a transaction. Defaults to COMMIT.

Source

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

SQL keyword that rolls back a transaction. Defaults to ROLLBACK.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§