Skip to main content

Dialect

Trait Dialect 

Source
pub trait Dialect:
    Send
    + Sync
    + 'static {
    const AUTO_PK: &'static str;
    const INSERT_IGNORE: &'static str;
    const CONFLICT_NOTHING: &'static str;
    const COLLATE_NOCASE: &'static str;
    const EPOCH_NOW: &'static str;

    // Required methods
    fn ilike(col: &str) -> String;
    fn epoch_from_col(col: &str) -> String;
}
Expand description

SQL fragments that differ between database backends.

Implemented by zero-sized marker types (Sqlite, Postgres). All associated constants are &'static str for zero-cost usage.

Required Associated Constants§

Source

const AUTO_PK: &'static str

Auto-increment primary key DDL fragment.

SQLite: INTEGER PRIMARY KEY AUTOINCREMENT PostgreSQL: BIGSERIAL PRIMARY KEY

Source

const INSERT_IGNORE: &'static str

INSERT OR IGNORE prefix for this backend.

SQLite: INSERT OR IGNORE PostgreSQL: INSERT (pair with CONFLICT_NOTHING suffix)

Source

const CONFLICT_NOTHING: &'static str

Suffix for conflict-do-nothing semantics.

SQLite: empty string (handled by INSERT OR IGNORE prefix) PostgreSQL: ON CONFLICT DO NOTHING

Source

const COLLATE_NOCASE: &'static str

Case-insensitive collation suffix for ORDER BY / WHERE clauses.

SQLite: COLLATE NOCASE PostgreSQL: empty string (use ILIKE or LOWER() instead)

Source

const EPOCH_NOW: &'static str

Current epoch seconds expression.

SQLite: unixepoch('now') PostgreSQL: EXTRACT(EPOCH FROM NOW())::BIGINT

Required Methods§

Source

fn ilike(col: &str) -> String

Case-insensitive comparison expression for a column.

SQLite: {col} COLLATE NOCASE PostgreSQL: LOWER({col})

Source

fn epoch_from_col(col: &str) -> String

Epoch seconds expression for a timestamp column.

Wraps the column in the backend-specific function that converts a stored timestamp to a Unix epoch integer, coalescing NULL to 0.

SQLite: COALESCE(CAST(strftime('%s', {col}) AS INTEGER), 0) PostgreSQL: COALESCE(CAST(EXTRACT(EPOCH FROM {col}) AS BIGINT), 0)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Dialect for Postgres

Source§

const AUTO_PK: &'static str = "BIGSERIAL PRIMARY KEY"

Source§

const INSERT_IGNORE: &'static str = "INSERT"

Source§

const CONFLICT_NOTHING: &'static str = "ON CONFLICT DO NOTHING"

Source§

const COLLATE_NOCASE: &'static str = ""

Source§

const EPOCH_NOW: &'static str = "EXTRACT(EPOCH FROM NOW())::BIGINT"

Source§

impl Dialect for Sqlite

Source§

const AUTO_PK: &'static str = "INTEGER PRIMARY KEY AUTOINCREMENT"

Source§

const INSERT_IGNORE: &'static str = "INSERT OR IGNORE"

Source§

const CONFLICT_NOTHING: &'static str = ""

Source§

const COLLATE_NOCASE: &'static str = "COLLATE NOCASE"

Source§

const EPOCH_NOW: &'static str = "unixepoch('now')"