pub trait Dialect:
Send
+ Sync
+ 'static {
Show 37 methods
// Required methods
fn name(&self) -> &'static str;
fn ddl_type(&self, t: &CanonicalType) -> String;
fn cast_name(&self, t: &CanonicalType) -> Option<String>;
fn type_category(&self, t: &CanonicalType) -> TypeCategory;
fn type_support(&self, t: &CanonicalType) -> TypeSupport;
fn quote_ident(&self, s: &str) -> String;
fn placeholder(&self, n: usize) -> String;
fn cast_expr(&self, placeholder: &str, cast: &str) -> String;
fn now_fn(&self) -> &'static str;
fn uuid_default_expr(&self) -> &'static str;
fn returning_clause(&self, cols: &str) -> String;
fn upsert_conflict(&self, conflict_cols: &[&str], set_pairs: &str) -> String;
fn to_one_subquery(&self, col_exprs: &[String], from_clause: &str) -> String;
fn to_many_subquery(
&self,
col_exprs: &[String],
from_clause: &str,
) -> String;
fn json_extract_text(&self, col: &str, key: &str) -> String;
fn json_extract_typed(
&self,
col: &str,
key: &str,
t: &CanonicalType,
) -> String;
fn case_insensitive_like(&self, col: &str, placeholder: &str) -> String;
fn sys_json_type(&self) -> &'static str;
fn sys_timestamp_type(&self) -> &'static str;
fn sys_bigserial_type(&self) -> &'static str;
fn sys_bytes_type(&self) -> &'static str;
fn audit_timestamp_type(&self) -> &'static str;
fn supports_rls(&self) -> bool;
fn supports_named_enum_types(&self) -> bool;
fn supports_index_include(&self) -> bool;
fn set_tenant_session_sql(&self, tenant_id: &str) -> Option<String>;
// Provided methods
fn sys_timestamp_default(&self) -> String { ... }
fn supports_schemas(&self) -> bool { ... }
fn default_now_plus_hours(&self, hours: u32) -> Option<String> { ... }
fn set_read_only_sql(&self) -> Option<String> { ... }
fn set_statement_timeout_sql(&self, _ms: u64) -> Option<String> { ... }
fn set_role_sql(&self, _role: &str) -> Option<String> { ... }
fn supports_add_column_if_not_exists(&self) -> bool { ... }
fn is_duplicate_object_code(&self, _code: &str) -> bool { ... }
fn introspect_columns_sql(&self, schema: &str) -> String { ... }
fn introspect_indexes_sql(&self, _schema: &str) -> Option<String> { ... }
fn introspect_constraints_sql(&self, schema: &str) -> Option<String> { ... }
}Expand description
A database dialect encapsulates all SQL syntax and type-mapping differences between database engines. The SDK calls dialect methods instead of hardcoding Postgres strings, so adding a new database is a matter of implementing this trait.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Short name for log messages and errors (e.g. “postgres”, “mysql”, “sqlite”).
Sourcefn ddl_type(&self, t: &CanonicalType) -> String
fn ddl_type(&self, t: &CanonicalType) -> String
DDL type string for CREATE TABLE (e.g. “TIMESTAMPTZ”, “DATETIME”, “TEXT”).
Sourcefn cast_name(&self, t: &CanonicalType) -> Option<String>
fn cast_name(&self, t: &CanonicalType) -> Option<String>
Type name used in parameter cast expressions, or None when no cast is needed.
Postgres: becomes $n::cast. MySQL/SQLite: cast is omitted (binding handles type).
Sourcefn type_category(&self, t: &CanonicalType) -> TypeCategory
fn type_category(&self, t: &CanonicalType) -> TypeCategory
Broad category for RSQL operator validation.
Sourcefn type_support(&self, t: &CanonicalType) -> TypeSupport
fn type_support(&self, t: &CanonicalType) -> TypeSupport
How well this dialect supports the canonical type.
Sourcefn quote_ident(&self, s: &str) -> String
fn quote_ident(&self, s: &str) -> String
Wrap an identifier in dialect-specific delimiters. Postgres/SQLite: double-quotes. MySQL: backticks.
Sourcefn placeholder(&self, n: usize) -> String
fn placeholder(&self, n: usize) -> String
Positional placeholder for the n-th parameter (1-based).
Postgres: $1. MySQL/SQLite: ?.
Sourcefn cast_expr(&self, placeholder: &str, cast: &str) -> String
fn cast_expr(&self, placeholder: &str, cast: &str) -> String
Wrap a placeholder with a type cast where required.
Postgres: $1::uuid. MySQL/SQLite: placeholder returned unchanged.
Sourcefn uuid_default_expr(&self) -> &'static str
fn uuid_default_expr(&self) -> &'static str
Expression that generates a random UUID as a column DEFAULT.
Sourcefn returning_clause(&self, cols: &str) -> String
fn returning_clause(&self, cols: &str) -> String
RETURNING clause appended to INSERT/UPDATE/DELETE, or empty string when unsupported.
Sourcefn upsert_conflict(&self, conflict_cols: &[&str], set_pairs: &str) -> String
fn upsert_conflict(&self, conflict_cols: &[&str], set_pairs: &str) -> String
Upsert conflict suffix.
conflict_cols: columns that identify the conflict.
set_pairs: pre-built “col = value” pairs for the update branch.
Sourcefn to_one_subquery(&self, col_exprs: &[String], from_clause: &str) -> String
fn to_one_subquery(&self, col_exprs: &[String], from_clause: &str) -> String
Build a scalar subquery returning a single JSON object for a to-one include.
col_exprs: already-quoted column expressions.
from_clause: "schema"."table" WHERE ... fragment.
Sourcefn to_many_subquery(&self, col_exprs: &[String], from_clause: &str) -> String
fn to_many_subquery(&self, col_exprs: &[String], from_clause: &str) -> String
Build a scalar subquery returning a JSON array for a to-many include.
Sourcefn json_extract_text(&self, col: &str, key: &str) -> String
fn json_extract_text(&self, col: &str, key: &str) -> String
Extract a top-level key from a JSON/JSONB column as text.
col is an already-quoted column expression; key is the raw JSON key (escaped here).
Postgres: (col ->> 'key'). MySQL/SQLite: col->>'$.key'.
Sourcefn json_extract_typed(&self, col: &str, key: &str, t: &CanonicalType) -> String
fn json_extract_typed(&self, col: &str, key: &str, t: &CanonicalType) -> String
Extract a JSON key and cast it to t so comparisons and ORDER BY are type-correct.
For text-like types this is equivalent to Dialect::json_extract_text.
Sourcefn case_insensitive_like(&self, col: &str, placeholder: &str) -> String
fn case_insensitive_like(&self, col: &str, placeholder: &str) -> String
Case-insensitive LIKE comparison fragment: col <ci-like> placeholder.
Postgres: col ILIKE ph. MySQL: LOWER(col) LIKE LOWER(ph). SQLite: col LIKE ph
(SQLite LIKE is case-insensitive for ASCII by default).
Sourcefn sys_json_type(&self) -> &'static str
fn sys_json_type(&self) -> &'static str
DDL fragment for a JSON/JSONB payload column (e.g. “JSONB”, “JSON”, “TEXT”).
Sourcefn sys_timestamp_type(&self) -> &'static str
fn sys_timestamp_type(&self) -> &'static str
Timestamp type name (without NOT NULL / DEFAULT).
Sourcefn sys_bigserial_type(&self) -> &'static str
fn sys_bigserial_type(&self) -> &'static str
Auto-incrementing large integer for surrogate PKs. e.g. “BIGSERIAL”, “BIGINT AUTO_INCREMENT”, “INTEGER”.
Sourcefn sys_bytes_type(&self) -> &'static str
fn sys_bytes_type(&self) -> &'static str
DDL type for a raw binary payload column (e.g. “BYTEA”, “BLOB”).
Sourcefn audit_timestamp_type(&self) -> &'static str
fn audit_timestamp_type(&self) -> &'static str
Timestamp type used in audit table columns (no DEFAULT — values supplied explicitly).
Sourcefn supports_rls(&self) -> bool
fn supports_rls(&self) -> bool
Whether this dialect natively supports row-level security (CREATE POLICY etc.).
Sourcefn supports_named_enum_types(&self) -> bool
fn supports_named_enum_types(&self) -> bool
Whether this dialect supports named enum types (CREATE TYPE … AS ENUM).
Sourcefn supports_index_include(&self) -> bool
fn supports_index_include(&self) -> bool
Whether this dialect supports INCLUDE columns on indexes (Postgres 11+).
Sourcefn set_tenant_session_sql(&self, tenant_id: &str) -> Option<String>
fn set_tenant_session_sql(&self, tenant_id: &str) -> Option<String>
SQL statement that sets a session-local tenant identifier before a query.
Returns None when the dialect has no such mechanism.
Provided Methods§
Sourcefn sys_timestamp_default(&self) -> String
fn sys_timestamp_default(&self) -> String
NOT NULL timestamp column with a now() default — convenience built from above.
Sourcefn supports_schemas(&self) -> bool
fn supports_schemas(&self) -> bool
Whether this dialect supports CREATE SCHEMA DDL.
Postgres: true. MySQL: false (uses databases). SQLite: false (no user-defined schemas).
Sourcefn default_now_plus_hours(&self, hours: u32) -> Option<String>
fn default_now_plus_hours(&self, hours: u32) -> Option<String>
DDL fragment for a column that holds a timestamp defaulting to N hours from now.
Returns None when the dialect has no constant-expression equivalent (SQLite).
Callers should make the column nullable and omit the DEFAULT when None is returned.
Sourcefn set_read_only_sql(&self) -> Option<String>
fn set_read_only_sql(&self) -> Option<String>
Make the current transaction read-only (blocks writes and writable CTEs).
Sourcefn set_statement_timeout_sql(&self, _ms: u64) -> Option<String>
fn set_statement_timeout_sql(&self, _ms: u64) -> Option<String>
Bound the running time of statements in the current transaction, in milliseconds.
Sourcefn set_role_sql(&self, _role: &str) -> Option<String>
fn set_role_sql(&self, _role: &str) -> Option<String>
Drop to a specific (read-only) DB role for the current transaction. role is a bare
identifier supplied by an operator via env var, quoted by the dialect.
Sourcefn supports_add_column_if_not_exists(&self) -> bool
fn supports_add_column_if_not_exists(&self) -> bool
Whether ALTER TABLE … ADD COLUMN IF NOT EXISTS is valid syntax.
Postgres: true. MySQL/SQLite: false (they need a pre-flight existence check).
Sourcefn is_duplicate_object_code(&self, _code: &str) -> bool
fn is_duplicate_object_code(&self, _code: &str) -> bool
Whether a database error code (SQLSTATE for Postgres, error number for MySQL) means “the object I tried to create already exists” — a migration step that is already applied.
Sourcefn introspect_columns_sql(&self, schema: &str) -> String
fn introspect_columns_sql(&self, schema: &str) -> String
One row per column in schema:
(table_name, column_name, data_type, is_nullable 'YES'/'NO', has_default 'YES'/'NO').
Sourcefn introspect_indexes_sql(&self, _schema: &str) -> Option<String>
fn introspect_indexes_sql(&self, _schema: &str) -> Option<String>
One row per index in schema: (index_name). None when the dialect cannot report them.
Sourcefn introspect_constraints_sql(&self, schema: &str) -> Option<String>
fn introspect_constraints_sql(&self, schema: &str) -> Option<String>
One row per table constraint in schema: (table_name, constraint_name).
None when the dialect cannot report them.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".