SQLite dialect implementation.

Generates SQLite SQL: INSERT OR IGNORE, ON CONFLICT ... DO UPDATE upserts, json_extract(), ifnull(), strftime() times in ISO 8601 UTC text, PRAGMA, and positional ? placeholders.

Implements

Constructors

Properties

name: "sqlite" = ...

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 upsert on the primary key that updates the existing row in place, on both engines: INSERT INTO t (a, b) VALUES (?, ?) ON CONFLICT (a) DO UPDATE SET b = excluded.b. The row keeps the columns the statement does not name, and its dependents. When every column is the key, the statement does nothing on a conflict.

    Parameters

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

      The conflict target. Defaults to the first column.

    Returns string

  • An upsert with an explicit conflict target that updates the existing row in place on both engines (SQLite 3.24 and later): INSERT INTO t (a, b, c) VALUES (?, ?, ?) ON CONFLICT (a) DO UPDATE SET b = excluded.b, c = excluded.c.

    Parameters

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

      The unique or primary-key columns of the conflict target.

    • OptionalupdateColumns: string[]

      The columns to update; by default every column outside the target. None left: DO NOTHING.

    Returns string

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

    Parameters

    • column: string
    • jsonPath: string

    Returns string

  • A value at jsonPath ($.a.b, $.a[0]) read as text, an integer or a real, with the same result on both engines; json reads the JSON value itself (jsonb on PostgreSQL, JSON text on SQLite), for use inside another expression such as jsonArrayContains. A path outside that form is refused.

    Parameters

    Returns string

  • Whether the JSON array jsonArray holds the value valueExpr, compared as text, so a string or a number matches on both engines.

    Parameters

    • jsonArray: string
    • valueExpr: 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, which takes an id an insert gives as well. Postgres: INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, which refuses one; with acceptExplicitIds, GENERATED BY DEFAULT, which takes it. After inserting ids, run syncIdentitySequence.

    Parameters

    Returns string

  • Statements that make every write to table, from any session, send a notification on channel: one per statement, its payload JSON {"schema", "table", "operation"} with the operation insert, update or delete (TRUNCATE too). Postgres: a trigger function and a statement-level trigger, which PostgresAdapter.listen hears. SQLite: null, since SQLite has no notifications between connections.

    Parameters

    • table: string
    • channel: string

    Returns null

  • A statement that moves an identity or serial column's sequence past the largest value in the table, so the next generated id does not collide with ids inserted explicitly. Postgres: SELECT setval(...). SQLite: null, since a rowid and AUTOINCREMENT follow the largest id by themselves. The table may be schema-qualified; names are SQL identifiers. Optional for existing custom dialects; callers may fall back to no statement.

    Parameters

    • table: string
    • column: string

    Returns null

  • A column type for DDL. PostgreSQL: TEXT, INTEGER, BIGINT, DOUBLE PRECISION, BOOLEAN, TIMESTAMPTZ, JSONB, UUID, BYTEA. SQLite: TEXT, INTEGER, INTEGER, REAL, INTEGER, TEXT, TEXT, TEXT, BLOB. The values a column returns follow each engine (a PostgreSQL boolean is true, a SQLite one 1); typeParsers and the bound-value conversions narrow that.

    Parameters

    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

  • The current time. PostgreSQL: now() (timestamptz). SQLite: ISO 8601 UTC text with milliseconds, the form a bound Date takes, so text comparisons with stored times order correctly.

    Returns string

  • expr cast to a type both engines read the same way. timestamp is timestamptz on PostgreSQL and ISO 8601 UTC text on SQLite.

    Parameters

    Returns string

  • The time expr moved by amount units (negative moves back), as an exact number of seconds on both engines. PostgreSQL: timestamptz. SQLite: ISO 8601 UTC text.

    Parameters

    Returns string

  • Case-insensitive LIKE. PostgreSQL: ILIKE. SQLite: LIKE, which folds only ASCII letters.

    Parameters

    • expr: string
    • pattern: string

    Returns string

  • expr IN (...) over the given placeholders or expressions; an empty list matches nothing.

    Parameters

    • expr: string
    • items: string[]

    Returns string

  • Membership in an array bound as one parameter. PostgreSQL: = ANY(param) (pg binds a JavaScript array as an array). SQLite: IN (SELECT value FROM json_each(param)) over the JSON text the array binds as.

    Parameters

    • expr: string
    • arrayParam: string

    Returns string

  • A row-lock clause to append to a SELECT. PostgreSQL: FOR UPDATE or FOR SHARE, with SKIP LOCKED or NOWAIT. SQLite: '', since a write transaction there holds the whole database.

    Parameters

    • mode: "update" | "share"
    • wait: "wait" | "skipLocked" | "noWait" = 'wait'

    Returns string

  • A statement that takes a transaction-scoped advisory lock on an integer key, released at COMMIT or ROLLBACK. PostgreSQL: SELECT pg_advisory_xact_lock(key). SQLite: null, to skip, since its write transactions already run one at a time.

    Parameters

    • _keyExpr: string

    Returns null | string