Interface SqlDialect

SQL dialect abstraction for cross-platform SQL generation.

Each method returns a SQL string fragment or full statement. Implementations are pure string transformers — no database calls.

interface SqlDialect {
    name: "sqlite" | "postgres";
    insertOrIgnore(table: string, columns: string[], placeholders: string[]): string;
    insertOrReplace(table: string, columns: string[], placeholders: string[], primaryKey?: string): string;
    jsonExtract(column: string, jsonPath: string): string;
    ifnull(expr: string, fallback: string): string;
    autoIncrementPrimaryKey(): string;
    pragma(key: string, value: string): null | string;
    placeholder(index: number): string;
}

Implemented by

Properties

name: "sqlite" | "postgres"

Dialect identifier.

Methods

  • Generate an INSERT OR IGNORE statement. SQLite: INSERT OR IGNORE INTO t (a, b) VALUES (?, ?) Postgres: INSERT INTO t (a, b) VALUES ($1, $2) ON CONFLICT DO NOTHING

    Parameters

    • table: string
    • columns: string[]
    • placeholders: string[]

    Returns string

  • Generate an INSERT OR REPLACE (upsert) statement. SQLite: INSERT OR REPLACE INTO t (a, b) VALUES (?, ?) Postgres: INSERT INTO t (a, b) VALUES ($1, $2) ON CONFLICT (pk) DO UPDATE SET ...

    Parameters

    • table: string
    • columns: string[]
    • placeholders: string[]
    • OptionalprimaryKey: string

      Required for Postgres ON CONFLICT clause. Defaults to first column.

    Returns string

  • Generate a JSON field extraction expression. SQLite: json_extract(col, '$.key') Postgres: (col::jsonb)->>'key'

    Parameters

    • column: string
    • jsonPath: string

    Returns string

  • Generate a null-coalesce expression. SQLite: ifnull(expr, fallback) Postgres: COALESCE(expr, fallback)

    Parameters

    • expr: string
    • fallback: string

    Returns string

  • Column definition for an auto-incrementing integer primary key. SQLite: INTEGER PRIMARY KEY AUTOINCREMENT Postgres: INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY

    Returns string

  • Generate a PRAGMA statement or equivalent. SQLite: PRAGMA key = value Postgres: returns null (skip — Postgres enforces FKs by default, etc.)

    Parameters

    • key: string
    • value: string

    Returns null | string

  • Parameter placeholder for the given 0-based index. SQLite: ? Postgres: $1, $2, etc.

    Parameters

    • index: number

    Returns string