vael:db
Zero-ORM fluent SQL query builder, safe tagged templates, savepoints, rich
SQL types, and strict JSON configuration for vael:db.
Available in the vjs (vaeljs) runtime only; absent in vjs-lite.
Provides async SQLite queries by default, plus optional feature-gated
PostgreSQL (vael-db-postgres), MySQL (vael-db-mysql), MariaDB
(vael-db-mariadb), and Microsoft SQL Server (vael-db-mssql) providers
with parameterized execution, bounded row limits, and automatic
COMMIT/ROLLBACK/SAVEPOINT handling.
import ... from "vael:db"
vael-db (SQLite enabled by default in vaeljs-core; opt-in network drivers vael-db-postgres, vael-db-mysql, vael-db-mariadb, vael-db-mssql, vael-db-all; absent in vaeljs-lite-core)Example
Section titled “Example”import { openSqlite, sql } from "vael:db";
await using db = await openSqlite(":memory:");await db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)");await db.insertInto("users").values({ name: "Ada" }).execute();const users = await db.from("users").select("id", "name").all();const one = await db.sql`SELECT id, name FROM users WHERE name = ${"Ada"}`.first();tablevjs onlyv0.0.0-alpha.2colvjs onlyv0.0.0-alpha.2col("id") or col("u", "id")).selectvjs onlyv0.0.0-alpha.2SELECT query builder.insertIntovjs onlyv0.0.0-alpha.2INSERT INTO query builder.updatevjs onlyv0.0.0-alpha.2UPDATE query builder.deleteFromvjs onlyv0.0.0-alpha.2DELETE FROM query builder.openvjs onlyv0.0.0-alpha.0openSqlitevjs onlyv0.0.0-alpha.0":memory:").SqliteDbConfigvjs onlyv0.0.0-alpha.0NetworkDbConfigvjs onlyv0.0.0-alpha.0DbTypedParamvjs onlyv0.0.0-alpha.2sql.uuid, sql.date, sql.timestamp, sql.timestampTz, sql.decimal, or sql.json.DbQueryOptionsvjs onlyv0.0.0-alpha.2maxRows <= 100,000, maxBytes <= 32 MiB, timeoutMs <= 300,000).DbExecuteResultvjs onlyv0.0.0-alpha.0execute().DbTableRefvjs onlyv0.0.0-alpha.2DbColumnRefvjs onlyv0.0.0-alpha.2col(...) / sql.ident(...)).DbExprvjs onlyv0.0.0-alpha.2ExprBuilder or func().SqlFragmentvjs onlyv0.0.0-alpha.2sql tagged template or sql.raw / sql.join.RenderedSqlvjs onlyv0.0.0-alpha.2AnySelectBuildervjs onlyv0.0.0-alpha.2SelectBuilder, regardless of schema <DB>, table <T>, or source TableRow.AnyMutationBuildervjs onlyv0.0.0-alpha.2InsertBuilder, UpdateBuilder, or DeleteBuilder, regardless of <DB>, <T>, or...ExprBuildervjs onlyv0.0.0-alpha.2.where((eb) => ...), .orWhere(...), .having(...), and .join(table, (eb) => ...).SelectBuildervjs onlyv0.0.0-alpha.2SELECT query builder.InsertBuildervjs onlyv0.0.0-alpha.2INSERT query builder.UpdateBuildervjs onlyv0.0.0-alpha.2UPDATE query builder (requires .where(...) or .unfiltered() to prevent accidental full-table updates).DeleteBuildervjs onlyv0.0.0-alpha.2DELETE query builder (requires .where(...) or .unfiltered() to prevent accidental full-table deletes).BoundSqlRunnervjs onlyv0.0.0-alpha.2db.sql\...\ and tx.sql\...\.SqlTagvjs onlyv0.0.0-alpha.2DatabaseHandlevjs onlyv0.0.0-alpha.0Database<DB> and Transaction<DB>.Transactionvjs onlyv0.0.0-alpha.2Databasevjs onlyv0.0.0-alpha.0DbDialectvjs onlyv0.0.0-alpha.2Database.dialect and Transaction.dialect.DbRowvjs onlyv0.0.0-alpha.2DbSchemavjs onlyv0.0.0-alpha.2{ tableName: { colName: colType } }) for generic autocomplete and row inference on open<DB>() / openSqlite<DB>().DbErrorCodevjs onlyv0.0.0-alpha.0DbError.code.DbConstraintKindvjs onlyv0.0.0-alpha.2DbError.constraintKind.DbConfigvjs onlyv0.0.0-alpha.0open(config).DbParamValuevjs onlyv0.0.0-alpha.0DbParamsvjs onlyv0.0.0-alpha.0?) or named (@name) parameters for a SQL statement.CompareOpvjs onlyv0.0.0-alpha.2where() / orWhere() calls.TableNameOfvjs onlyv0.0.0-alpha.0DbRowForvjs onlyv0.0.0-alpha.0ResolveTableRowvjs onlyv0.0.0-alpha.0IsInitialUnselectedvjs onlyv0.0.0-alpha.0MergeSelectedvjs onlyv0.0.0-alpha.0JoinSelectedRowvjs onlyv0.0.0-alpha.0Functions
Section titled “Functions”export function table<Name extends string, Alias extends string = Name>(
name: Name,
opts?: { readonly schema?: string; readonly as?: Alias },
): DbTableRef<Name, Alias>;
Construct a schema-qualified or aliased table reference.
| Name | Type | Description |
|---|---|---|
name | Name | — |
opts optional | { readonly schema?: string; readonly as?: Alias } | — |
DbTableRef<Name, Alias>export function col<T extends string, C extends string>(table: T, column: C): DbColumnRef<T, C>;
export function col<C extends string>(column: C): DbColumnRef<string, C>;
Construct an explicit SQL column reference (col("id") or col("u", "id")).
select
Section titled “select”export function select<DB = DbSchema>(): SelectBuilder<DB, string, DbRow, DbRow>;
export function select<
DB = DbSchema,
T extends (keyof DB & string) | (string & {}) | DbTableRef = string,
>(table: T): SelectBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>, ResolveTableRow<DB, T>>;
Construct an unbound SELECT query builder.
| Name | Type | Description |
|---|---|---|
table optional | T | — |
SelectBuilder<DB, string, DbRow, DbRow>SelectBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>, ResolveTableRow<DB, T>>
insertInto
Section titled “insertInto”export function insertInto<
DB = DbSchema,
T extends (keyof DB & string) | DbTableRef = keyof DB & string,
>(table: T): InsertBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Construct an unbound INSERT INTO query builder.
| Name | Type | Description |
|---|---|---|
table | T | — |
InsertBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>update
Section titled “update”export function update<
DB = DbSchema,
T extends (keyof DB & string) | DbTableRef = keyof DB & string,
>(table: T): UpdateBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Construct an unbound UPDATE query builder.
| Name | Type | Description |
|---|---|---|
table | T | — |
UpdateBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>deleteFrom
Section titled “deleteFrom”export function deleteFrom<
DB = DbSchema,
T extends (keyof DB & string) | DbTableRef = keyof DB & string,
>(table: T): DeleteBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Construct an unbound DELETE FROM query builder.
| Name | Type | Description |
|---|---|---|
table | T | — |
DeleteBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>export function open<DB = DbSchema>(
config: DbConfig | string,
): Promise<Database<DB>>;
Open a database from a strict configuration object or JSON configuration string.
| Name | Type | Description |
|---|---|---|
config | DbConfig | string | — |
openSqlite
Section titled “openSqlite”export function openSqlite<DB = DbSchema>(
database?: string,
): Promise<Database<DB>>;
Open a SQLite database (defaults to ":memory:").
| Name | Type | Description |
|---|---|---|
database optional | string | — |
Classes
Section titled “Classes”DbError
Section titled “DbError”export class DbError extends Error {
override name: "DbError";
code: DbErrorCode;
readonly databaseKind?: string;
readonly reason?: string;
readonly constraintKind?: DbConstraintKind | string;
constructor(
code: DbErrorCode,
message: string,
databaseKind?: string,
reason?: string,
constraintKind?: string,
);
}
Redacted database API error with a stable code.
constructor(
code: DbErrorCode,
message: string,
databaseKind?: string,
reason?: string,
constraintKind?: string,
);
Construct a DbError.
| Name | Type | Description |
|---|---|---|
code | DbErrorCode | Machine-readable DbErrorCode. |
message | string | Human-readable redacted error message. |
databaseKind optional | string | Optional provider error category. |
reason optional | string | Optional static invalid-argument reason. |
constraintKind optional | string | Optional static constraint classification. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "DbError" | Error name ("DbError"). | v0.0.0-alpha.0 |
code | DbErrorCode | Machine-readable database error code. | v0.0.0-alpha.0 |
databaseKind readonly optional | string | Optional underlying provider error category (for example "Overflow", "Constraint", "NoRows", "TooManyRows", or "Unsupported"). | v0.0.0-alpha.0 |
reason readonly optional | string | Optional static invalid-argument reason (for example "MissingWhereClause"). | v0.0.0-alpha.2 |
constraintKind readonly optional | DbConstraintKind | string | Optional static constraint classification ("Unique" | "ForeignKey" | "NotNull" | "Check"). | v0.0.0-alpha.2 |
Interfaces
Section titled “Interfaces”SqliteDbConfig
Section titled “SqliteDbConfig”export interface SqliteDbConfig {
driver: "sqlite";
database: string;
busy_timeout_ms?: number;
max_connections?: number;
}
Strict SQLite database configuration.
| Property | Type | Description | Since |
|---|---|---|---|
driver | "sqlite" | Driver identifier ("sqlite"). | v0.0.0-alpha.0 |
database | string | File path or ":memory:" for an in-memory SQLite database. | v0.0.0-alpha.0 |
busy_timeout_ms optional | number | SQLite busy timeout in milliseconds. | v0.0.0-alpha.0 |
max_connections optional | number | Maximum connection pool size (defaults to 1 for ":memory:"). | v0.0.0-alpha.0 |
NetworkDbConfig
Section titled “NetworkDbConfig”export interface NetworkDbConfig {
driver: "postgres" | "mysql" | "mariadb" | "mssql";
host: string;
port?: number;
database: string;
user: string;
password?: string;
tls?: boolean;
tlsMode?: "verifyFull" | "insecure" | "plaintext";
caFile?: string;
max_connections?: number;
connect_timeout_ms?: number;
}
Network database configuration for feature-gated PostgreSQL, MySQL, MariaDB, and Microsoft SQL Server providers.
When the build does not enable the requested driver feature (vael-db-postgres,
vael-db-mysql, vael-db-mariadb, vael-db-mssql, or vael-db-all),
open() validates the configuration strictly and rejects with
DbError (code === "DRIVER_UNAVAILABLE").
| Property | Type | Description | Since |
|---|---|---|---|
driver | "postgres" | "mysql" | "mariadb" | "mssql" | Network SQL driver name. | v0.0.0-alpha.0 |
host | string | Database server hostname or IP address. | v0.0.0-alpha.0 |
port optional | number | Database server TCP port (defaults to 5432, 3306, 3306, or 1433). | v0.0.0-alpha.0 |
database | string | Database or catalog name. | v0.0.0-alpha.0 |
user | string | Username for authentication. | v0.0.0-alpha.0 |
password optional | string | Optional password credential. | v0.0.0-alpha.0 |
tls optional | boolean | Whether to enable fail-closed TLS verification for the connection (defaults to true / "verifyFull"; pass tls: false or tlsMode: "plaintext" to opt into cleartext). | v0.0.0-alpha.0 |
tlsMode optional | "verifyFull" | "insecure" | "plaintext" | Explicit transport security mode ("verifyFull" | "insecure" | "plaintext", defaults to "verifyFull"). | v0.0.0-alpha.2 |
caFile optional | string | Explicit PEM CA certificate bundle path for "verifyFull" TLS mode. | v0.0.0-alpha.2 |
max_connections optional | number | Maximum connection pool size (1..=1024, defaults to 5). | v0.0.0-alpha.2 |
connect_timeout_ms optional | number | Connect/acquire timeout in milliseconds (1..=300000, defaults to 15000). | v0.0.0-alpha.2 |
DbTypedParam
Section titled “DbTypedParam”export interface DbTypedParam<V = unknown> {
readonly __vaelDbKind: "typed_param";
readonly type: "uuid" | "date" | "timestamp" | "timestampTz" | "decimal" | "json";
readonly value: unknown;
readonly __type?: V;
}
Typed SQL parameter wrapper created by sql.uuid, sql.date, sql.timestamp,
sql.timestampTz, sql.decimal, or sql.json.
| Property | Type | Description | Since |
|---|---|---|---|
__vaelDbKind readonly | "typed_param" | — | v0.0.0-alpha.2 |
type readonly | "uuid" | "date" | "timestamp" | "timestampTz" | "decimal" | "json" | — | v0.0.0-alpha.2 |
value readonly | unknown | — | v0.0.0-alpha.2 |
__type readonly optional | V | — | v0.0.0-alpha.2 |
DbQueryOptions
Section titled “DbQueryOptions”export interface DbQueryOptions {
readonly timeoutMs?: number;
readonly maxRows?: number;
readonly maxBytes?: number;
}
Per-query execution bounds (maxRows <= 100,000, maxBytes <= 32 MiB, timeoutMs <= 300,000).
| Property | Type | Description | Since |
|---|---|---|---|
timeoutMs readonly optional | number | Per-query deadline in milliseconds (1..=300000). Note: SQLite rejects timeoutMs with Unsupported. | v0.0.0-alpha.2 |
maxRows readonly optional | number | Maximum result rows (1..=100000, defaults to 1000). | v0.0.0-alpha.2 |
maxBytes readonly optional | number | Maximum aggregate result bytes (1..=33554432, defaults to 1048576). | v0.0.0-alpha.2 |
DbExecuteResult
Section titled “DbExecuteResult”export interface DbExecuteResult {
rowsAffected: number;
}
Result returned by execute().
| Property | Type | Description | Since |
|---|---|---|---|
rowsAffected | number | Number of rows inserted, updated, or deleted by the statement. | v0.0.0-alpha.0 |
DbTableRef
Section titled “DbTableRef”export interface DbTableRef<Name extends string = string, Alias extends string = Name> {
readonly name: Name;
readonly schema?: string;
readonly as?: Alias;
}
Qualified or aliased SQL table reference.
| Property | Type | Description | Since |
|---|---|---|---|
name readonly | Name | Table name. | v0.0.0-alpha.2 |
schema readonly optional | string | Optional schema qualifier. | v0.0.0-alpha.2 |
as readonly optional | Alias | Optional table alias. | v0.0.0-alpha.2 |
DbColumnRef
Section titled “DbColumnRef”export interface DbColumnRef<T extends string = string, C extends string = string> {
readonly __vaelDbKind?: "column";
readonly table?: T;
readonly column: C;
}
Explicit SQL column or identifier reference (col(...) / sql.ident(...)).
| Property | Type | Description | Since |
|---|---|---|---|
__vaelDbKind readonly optional | "column" | — | v0.0.0-alpha.2 |
table readonly optional | T | — | v0.0.0-alpha.2 |
column readonly | C | — | v0.0.0-alpha.2 |
DbExpr
Section titled “DbExpr”export interface DbExpr<V = unknown> {
readonly __vaelDbKind?: "expr";
readonly __type?: V;
}
Composable AST expression node built by ExprBuilder or func().
| Property | Type | Description | Since |
|---|---|---|---|
__vaelDbKind readonly optional | "expr" | — | v0.0.0-alpha.2 |
__type readonly optional | V | — | v0.0.0-alpha.2 |
SqlFragment
Section titled “SqlFragment”export interface SqlFragment {
readonly __vaelDbKind?: "sql_fragment";
readonly sql: string;
readonly params: readonly DbParamValue[];
toSql(dialect: DbDialect): RenderedSql;
}
Parameterized SQL fragment returned by the sql tagged template or sql.raw / sql.join.
| Property | Type | Description | Since |
|---|---|---|---|
__vaelDbKind readonly optional | "sql_fragment" | — | v0.0.0-alpha.2 |
sql readonly | string | Preview SQL string with ? placeholders and double-quoted identifiers. | v0.0.0-alpha.2 |
params readonly | readonly DbParamValue[] | Ordered parameter values bound by this fragment. | v0.0.0-alpha.2 |
SqlFragment.toSql
Section titled “SqlFragment.toSql”toSql(dialect: DbDialect): RenderedSql;
Render this fragment into dialect-specific SQL and parameters.
| Name | Type | Description |
|---|---|---|
dialect | DbDialect | Target SQL dialect. |
DbError— ("INVALID_PARAM"or"SQL") on invalid SQL or placeholder syntax.
RenderedSql
Section titled “RenderedSql”export interface RenderedSql {
readonly sql: string;
readonly params: unknown[];
}
Dialect-specific rendered SQL text paired with its ordered bound parameters.
| Property | Type | Description | Since |
|---|---|---|---|
sql readonly | string | Dialect-specific rendered SQL text. | v0.0.0-alpha.2 |
params readonly | unknown[] | Ordered bound parameter values. | v0.0.0-alpha.2 |
AnySelectBuilder
Section titled “AnySelectBuilder”export interface AnySelectBuilder<out SelectedRow = DbRow> {
toSql(dialect?: DbDialect): RenderedSql;
all(): Promise<SelectedRow[]>;
first(): Promise<SelectedRow | null>;
one(): Promise<SelectedRow>;
exists(): Promise<boolean>;
count(): Promise<number | bigint>;
}
Covariant read-only query shape satisfied by any SelectBuilder,
regardless of schema <DB>, table <T>, or source TableRow.
AnySelectBuilder.toSql
Section titled “AnySelectBuilder.toSql”toSql(dialect?: DbDialect): RenderedSql;
Render this query for dialect (or the bound handle’s dialect).
| Name | Type | Description |
|---|---|---|
dialect optional | DbDialect | — |
AnySelectBuilder.all
Section titled “AnySelectBuilder.all”all(): Promise<SelectedRow[]>;
Execute and return all matching rows (bounded by DbQueryOptions).
Promise<SelectedRow[]>AnySelectBuilder.first
Section titled “AnySelectBuilder.first”first(): Promise<SelectedRow | null>;
Execute with LIMIT 1 and return the first row, or null.
Promise<SelectedRow | null>AnySelectBuilder.one
Section titled “AnySelectBuilder.one”one(): Promise<SelectedRow>;
Execute with LIMIT 2 and return the single matching row.
Promise<SelectedRow>DbError— ("CARDINALITY"/NoRowsorTooManyRows) unless exactly 1 row matches.
AnySelectBuilder.exists
Section titled “AnySelectBuilder.exists”exists(): Promise<boolean>;
Execute an EXISTS (...) check and return whether at least one row matches.
Promise<boolean>AnySelectBuilder.count
Section titled “AnySelectBuilder.count”count(): Promise<number | bigint>;
Execute SELECT COUNT(*) and return the row count.
Promise<number | bigint>AnyMutationBuilder
Section titled “AnyMutationBuilder”export interface AnyMutationBuilder<out ReturningRow = never> {
readonly __vaelReturning?: ReturningRow;
toSql(dialect?: DbDialect): RenderedSql;
execute(): Promise<DbExecuteResult>;
all(): Promise<ReturningRow[]>;
first(): Promise<ReturningRow | null>;
one(): Promise<ReturningRow>;
}
Covariant mutation query shape satisfied by any InsertBuilder,
UpdateBuilder, or DeleteBuilder, regardless of <DB>, <T>, or <Row>.
| Property | Type | Description | Since |
|---|---|---|---|
__vaelReturning readonly optional | ReturningRow | — | v0.0.0-alpha.2 |
AnyMutationBuilder.toSql
Section titled “AnyMutationBuilder.toSql”toSql(dialect?: DbDialect): RenderedSql;
Render this mutation query for dialect (or the bound handle’s dialect).
| Name | Type | Description |
|---|---|---|
dialect optional | DbDialect | — |
AnyMutationBuilder.execute
Section titled “AnyMutationBuilder.execute”execute(): Promise<DbExecuteResult>;
Execute the mutation without RETURNING rows and return { rowsAffected }.
AnyMutationBuilder.all
Section titled “AnyMutationBuilder.all”all(): Promise<ReturningRow[]>;
Execute with RETURNING and return all affected rows.
Promise<ReturningRow[]>AnyMutationBuilder.first
Section titled “AnyMutationBuilder.first”first(): Promise<ReturningRow | null>;
Execute with RETURNING and return the first row, or null.
Promise<ReturningRow | null>AnyMutationBuilder.one
Section titled “AnyMutationBuilder.one”one(): Promise<ReturningRow>;
Execute with RETURNING and expect exactly one affected row.
Promise<ReturningRow>DbError— ("CARDINALITY"/NoRowsorTooManyRows) unless exactly 1 row is returned.
ExprBuilder
Section titled “ExprBuilder”export interface ExprBuilder<Row = DbRow> {
col<K extends keyof Row & string>(column: K): DbExpr<Row[K]>;
col(table: string, column: string): DbExpr<unknown>;
lit<V extends DbParamValue>(value: V): DbExpr<V>;
val<V extends DbParamValue>(value: V): DbExpr<V>;
null(): DbExpr<null>;
excluded(column: string): DbExpr<unknown>;
eq<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
eq(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
ne<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
ne(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
lt<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
lt(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
lte<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
lte(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
le(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
gt<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
gt(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
gte<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
gte(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
ge(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
like<K extends keyof Row & string>(column: K, pattern: string | DbExpr<string>): DbExpr<boolean>;
like(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
notLike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
iLike<K extends keyof Row & string>(column: K, pattern: string | DbExpr<string>): DbExpr<boolean>;
iLike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
ilike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
notILike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
notIlike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
inList<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
inList(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
in(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
notInList<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
notInList(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
notIn(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
isNull(column: (keyof Row & string) | DbExpr<unknown> | DbColumnRef): DbExpr<boolean>;
isNotNull(column: (keyof Row & string) | DbExpr<unknown> | DbColumnRef): DbExpr<boolean>;
between<K extends keyof Row & string>(
column: K,
low: Row[K] | DbExpr<Row[K]> | DbTypedParam,
high: Row[K] | DbExpr<Row[K]> | DbTypedParam,
): DbExpr<boolean>;
between(
lhs: DbExpr<unknown> | DbColumnRef | string,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DbExpr<boolean>;
notBetween(
lhs: DbExpr<unknown> | DbColumnRef | string,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DbExpr<boolean>;
and(...predicates: readonly (DbExpr<boolean> | SqlFragment)[]): DbExpr<boolean>;
or(...predicates: readonly (DbExpr<boolean> | SqlFragment)[]): DbExpr<boolean>;
not(predicate: DbExpr<boolean> | SqlFragment): DbExpr<boolean>;
add(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
sub(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
mul(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
div(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
neg(expr: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
func<V = unknown>(name: string, ...args: readonly unknown[]): DbExpr<V>;
countAll(): DbExpr<number | bigint>;
count(expr?: unknown): DbExpr<number | bigint>;
sum(expr: unknown): DbExpr<number | bigint | string | null>;
avg(expr: unknown): DbExpr<number | null>;
min<V = unknown>(expr: unknown): DbExpr<V | null>;
max<V = unknown>(expr: unknown): DbExpr<V | null>;
coalesce<V = unknown>(...args: readonly unknown[]): DbExpr<V>;
caseWhen<V = unknown>(
arms: readonly (readonly [DbExpr<boolean> | SqlFragment, unknown] | { readonly when: DbExpr<boolean> | SqlFragment; readonly then: unknown })[],
elseExpr?: unknown,
): DbExpr<V>;
exists(subquery: AnySelectBuilder<unknown>): DbExpr<boolean>;
subquery<V = unknown>(subquery: AnySelectBuilder<unknown>): DbExpr<V>;
raw(fragment: SqlFragment | string, params?: readonly DbParamValue[]): DbExpr<unknown>;
byDialect<V = unknown>(
defaultExpr: unknown,
overrides: Partial<Record<DbDialect, unknown>>,
): DbExpr<V>;
}
Expression builder passed to .where((eb) => ...), .orWhere(...),
.having(...), and .join(table, (eb) => ...).
ExprBuilder.col
Section titled “ExprBuilder.col”col<K extends keyof Row & string>(column: K): DbExpr<Row[K]>;
col(table: string, column: string): DbExpr<unknown>;
Reference an unqualified column in Row.
col(table, column)Reference a table-qualified column (table.column).
| Name | Type | Description |
|---|---|---|
table | string | — |
column | string | — |
DbExpr<unknown>ExprBuilder.lit
Section titled “ExprBuilder.lit”lit<V extends DbParamValue>(value: V): DbExpr<V>;
Bind a literal scalar, binary, or typed parameter value.
| Name | Type | Description |
|---|---|---|
value | V | — |
DbExpr<V>ExprBuilder.val
Section titled “ExprBuilder.val”val<V extends DbParamValue>(value: V): DbExpr<V>;
Alias for lit(value): bind a parameter value.
| Name | Type | Description |
|---|---|---|
value | V | — |
DbExpr<V>ExprBuilder.null
Section titled “ExprBuilder.null”null(): DbExpr<null>;
Emit a SQL NULL literal expression.
DbExpr<null>ExprBuilder.excluded
Section titled “ExprBuilder.excluded”excluded(column: string): DbExpr<unknown>;
Reference EXCLUDED.<column> (or VALUES(<column>) on MySQL/MariaDB) in conflict updates.
| Name | Type | Description |
|---|---|---|
column | string | — |
DbExpr<unknown>ExprBuilder.eq
Section titled “ExprBuilder.eq”eq<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
eq(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs = rhs.
eq(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>eq(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.ne
Section titled “ExprBuilder.ne”ne<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
ne(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs <> rhs.
ne(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>ne(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.lt
Section titled “ExprBuilder.lt”lt<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
lt(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs < rhs.
lt(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>lt(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.lte
Section titled “ExprBuilder.lte”lte<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
lte(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs <= rhs.
lte(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>lte(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.le
Section titled “ExprBuilder.le”le(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Alias for lte(lhs, rhs): build lhs <= rhs.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.gt
Section titled “ExprBuilder.gt”gt<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
gt(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs > rhs.
gt(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>gt(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.gte
Section titled “ExprBuilder.gte”gte<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam,
): DbExpr<boolean>;
gte(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Build lhs >= rhs.
gte(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | DbTypedParam | — |
DbExpr<boolean>gte(lhs, rhs)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.ge
Section titled “ExprBuilder.ge”ge(
lhs: DbExpr<unknown> | DbColumnRef | SqlFragment | string,
rhs: DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue,
): DbExpr<boolean>;
Alias for gte(lhs, rhs): build lhs >= rhs.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | SqlFragment | string | — |
rhs | DbExpr<unknown> | DbColumnRef | SqlFragment | DbParamValue | — |
DbExpr<boolean>ExprBuilder.like
Section titled “ExprBuilder.like”like<K extends keyof Row & string>(column: K, pattern: string | DbExpr<string>): DbExpr<boolean>;
like(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Build lhs LIKE pattern.
like(column, pattern)| Name | Type | Description |
|---|---|---|
column | K | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>like(lhs, pattern)| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.notLike
Section titled “ExprBuilder.notLike”notLike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Build lhs NOT LIKE pattern.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.iLike
Section titled “ExprBuilder.iLike”iLike<K extends keyof Row & string>(column: K, pattern: string | DbExpr<string>): DbExpr<boolean>;
iLike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Build dialect-portable case-insensitive ILIKE (ILIKE on PostgreSQL, LOWER(...) LIKE LOWER(...) elsewhere).
iLike(column, pattern)| Name | Type | Description |
|---|---|---|
column | K | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>iLike(lhs, pattern)Build dialect-portable case-insensitive ILIKE.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.ilike
Section titled “ExprBuilder.ilike”ilike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Alias for iLike.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.notILike
Section titled “ExprBuilder.notILike”notILike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Build negated case-insensitive NOT (lhs ILIKE pattern).
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.notIlike
Section titled “ExprBuilder.notIlike”notIlike(lhs: DbExpr<unknown> | DbColumnRef | string, pattern: string | DbExpr<string>): DbExpr<boolean>;
Alias for notILike.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
pattern | string | DbExpr<string> | — |
DbExpr<boolean>ExprBuilder.inList
Section titled “ExprBuilder.inList”inList<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
inList(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
Build column IN (...) from a value list or scalar subquery.
inList(column, values)| Name | Type | Description |
|---|---|---|
column | K | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>inList(lhs, values)Build lhs IN (...) from a value list or scalar subquery.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
values | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>ExprBuilder.in
Section titled “ExprBuilder.in”in(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
Alias for inList.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
values | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>ExprBuilder.notInList
Section titled “ExprBuilder.notInList”notInList<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
notInList(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
Build column NOT IN (...) from a value list or scalar subquery.
notInList(column, values)| Name | Type | Description |
|---|---|---|
column | K | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>notInList(lhs, values)Build lhs NOT IN (...) from a value list or scalar subquery.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
values | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>ExprBuilder.notIn
Section titled “ExprBuilder.notIn”notIn(
lhs: DbExpr<unknown> | DbColumnRef | string,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DbExpr<boolean>;
Alias for notInList.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
values | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DbExpr<boolean>ExprBuilder.isNull
Section titled “ExprBuilder.isNull”isNull(column: (keyof Row & string) | DbExpr<unknown> | DbColumnRef): DbExpr<boolean>;
Build column IS NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbExpr<unknown> | DbColumnRef | — |
DbExpr<boolean>ExprBuilder.isNotNull
Section titled “ExprBuilder.isNotNull”isNotNull(column: (keyof Row & string) | DbExpr<unknown> | DbColumnRef): DbExpr<boolean>;
Build column IS NOT NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbExpr<unknown> | DbColumnRef | — |
DbExpr<boolean>ExprBuilder.between
Section titled “ExprBuilder.between”between<K extends keyof Row & string>(
column: K,
low: Row[K] | DbExpr<Row[K]> | DbTypedParam,
high: Row[K] | DbExpr<Row[K]> | DbTypedParam,
): DbExpr<boolean>;
between(
lhs: DbExpr<unknown> | DbColumnRef | string,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DbExpr<boolean>;
Build column BETWEEN low AND high.
between(column, low, high)| Name | Type | Description |
|---|---|---|
column | K | — |
low | Row[K] | DbExpr<Row[K]> | DbTypedParam | — |
high | Row[K] | DbExpr<Row[K]> | DbTypedParam | — |
DbExpr<boolean>between(lhs, low, high)Build lhs BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
low | DbParamValue | DbExpr<unknown> | — |
high | DbParamValue | DbExpr<unknown> | — |
DbExpr<boolean>ExprBuilder.notBetween
Section titled “ExprBuilder.notBetween”notBetween(
lhs: DbExpr<unknown> | DbColumnRef | string,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DbExpr<boolean>;
Build lhs NOT BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | string | — |
low | DbParamValue | DbExpr<unknown> | — |
high | DbParamValue | DbExpr<unknown> | — |
DbExpr<boolean>ExprBuilder.and
Section titled “ExprBuilder.and”and(...predicates: readonly (DbExpr<boolean> | SqlFragment)[]): DbExpr<boolean>;
Combine predicates with logical AND.
| Name | Type | Description |
|---|---|---|
...predicates | readonly (DbExpr<boolean> | SqlFragment)[] | — |
DbExpr<boolean>ExprBuilder.or
Section titled “ExprBuilder.or”or(...predicates: readonly (DbExpr<boolean> | SqlFragment)[]): DbExpr<boolean>;
Combine predicates with logical OR.
| Name | Type | Description |
|---|---|---|
...predicates | readonly (DbExpr<boolean> | SqlFragment)[] | — |
DbExpr<boolean>ExprBuilder.not
Section titled “ExprBuilder.not”not(predicate: DbExpr<boolean> | SqlFragment): DbExpr<boolean>;
Negate a predicate with NOT (...).
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
DbExpr<boolean>ExprBuilder.add
Section titled “ExprBuilder.add”add(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
Build arithmetic addition (lhs + rhs).
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
rhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
DbExpr<number>ExprBuilder.sub
Section titled “ExprBuilder.sub”sub(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
Build arithmetic subtraction (lhs - rhs).
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
rhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
DbExpr<number>ExprBuilder.mul
Section titled “ExprBuilder.mul”mul(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
Build arithmetic multiplication (lhs * rhs).
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
rhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
DbExpr<number>ExprBuilder.div
Section titled “ExprBuilder.div”div(lhs: DbExpr<unknown> | DbColumnRef | DbParamValue, rhs: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
Build arithmetic division (lhs / rhs).
| Name | Type | Description |
|---|---|---|
lhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
rhs | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
DbExpr<number>ExprBuilder.neg
Section titled “ExprBuilder.neg”neg(expr: DbExpr<unknown> | DbColumnRef | DbParamValue): DbExpr<number>;
Build arithmetic negation (-expr).
| Name | Type | Description |
|---|---|---|
expr | DbExpr<unknown> | DbColumnRef | DbParamValue | — |
DbExpr<number>ExprBuilder.func
Section titled “ExprBuilder.func”func<V = unknown>(name: string, ...args: readonly unknown[]): DbExpr<V>;
Build a validated SQL function call name(...args).
| Name | Type | Description |
|---|---|---|
name | string | — |
...args | readonly unknown[] | — |
DbExpr<V>ExprBuilder.countAll
Section titled “ExprBuilder.countAll”countAll(): DbExpr<number | bigint>;
Build COUNT(*).
DbExpr<number | bigint>ExprBuilder.count
Section titled “ExprBuilder.count”count(expr?: unknown): DbExpr<number | bigint>;
Build COUNT(*) or COUNT(expr).
| Name | Type | Description |
|---|---|---|
expr optional | unknown | — |
DbExpr<number | bigint>ExprBuilder.sum
Section titled “ExprBuilder.sum”sum(expr: unknown): DbExpr<number | bigint | string | null>;
Build SUM(expr).
| Name | Type | Description |
|---|---|---|
expr | unknown | — |
DbExpr<number | bigint | string | null>ExprBuilder.avg
Section titled “ExprBuilder.avg”avg(expr: unknown): DbExpr<number | null>;
Build AVG(expr).
| Name | Type | Description |
|---|---|---|
expr | unknown | — |
DbExpr<number | null>ExprBuilder.min
Section titled “ExprBuilder.min”min<V = unknown>(expr: unknown): DbExpr<V | null>;
Build MIN(expr).
| Name | Type | Description |
|---|---|---|
expr | unknown | — |
DbExpr<V | null>ExprBuilder.max
Section titled “ExprBuilder.max”max<V = unknown>(expr: unknown): DbExpr<V | null>;
Build MAX(expr).
| Name | Type | Description |
|---|---|---|
expr | unknown | — |
DbExpr<V | null>ExprBuilder.coalesce
Section titled “ExprBuilder.coalesce”coalesce<V = unknown>(...args: readonly unknown[]): DbExpr<V>;
Build COALESCE(...args).
| Name | Type | Description |
|---|---|---|
...args | readonly unknown[] | — |
DbExpr<V>ExprBuilder.caseWhen
Section titled “ExprBuilder.caseWhen”caseWhen<V = unknown>(
arms: readonly (readonly [DbExpr<boolean> | SqlFragment, unknown] | { readonly when: DbExpr<boolean> | SqlFragment; readonly then: unknown })[],
elseExpr?: unknown,
): DbExpr<V>;
Build a searched CASE WHEN ... THEN ... [ELSE ...] END expression.
| Name | Type | Description |
|---|---|---|
arms | readonly (readonly [DbExpr<boolean> | SqlFragment, unknown] | { readonly when: DbExpr<boolean> | SqlFragment; readonly then: unknown })[] | — |
elseExpr optional | unknown | — |
DbExpr<V>ExprBuilder.exists
Section titled “ExprBuilder.exists”exists(subquery: AnySelectBuilder<unknown>): DbExpr<boolean>;
Build an EXISTS (SELECT ...) predicate.
| Name | Type | Description |
|---|---|---|
subquery | AnySelectBuilder<unknown> | — |
DbExpr<boolean>ExprBuilder.subquery
Section titled “ExprBuilder.subquery”subquery<V = unknown>(subquery: AnySelectBuilder<unknown>): DbExpr<V>;
Embed a scalar SelectBuilder as a parenthesized subquery expression.
| Name | Type | Description |
|---|---|---|
subquery | AnySelectBuilder<unknown> | — |
DbExpr<V>ExprBuilder.raw
Section titled “ExprBuilder.raw”raw(fragment: SqlFragment | string, params?: readonly DbParamValue[]): DbExpr<unknown>;
Embed a validated raw SQL expression fragment (sql.raw semantics).
| Name | Type | Description |
|---|---|---|
fragment | SqlFragment | string | — |
params optional | readonly DbParamValue[] | — |
DbExpr<unknown>ExprBuilder.byDialect
Section titled “ExprBuilder.byDialect”byDialect<V = unknown>(
defaultExpr: unknown,
overrides: Partial<Record<DbDialect, unknown>>,
): DbExpr<V>;
Select a dialect-specific expression with an optional default fallback.
DbExpr<V>SelectBuilder
Section titled “SelectBuilder”export interface SelectBuilder<
DB = DbSchema,
T extends string = string,
TableRow = DbRowFor<DB, T>,
SelectedRow = TableRow,
> extends AnySelectBuilder<SelectedRow> {
from<NextT extends (keyof DB & string) | (string & {}) | DbTableRef>(
table: NextT,
): SelectBuilder<DB, TableNameOf<NextT>, ResolveTableRow<DB, NextT>, ResolveTableRow<DB, NextT>>;
with(name: string, cte: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
withRecursive(name: string, cte: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
distinct(): SelectBuilder<DB, T, TableRow, SelectedRow>;
select<K extends keyof TableRow & string>(
first: K,
...rest: readonly K[]
): SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>;
select<K extends keyof TableRow & string>(
columns: readonly [K, ...K[]],
): SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>;
select<M extends Record<string, (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment>>(
projection: M,
): SelectBuilder<
DB,
T,
TableRow,
MergeSelected<
TableRow,
SelectedRow,
{ [P in keyof M]: M[P] extends keyof TableRow ? TableRow[M[P]] : M[P] extends DbExpr<infer V> ? V : unknown }
>
>;
select(
first: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[]
): SelectBuilder<DB, T, TableRow, DbRow>;
selectAll(): SelectBuilder<DB, T, TableRow, TableRow>;
selectTableAll(table: string): SelectBuilder<DB, T, TableRow, DbRow>;
where<K extends keyof TableRow & string>(
column: K,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
where<K extends keyof TableRow & string>(
column: K,
op: CompareOp,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(criteria: Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }>): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(fn: (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(predicate: DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere<K extends keyof TableRow & string>(
column: K,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere<K extends keyof TableRow & string>(
column: K,
op: CompareOp,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(criteria: Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }>): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(fn: (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereIn<K extends keyof TableRow & string>(
column: K,
values: readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotIn<K extends keyof TableRow & string>(
column: K,
values: readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNull(column: (keyof TableRow & string) | DbColumnRef | DbExpr<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotNull(column: (keyof TableRow & string) | DbColumnRef | DbExpr<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereBetween<K extends keyof TableRow & string>(
column: K,
low: TableRow[K] | DbTypedParam,
high: TableRow[K] | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotBetween<K extends keyof TableRow & string>(
column: K,
low: TableRow[K] | DbTypedParam,
high: TableRow[K] | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereLike<K extends keyof TableRow & string>(column: K, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereILike<K extends keyof TableRow & string>(column: K, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereExists(subquery: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
when<NextSelectedRow = SelectedRow>(
condition: unknown,
apply: (q: SelectBuilder<DB, T, TableRow, SelectedRow>) => SelectBuilder<DB, T, TableRow, NextSelectedRow>,
): SelectBuilder<DB, T, TableRow, NextSelectedRow>;
join(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
join(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
innerJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
innerJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
leftJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
leftJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
rightJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
rightJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
fullJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
fullJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
crossJoin(table: string | DbTableRef): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
groupBy(
...columns: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[]
): SelectBuilder<DB, T, TableRow, SelectedRow>;
groupBy(
columns: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[],
): SelectBuilder<DB, T, TableRow, SelectedRow>;
having(
predicate: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orderBy(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
dir?: "asc" | "desc",
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orderBy(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts: { readonly dir?: "asc" | "desc"; readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orderAsc(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orderDesc(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
limit(count: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
offset(count: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
page(limit: number, offset: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
forUpdate(mode?: "update" | "skipLocked" | "nowait"): SelectBuilder<DB, T, TableRow, SelectedRow>;
forShare(): SelectBuilder<DB, T, TableRow, SelectedRow>;
union(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
unionAll(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
intersect(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
except(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
options(opts: DbQueryOptions): SelectBuilder<DB, T, TableRow, SelectedRow>;
value<K extends keyof SelectedRow & string>(column: K): Promise<SelectedRow[K] | null>;
value(column: DbColumnRef): Promise<unknown>;
pluck<K extends keyof SelectedRow & string>(column: K): Promise<SelectedRow[K][]>;
pluck(column: DbColumnRef): Promise<unknown[]>;
}
Immutable fluent SELECT query builder.
TableRow tracks the source table’s columns for .where(), .groupBy(),
.orderBy(), and chained .select(), while SelectedRow tracks the
projected result row shape returned by .all(), .first(), .one(),
.value(), and .pluck().
SelectBuilder.from
Section titled “SelectBuilder.from”from<NextT extends (keyof DB & string) | (string & {}) | DbTableRef>(
table: NextT,
): SelectBuilder<DB, TableNameOf<NextT>, ResolveTableRow<DB, NextT>, ResolveTableRow<DB, NextT>>;
Set or replace the FROM table or CTE name.
| Name | Type | Description |
|---|---|---|
table | NextT | — |
SelectBuilder<DB, TableNameOf<NextT>, ResolveTableRow<DB, NextT>, ResolveTableRow<DB, NextT>>SelectBuilder.with
Section titled “SelectBuilder.with”with(name: string, cte: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Attach a non-recursive Common Table Expression (WITH name AS (...)).
| Name | Type | Description |
|---|---|---|
name | string | — |
cte | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.withRecursive
Section titled “SelectBuilder.withRecursive”withRecursive(name: string, cte: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Attach a recursive Common Table Expression (WITH RECURSIVE name AS (...)).
| Name | Type | Description |
|---|---|---|
name | string | — |
cte | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.distinct
Section titled “SelectBuilder.distinct”distinct(): SelectBuilder<DB, T, TableRow, SelectedRow>;
Emit SELECT DISTINCT.
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.select
Section titled “SelectBuilder.select”select<K extends keyof TableRow & string>(
first: K,
...rest: readonly K[]
): SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>;
select<K extends keyof TableRow & string>(
columns: readonly [K, ...K[]],
): SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>;
select<M extends Record<string, (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment>>(
projection: M,
): SelectBuilder<
DB,
T,
TableRow,
MergeSelected<
TableRow,
SelectedRow,
{ [P in keyof M]: M[P] extends keyof TableRow ? TableRow[M[P]] : M[P] extends DbExpr<infer V> ? V : unknown }
>
>;
select(
first: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[]
): SelectBuilder<DB, T, TableRow, DbRow>;
Project one or more columns from TableRow. Chained .select() calls append items.
select(first, ...rest)| Name | Type | Description |
|---|---|---|
first | K | — |
...rest | readonly K[] | — |
SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>select(columns)Project a non-empty array of column names from TableRow.
| Name | Type | Description |
|---|---|---|
columns | readonly [K, ...K[]] | — |
SelectBuilder<DB, T, TableRow, MergeSelected<TableRow, SelectedRow, Pick<TableRow, K>>>select(projection)Project an alias map { alias: columnOrExpr }.
| Name | Type | Description |
|---|---|---|
projection | M | — |
SelectBuilder<
DB,
T,
TableRow,
MergeSelected<
TableRow,
SelectedRow,
{ [P in keyof M]: M[P] extends keyof TableRow ? TableRow[M[P]] : M[P] extends DbExpr<infer V> ? V : unknown }
>
>select(first, ...rest)Project one or more columns, expressions, DbColumnRefs, or SqlFragments.
| Name | Type | Description |
|---|---|---|
first | (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment | — |
...rest | readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
SelectBuilder<DB, T, TableRow, DbRow>SelectBuilder.selectAll
Section titled “SelectBuilder.selectAll”selectAll(): SelectBuilder<DB, T, TableRow, TableRow>;
Append * to the projection list.
SelectBuilder<DB, T, TableRow, TableRow>SelectBuilder.selectTableAll
Section titled “SelectBuilder.selectTableAll”selectTableAll(table: string): SelectBuilder<DB, T, TableRow, DbRow>;
Append table.* to the projection list.
| Name | Type | Description |
|---|---|---|
table | string | — |
SelectBuilder<DB, T, TableRow, DbRow>SelectBuilder.where
Section titled “SelectBuilder.where”where<K extends keyof TableRow & string>(
column: K,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
where<K extends keyof TableRow & string>(
column: K,
op: CompareOp,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(criteria: Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }>): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(fn: (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(predicate: DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add an AND equality condition (column = value).
where(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
SelectBuilder<DB, T, TableRow, SelectedRow>where(column, op, value)Add an AND comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
SelectBuilder<DB, T, TableRow, SelectedRow>where(criteria)Add AND equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>where(fn)Add an AND predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>where(predicate)Add an AND predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>where(lhs, opOrVal, maybeVal?)Add an AND comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.orWhere
Section titled “SelectBuilder.orWhere”orWhere<K extends keyof TableRow & string>(
column: K,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere<K extends keyof TableRow & string>(
column: K,
op: CompareOp,
value: TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(criteria: Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }>): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(fn: (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): SelectBuilder<DB, T, TableRow, SelectedRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add an OR equality condition (column = value).
orWhere(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orWhere(column, op, value)Add an OR comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | TableRow[K] | DbExpr<TableRow[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orWhere(criteria)Add OR equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof TableRow]: TableRow[K] | undefined }> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orWhere(fn)Add an OR predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orWhere(predicate)Add an OR predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orWhere(lhs, opOrVal, maybeVal?)Add an OR comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereIn
Section titled “SelectBuilder.whereIn”whereIn<K extends keyof TableRow & string>(
column: K,
values: readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column IN (...).
Add AND lhs IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereNotIn
Section titled “SelectBuilder.whereNotIn”whereNotIn<K extends keyof TableRow & string>(
column: K,
values: readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column NOT IN (...).
Add AND lhs NOT IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (TableRow[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereNull
Section titled “SelectBuilder.whereNull”whereNull(column: (keyof TableRow & string) | DbColumnRef | DbExpr<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column IS NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbColumnRef | DbExpr<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereNotNull
Section titled “SelectBuilder.whereNotNull”whereNotNull(column: (keyof TableRow & string) | DbColumnRef | DbExpr<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column IS NOT NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbColumnRef | DbExpr<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereBetween
Section titled “SelectBuilder.whereBetween”whereBetween<K extends keyof TableRow & string>(
column: K,
low: TableRow[K] | DbTypedParam,
high: TableRow[K] | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column BETWEEN low AND high.
Add AND lhs BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
low | TableRow[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
high | TableRow[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereNotBetween
Section titled “SelectBuilder.whereNotBetween”whereNotBetween<K extends keyof TableRow & string>(
column: K,
low: TableRow[K] | DbTypedParam,
high: TableRow[K] | DbTypedParam,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereNotBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column NOT BETWEEN low AND high.
Add AND lhs NOT BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
low | TableRow[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
high | TableRow[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereLike
Section titled “SelectBuilder.whereLike”whereLike<K extends keyof TableRow & string>(column: K, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND column LIKE pattern.
Add AND lhs LIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereILike
Section titled “SelectBuilder.whereILike”whereILike<K extends keyof TableRow & string>(column: K, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add dialect-portable case-insensitive AND column ILIKE pattern.
Add dialect-portable case-insensitive AND lhs ILIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.whereExists
Section titled “SelectBuilder.whereExists”whereExists(subquery: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add AND EXISTS (subquery).
| Name | Type | Description |
|---|---|---|
subquery | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.when
Section titled “SelectBuilder.when”when<NextSelectedRow = SelectedRow>(
condition: unknown,
apply: (q: SelectBuilder<DB, T, TableRow, SelectedRow>) => SelectBuilder<DB, T, TableRow, NextSelectedRow>,
): SelectBuilder<DB, T, TableRow, NextSelectedRow>;
Conditionally transform this builder when condition is truthy.
| Name | Type | Description |
|---|---|---|
condition | unknown | — |
apply | (q: SelectBuilder<DB, T, TableRow, SelectedRow>) => SelectBuilder<DB, T, TableRow, NextSelectedRow> | — |
SelectBuilder<DB, T, TableRow, NextSelectedRow>SelectBuilder.join
Section titled “SelectBuilder.join”join(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
join(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add an INNER JOIN table ON ... clause.
join(table, on)| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
on | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>join(table, lhs, rhs)Add an INNER JOIN table ON lhs = rhs clause where both lhs and rhs are column refs/expressions.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
lhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
rhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.innerJoin
Section titled “SelectBuilder.innerJoin”innerJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
innerJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add an INNER JOIN table ON ... clause.
innerJoin(table, on)| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
on | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>innerJoin(table, lhs, rhs)Add an INNER JOIN table ON lhs = rhs clause where both lhs and rhs are column refs/expressions.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
lhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
rhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.leftJoin
Section titled “SelectBuilder.leftJoin”leftJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
leftJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add a LEFT JOIN table ON ... clause.
leftJoin(table, on)| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
on | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>leftJoin(table, lhs, rhs)Add a LEFT JOIN table ON lhs = rhs clause where both lhs and rhs are column refs/expressions.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
lhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
rhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.rightJoin
Section titled “SelectBuilder.rightJoin”rightJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
rightJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add a RIGHT JOIN table ON ... clause.
rightJoin(table, on)| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
on | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>rightJoin(table, lhs, rhs)Add a RIGHT JOIN table ON lhs = rhs clause where both lhs and rhs are column refs/expressions.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
lhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
rhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.fullJoin
Section titled “SelectBuilder.fullJoin”fullJoin(
table: string | DbTableRef,
on: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
fullJoin(
table: string | DbTableRef,
lhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
rhs: string | DbColumnRef | DbExpr<unknown> | SqlFragment,
): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add a FULL OUTER JOIN table ON ... clause (unsupported on SQLite/MySQL/MariaDB).
fullJoin(table, on)| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
on | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<DbRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>fullJoin(table, lhs, rhs)Add a FULL OUTER JOIN table ON lhs = rhs clause where both lhs and rhs are column refs/expressions.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
lhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
rhs | string | DbColumnRef | DbExpr<unknown> | SqlFragment | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.crossJoin
Section titled “SelectBuilder.crossJoin”crossJoin(table: string | DbTableRef): SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>;
Add a CROSS JOIN table clause.
| Name | Type | Description |
|---|---|---|
table | string | DbTableRef | — |
SelectBuilder<DB, T, DbRow, JoinSelectedRow<TableRow, SelectedRow>>SelectBuilder.groupBy
Section titled “SelectBuilder.groupBy”groupBy(
...columns: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[]
): SelectBuilder<DB, T, TableRow, SelectedRow>;
groupBy(
columns: readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[],
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Append GROUP BY columns or expressions.
groupBy(...columns)| Name | Type | Description |
|---|---|---|
...columns | readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
SelectBuilder<DB, T, TableRow, SelectedRow>groupBy(columns)Append GROUP BY columns or expressions from an array.
| Name | Type | Description |
|---|---|---|
columns | readonly ((keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.having
Section titled “SelectBuilder.having”having(
predicate: DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment),
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add an AND HAVING predicate.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | ((eb: ExprBuilder<TableRow>) => DbExpr<boolean> | SqlFragment) | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.orderBy
Section titled “SelectBuilder.orderBy”orderBy(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
dir?: "asc" | "desc",
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
orderBy(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts: { readonly dir?: "asc" | "desc"; readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Append an ORDER BY term with optional direction and nulls placement (SQLite/PostgreSQL).
orderBy(column, dir?, opts?)| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment | — |
dir optional | "asc" | "desc" | — |
opts optional | { readonly nulls?: "first" | "last" } | — |
SelectBuilder<DB, T, TableRow, SelectedRow>orderBy(column, opts)Append an ORDER BY term with an options object ({ dir, nulls }).
| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment | — |
opts | { readonly dir?: "asc" | "desc"; readonly nulls?: "first" | "last" } | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.orderAsc
Section titled “SelectBuilder.orderAsc”orderAsc(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Append ORDER BY column ASC with optional nulls placement (SQLite/PostgreSQL).
| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment | — |
opts optional | { readonly nulls?: "first" | "last" } | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.orderDesc
Section titled “SelectBuilder.orderDesc”orderDesc(
column: (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment,
opts?: { readonly nulls?: "first" | "last" },
): SelectBuilder<DB, T, TableRow, SelectedRow>;
Append ORDER BY column DESC with optional nulls placement (SQLite/PostgreSQL).
| Name | Type | Description |
|---|---|---|
column | (keyof TableRow & string) | DbExpr | DbColumnRef | SqlFragment | — |
opts optional | { readonly nulls?: "first" | "last" } | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.limit
Section titled “SelectBuilder.limit”limit(count: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
Set LIMIT count.
| Name | Type | Description |
|---|---|---|
count | number | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.offset
Section titled “SelectBuilder.offset”offset(count: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
Set OFFSET count.
| Name | Type | Description |
|---|---|---|
count | number | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.page
Section titled “SelectBuilder.page”page(limit: number, offset: number): SelectBuilder<DB, T, TableRow, SelectedRow>;
Set both LIMIT and OFFSET in one call.
| Name | Type | Description |
|---|---|---|
limit | number | — |
offset | number | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.forUpdate
Section titled “SelectBuilder.forUpdate”forUpdate(mode?: "update" | "skipLocked" | "nowait"): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add row-level FOR UPDATE locking ("update" | "skipLocked" | "nowait").
Unsupported on SQLite and MSSQL (DbError DATABASE / Unsupported).
| Name | Type | Description |
|---|---|---|
mode optional | "update" | "skipLocked" | "nowait" | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.forShare
Section titled “SelectBuilder.forShare”forShare(): SelectBuilder<DB, T, TableRow, SelectedRow>;
Add row-level FOR SHARE / LOCK IN SHARE MODE locking.
Unsupported on SQLite and MSSQL (DbError DATABASE / Unsupported).
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.union
Section titled “SelectBuilder.union”union(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Combine with another query using UNION.
| Name | Type | Description |
|---|---|---|
other | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.unionAll
Section titled “SelectBuilder.unionAll”unionAll(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Combine with another query using UNION ALL.
| Name | Type | Description |
|---|---|---|
other | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.intersect
Section titled “SelectBuilder.intersect”intersect(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Combine with another query using INTERSECT.
| Name | Type | Description |
|---|---|---|
other | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.except
Section titled “SelectBuilder.except”except(other: AnySelectBuilder<unknown>): SelectBuilder<DB, T, TableRow, SelectedRow>;
Combine with another query using EXCEPT.
| Name | Type | Description |
|---|---|---|
other | AnySelectBuilder<unknown> | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.options
Section titled “SelectBuilder.options”options(opts: DbQueryOptions): SelectBuilder<DB, T, TableRow, SelectedRow>;
Merge per-query execution options (maxRows, maxBytes, timeoutMs).
| Name | Type | Description |
|---|---|---|
opts | DbQueryOptions | — |
SelectBuilder<DB, T, TableRow, SelectedRow>SelectBuilder.value
Section titled “SelectBuilder.value”value<K extends keyof SelectedRow & string>(column: K): Promise<SelectedRow[K] | null>;
value(column: DbColumnRef): Promise<unknown>;
Fetch the scalar value of column from the first matching row.
Returns null both when zero rows matched and when the matched row’s
column value is SQL NULL (use .first() if you need to distinguish the two).
Fetch the scalar value of a DbColumnRef from the first matching row
(returns null both when zero rows matched and when the value is SQL NULL).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | Column name or alias present in SelectedRow. |
SelectBuilder.pluck
Section titled “SelectBuilder.pluck”pluck<K extends keyof SelectedRow & string>(column: K): Promise<SelectedRow[K][]>;
pluck(column: DbColumnRef): Promise<unknown[]>;
Fetch an array of scalar values for column across all matching rows.
Fetch an array of scalar values for a DbColumnRef across all matching rows.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | — |
InsertBuilder
Section titled “InsertBuilder”export interface InsertBuilder<
DB = DbSchema,
T extends string = string,
Row = DbRowFor<DB, T>,
ReturningRow = never,
> extends AnyMutationBuilder<ReturningRow> {
values(
rowOrRows:
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| readonly Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>[],
): InsertBuilder<DB, T, Row, ReturningRow>;
upsert(
conflictTarget: readonly (keyof Row & string)[],
updateColumns: readonly (keyof Row & string)[],
): InsertBuilder<DB, T, Row, ReturningRow>;
onConflict(
conflictTarget: readonly (keyof Row & string)[],
config:
| { readonly action: "ignore" }
| {
readonly action: "update";
readonly columns?: readonly (keyof Row & string)[];
readonly set?:
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue>;
},
): InsertBuilder<DB, T, Row, ReturningRow>;
insertIgnore(): InsertBuilder<DB, T, Row, ReturningRow>;
onDuplicateKeyUpdate(
assignments:
| readonly (keyof Row & string)[]
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue>,
): InsertBuilder<DB, T, Row, ReturningRow>;
returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): InsertBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): InsertBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): InsertBuilder<DB, T, Row, DbRow>;
returningAll(): InsertBuilder<DB, T, Row, Row>;
options(opts: DbQueryOptions): InsertBuilder<DB, T, Row, ReturningRow>;
all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
}
Immutable fluent INSERT query builder.
InsertBuilder.values
Section titled “InsertBuilder.values”values(
rowOrRows:
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| readonly Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>[],
): InsertBuilder<DB, T, Row, ReturningRow>;
Append one or more rows to insert. Keys set to undefined are omitted
so database DEFAULT values apply, while null explicitly binds SQL NULL.
| Name | Type | Description |
|---|---|---|
rowOrRows | | Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| readonly Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>[] | — |
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.upsert
Section titled “InsertBuilder.upsert”upsert(
conflictTarget: readonly (keyof Row & string)[],
updateColumns: readonly (keyof Row & string)[],
): InsertBuilder<DB, T, Row, ReturningRow>;
Shorthand for onConflict(conflictTarget, { action: "update", columns: updateColumns }).
Supported on SQLite and PostgreSQL; rejects MySQL/MariaDB/MSSQL with
DbError (DATABASE / Unsupported) — use onDuplicateKeyUpdate() on MySQL/MariaDB.
| Name | Type | Description |
|---|---|---|
conflictTarget | readonly (keyof Row & string)[] | — |
updateColumns | readonly (keyof Row & string)[] | — |
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.onConflict
Section titled “InsertBuilder.onConflict”onConflict(
conflictTarget: readonly (keyof Row & string)[],
config:
| { readonly action: "ignore" }
| {
readonly action: "update";
readonly columns?: readonly (keyof Row & string)[];
readonly set?:
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue>;
},
): InsertBuilder<DB, T, Row, ReturningRow>;
Configure ON CONFLICT (...) DO NOTHING or DO UPDATE SET ....
Supported on SQLite and PostgreSQL; rejects MySQL/MariaDB/MSSQL with
DbError (DATABASE / Unsupported).
| Name | Type | Description |
|---|---|---|
conflictTarget | readonly (keyof Row & string)[] | — |
config | | { readonly action: "ignore" }
| {
readonly action: "update";
readonly columns?: readonly (keyof Row & string)[];
readonly set?:
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue>;
} | — |
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.insertIgnore
Section titled “InsertBuilder.insertIgnore”insertIgnore(): InsertBuilder<DB, T, Row, ReturningRow>;
Emit MySQL/MariaDB INSERT IGNORE INTO ....
Rejects other dialects with DbError (DATABASE / Unsupported).
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.onDuplicateKeyUpdate
Section titled “InsertBuilder.onDuplicateKeyUpdate”onDuplicateKeyUpdate(
assignments:
| readonly (keyof Row & string)[]
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue>,
): InsertBuilder<DB, T, Row, ReturningRow>;
Emit MySQL/MariaDB ON DUPLICATE KEY UPDATE ....
Rejects other dialects with DbError (DATABASE / Unsupported).
| Name | Type | Description |
|---|---|---|
assignments | | readonly (keyof Row & string)[]
| Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>
| Record<string, DbExpr | DbColumnRef | SqlFragment | DbParamValue> | — |
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.returning
Section titled “InsertBuilder.returning”returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): InsertBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): InsertBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): InsertBuilder<DB, T, Row, DbRow>;
Emit RETURNING (or MSSQL OUTPUT INSERTED) for one or more columns.
Note: MySQL does not support INSERT ... RETURNING.
returning(first, ...rest)| Name | Type | Description |
|---|---|---|
first | K | — |
...rest | readonly K[] | — |
InsertBuilder<DB, T, Row, Pick<Row, K>>returning(columns)Emit RETURNING for a non-empty array of columns.
| Name | Type | Description |
|---|---|---|
columns | readonly [K, ...K[]] | — |
InsertBuilder<DB, T, Row, Pick<Row, K>>returning(first, ...rest)Emit RETURNING for columns, expressions, DbColumnRefs, or SqlFragments.
| Name | Type | Description |
|---|---|---|
first | (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment | — |
...rest | readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
InsertBuilder<DB, T, Row, DbRow>InsertBuilder.returningAll
Section titled “InsertBuilder.returningAll”returningAll(): InsertBuilder<DB, T, Row, Row>;
Emit RETURNING * (or MSSQL OUTPUT INSERTED.*).
InsertBuilder<DB, T, Row, Row>InsertBuilder.options
Section titled “InsertBuilder.options”options(opts: DbQueryOptions): InsertBuilder<DB, T, Row, ReturningRow>;
Merge per-query execution options (maxRows, maxBytes, timeoutMs).
| Name | Type | Description |
|---|---|---|
opts | DbQueryOptions | — |
InsertBuilder<DB, T, Row, ReturningRow>InsertBuilder.all
Section titled “InsertBuilder.all”all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
Execute with RETURNING and return all inserted rows (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow[]>InsertBuilder.first
Section titled “InsertBuilder.first”first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
Execute with RETURNING and return the first inserted row or null (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow | null>InsertBuilder.one
Section titled “InsertBuilder.one”one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
Execute with RETURNING and expect one inserted row (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow>UpdateBuilder
Section titled “UpdateBuilder”export interface UpdateBuilder<
DB = DbSchema,
T extends string = string,
Row = DbRowFor<DB, T>,
ReturningRow = never,
> extends AnyMutationBuilder<ReturningRow> {
set(
values: Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
set<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined,
): UpdateBuilder<DB, T, Row, ReturningRow>;
where<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
where<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
where(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): UpdateBuilder<DB, T, Row, ReturningRow>;
where(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
where(predicate: DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereNotIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): UpdateBuilder<DB, T, Row, ReturningRow>;
whereNotNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): UpdateBuilder<DB, T, Row, ReturningRow>;
whereBetween<K extends keyof Row & string>(
column: K,
low: Row[K] | DbTypedParam,
high: Row[K] | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereLike<K extends keyof Row & string>(column: K, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
whereILike<K extends keyof Row & string>(column: K, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
when(
condition: unknown,
apply: (q: UpdateBuilder<DB, T, Row, ReturningRow>) => UpdateBuilder<DB, T, Row, ReturningRow>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
unfiltered(): UpdateBuilder<DB, T, Row, ReturningRow>;
returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): UpdateBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): UpdateBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): UpdateBuilder<DB, T, Row, DbRow>;
returningAll(): UpdateBuilder<DB, T, Row, Row>;
options(opts: DbQueryOptions): UpdateBuilder<DB, T, Row, ReturningRow>;
all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
}
Immutable fluent UPDATE query builder (requires .where(...) or .unfiltered()
to prevent accidental full-table updates).
UpdateBuilder.set
Section titled “UpdateBuilder.set”set(
values: Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
set<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Assign multiple columns (undefined keys are skipped for PATCH semantics;
null explicitly sets SQL NULL).
set(values)| Name | Type | Description |
|---|---|---|
values | Partial<{ [K in keyof Row]: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined }> | — |
UpdateBuilder<DB, T, Row, ReturningRow>set(column, value)Assign a single column (undefined is a no-op; null sets SQL NULL).
| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam<Row[K]> | undefined | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.where
Section titled “UpdateBuilder.where”where<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
where<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
where(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): UpdateBuilder<DB, T, Row, ReturningRow>;
where(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
where(predicate: DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Add an AND equality condition (column = value).
where(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
UpdateBuilder<DB, T, Row, ReturningRow>where(column, op, value)Add an AND comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
UpdateBuilder<DB, T, Row, ReturningRow>where(criteria)Add AND equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof Row]: Row[K] | undefined }> | — |
UpdateBuilder<DB, T, Row, ReturningRow>where(fn)Add an AND predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>where(predicate)Add an AND predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>where(lhs, opOrVal, maybeVal?)Add an AND comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.orWhere
Section titled “UpdateBuilder.orWhere”orWhere<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): UpdateBuilder<DB, T, Row, ReturningRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Add an OR equality condition (column = value).
orWhere(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
UpdateBuilder<DB, T, Row, ReturningRow>orWhere(column, op, value)Add an OR comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
UpdateBuilder<DB, T, Row, ReturningRow>orWhere(criteria)Add OR equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof Row]: Row[K] | undefined }> | — |
UpdateBuilder<DB, T, Row, ReturningRow>orWhere(fn)Add an OR predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>orWhere(predicate)Add an OR predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>orWhere(lhs, opOrVal, maybeVal?)Add an OR comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereIn
Section titled “UpdateBuilder.whereIn”whereIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column IN (...).
Add AND lhs IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereNotIn
Section titled “UpdateBuilder.whereNotIn”whereNotIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column NOT IN (...).
Add AND lhs NOT IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereNull
Section titled “UpdateBuilder.whereNull”whereNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column IS NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbColumnRef | DbExpr<unknown> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereNotNull
Section titled “UpdateBuilder.whereNotNull”whereNotNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column IS NOT NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbColumnRef | DbExpr<unknown> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereBetween
Section titled “UpdateBuilder.whereBetween”whereBetween<K extends keyof Row & string>(
column: K,
low: Row[K] | DbTypedParam,
high: Row[K] | DbTypedParam,
): UpdateBuilder<DB, T, Row, ReturningRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column BETWEEN low AND high.
Add AND lhs BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
low | Row[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
high | Row[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereLike
Section titled “UpdateBuilder.whereLike”whereLike<K extends keyof Row & string>(column: K, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
Add AND column LIKE pattern.
Add AND lhs LIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.whereILike
Section titled “UpdateBuilder.whereILike”whereILike<K extends keyof Row & string>(column: K, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): UpdateBuilder<DB, T, Row, ReturningRow>;
Add dialect-portable case-insensitive AND column ILIKE pattern.
Add dialect-portable case-insensitive AND lhs ILIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.when
Section titled “UpdateBuilder.when”when(
condition: unknown,
apply: (q: UpdateBuilder<DB, T, Row, ReturningRow>) => UpdateBuilder<DB, T, Row, ReturningRow>,
): UpdateBuilder<DB, T, Row, ReturningRow>;
Conditionally transform this builder when condition is truthy.
| Name | Type | Description |
|---|---|---|
condition | unknown | — |
apply | (q: UpdateBuilder<DB, T, Row, ReturningRow>) => UpdateBuilder<DB, T, Row, ReturningRow> | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.unfiltered
Section titled “UpdateBuilder.unfiltered”unfiltered(): UpdateBuilder<DB, T, Row, ReturningRow>;
Explicitly allow an UPDATE with no WHERE clause (full-table update).
Without .where(...) or .unfiltered(), rendering rejects with reason === "MissingWhereClause".
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.returning
Section titled “UpdateBuilder.returning”returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): UpdateBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): UpdateBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): UpdateBuilder<DB, T, Row, DbRow>;
Emit RETURNING (or MSSQL OUTPUT INSERTED) for one or more columns.
Note: MySQL/MariaDB do not support UPDATE ... RETURNING.
returning(first, ...rest)| Name | Type | Description |
|---|---|---|
first | K | — |
...rest | readonly K[] | — |
UpdateBuilder<DB, T, Row, Pick<Row, K>>returning(columns)Emit RETURNING for a non-empty array of columns.
| Name | Type | Description |
|---|---|---|
columns | readonly [K, ...K[]] | — |
UpdateBuilder<DB, T, Row, Pick<Row, K>>returning(first, ...rest)Emit RETURNING for columns, expressions, DbColumnRefs, or SqlFragments.
| Name | Type | Description |
|---|---|---|
first | (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment | — |
...rest | readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
UpdateBuilder<DB, T, Row, DbRow>UpdateBuilder.returningAll
Section titled “UpdateBuilder.returningAll”returningAll(): UpdateBuilder<DB, T, Row, Row>;
Emit RETURNING * (or MSSQL OUTPUT INSERTED.*).
UpdateBuilder<DB, T, Row, Row>UpdateBuilder.options
Section titled “UpdateBuilder.options”options(opts: DbQueryOptions): UpdateBuilder<DB, T, Row, ReturningRow>;
Merge per-query execution options (maxRows, maxBytes, timeoutMs).
| Name | Type | Description |
|---|---|---|
opts | DbQueryOptions | — |
UpdateBuilder<DB, T, Row, ReturningRow>UpdateBuilder.all
Section titled “UpdateBuilder.all”all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
Execute with RETURNING and return all updated rows (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow[]>UpdateBuilder.first
Section titled “UpdateBuilder.first”first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
Execute with RETURNING and return the first updated row or null (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow | null>UpdateBuilder.one
Section titled “UpdateBuilder.one”one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
Execute with RETURNING and expect one updated row (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow>DeleteBuilder
Section titled “DeleteBuilder”export interface DeleteBuilder<
DB = DbSchema,
T extends string = string,
Row = DbRowFor<DB, T>,
ReturningRow = never,
> extends AnyMutationBuilder<ReturningRow> {
where<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
where<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
where(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): DeleteBuilder<DB, T, Row, ReturningRow>;
where(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
where(predicate: DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereNotIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): DeleteBuilder<DB, T, Row, ReturningRow>;
whereNotNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): DeleteBuilder<DB, T, Row, ReturningRow>;
whereBetween<K extends keyof Row & string>(
column: K,
low: Row[K] | DbTypedParam,
high: Row[K] | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereLike<K extends keyof Row & string>(column: K, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
whereILike<K extends keyof Row & string>(column: K, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
when(
condition: unknown,
apply: (q: DeleteBuilder<DB, T, Row, ReturningRow>) => DeleteBuilder<DB, T, Row, ReturningRow>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
unfiltered(): DeleteBuilder<DB, T, Row, ReturningRow>;
returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): DeleteBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): DeleteBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): DeleteBuilder<DB, T, Row, DbRow>;
returningAll(): DeleteBuilder<DB, T, Row, Row>;
options(opts: DbQueryOptions): DeleteBuilder<DB, T, Row, ReturningRow>;
all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
}
Immutable fluent DELETE query builder (requires .where(...) or .unfiltered()
to prevent accidental full-table deletes).
DeleteBuilder.where
Section titled “DeleteBuilder.where”where<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
where<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
where(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): DeleteBuilder<DB, T, Row, ReturningRow>;
where(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
where(predicate: DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
where(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Add an AND equality condition (column = value).
where(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
DeleteBuilder<DB, T, Row, ReturningRow>where(column, op, value)Add an AND comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
DeleteBuilder<DB, T, Row, ReturningRow>where(criteria)Add AND equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof Row]: Row[K] | undefined }> | — |
DeleteBuilder<DB, T, Row, ReturningRow>where(fn)Add an AND predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>where(predicate)Add an AND predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>where(lhs, opOrVal, maybeVal?)Add an AND comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.orWhere
Section titled “DeleteBuilder.orWhere”orWhere<K extends keyof Row & string>(
column: K,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere<K extends keyof Row & string>(
column: K,
op: CompareOp,
value: Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(criteria: Partial<{ [K in keyof Row]: Row[K] | undefined }>): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(fn: (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(predicate: DbExpr<boolean> | SqlFragment): DeleteBuilder<DB, T, Row, ReturningRow>;
orWhere(
lhs: DbColumnRef | DbExpr<unknown>,
opOrVal: CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
maybeVal?: DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Add an OR equality condition (column = value).
orWhere(column, value)| Name | Type | Description |
|---|---|---|
column | K | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
DeleteBuilder<DB, T, Row, ReturningRow>orWhere(column, op, value)Add an OR comparison condition (column op value).
| Name | Type | Description |
|---|---|---|
column | K | — |
op | CompareOp | — |
value | Row[K] | DbExpr<Row[K]> | DbColumnRef | SqlFragment | DbTypedParam | — |
DeleteBuilder<DB, T, Row, ReturningRow>orWhere(criteria)Add OR equality conditions for all non-undefined keys in criteria.
| Name | Type | Description |
|---|---|---|
criteria | Partial<{ [K in keyof Row]: Row[K] | undefined }> | — |
DeleteBuilder<DB, T, Row, ReturningRow>orWhere(fn)Add an OR predicate built via ExprBuilder.
| Name | Type | Description |
|---|---|---|
fn | (eb: ExprBuilder<Row>) => DbExpr<boolean> | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>orWhere(predicate)Add an OR predicate expression or SqlFragment.
| Name | Type | Description |
|---|---|---|
predicate | DbExpr<boolean> | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>orWhere(lhs, opOrVal, maybeVal?)Add an OR comparison on a DbColumnRef or DbExpr.
| Name | Type | Description |
|---|---|---|
lhs | DbColumnRef | DbExpr<unknown> | — |
opOrVal | CompareOp | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
maybeVal optional | DbParamValue | DbExpr<unknown> | DbColumnRef | SqlFragment | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereIn
Section titled “DeleteBuilder.whereIn”whereIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column IN (...).
Add AND lhs IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereNotIn
Section titled “DeleteBuilder.whereNotIn”whereNotIn<K extends keyof Row & string>(
column: K,
values: readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereNotIn(
column: DbColumnRef | DbExpr<unknown>,
values: readonly DbParamValue[] | AnySelectBuilder<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column NOT IN (...).
Add AND lhs NOT IN (...).
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
values | readonly (Row[K] | DbTypedParam)[] | AnySelectBuilder<unknown> | readonly DbParamValue[] | AnySelectBuilder<unknown> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereNull
Section titled “DeleteBuilder.whereNull”whereNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column IS NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbColumnRef | DbExpr<unknown> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereNotNull
Section titled “DeleteBuilder.whereNotNull”whereNotNull(column: (keyof Row & string) | DbColumnRef | DbExpr<unknown>): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column IS NOT NULL.
| Name | Type | Description |
|---|---|---|
column | (keyof Row & string) | DbColumnRef | DbExpr<unknown> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereBetween
Section titled “DeleteBuilder.whereBetween”whereBetween<K extends keyof Row & string>(
column: K,
low: Row[K] | DbTypedParam,
high: Row[K] | DbTypedParam,
): DeleteBuilder<DB, T, Row, ReturningRow>;
whereBetween(
column: DbColumnRef | DbExpr<unknown>,
low: DbParamValue | DbExpr<unknown>,
high: DbParamValue | DbExpr<unknown>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column BETWEEN low AND high.
Add AND lhs BETWEEN low AND high.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
low | Row[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
high | Row[K] | DbTypedParam | DbParamValue | DbExpr<unknown> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereLike
Section titled “DeleteBuilder.whereLike”whereLike<K extends keyof Row & string>(column: K, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
whereLike(column: DbColumnRef | DbExpr<unknown>, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
Add AND column LIKE pattern.
Add AND lhs LIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.whereILike
Section titled “DeleteBuilder.whereILike”whereILike<K extends keyof Row & string>(column: K, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
whereILike(column: DbColumnRef | DbExpr<unknown>, pattern: string): DeleteBuilder<DB, T, Row, ReturningRow>;
Add dialect-portable case-insensitive AND column ILIKE pattern.
Add dialect-portable case-insensitive AND lhs ILIKE pattern.
| Name | Type | Description |
|---|---|---|
column | K | DbColumnRef | DbExpr<unknown> | — |
pattern | string | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.when
Section titled “DeleteBuilder.when”when(
condition: unknown,
apply: (q: DeleteBuilder<DB, T, Row, ReturningRow>) => DeleteBuilder<DB, T, Row, ReturningRow>,
): DeleteBuilder<DB, T, Row, ReturningRow>;
Conditionally transform this builder when condition is truthy.
| Name | Type | Description |
|---|---|---|
condition | unknown | — |
apply | (q: DeleteBuilder<DB, T, Row, ReturningRow>) => DeleteBuilder<DB, T, Row, ReturningRow> | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.unfiltered
Section titled “DeleteBuilder.unfiltered”unfiltered(): DeleteBuilder<DB, T, Row, ReturningRow>;
Explicitly allow a DELETE with no WHERE clause (full-table delete).
Without .where(...) or .unfiltered(), rendering rejects with reason === "MissingWhereClause".
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.returning
Section titled “DeleteBuilder.returning”returning<K extends keyof Row & string>(
first: K,
...rest: readonly K[]
): DeleteBuilder<DB, T, Row, Pick<Row, K>>;
returning<K extends keyof Row & string>(
columns: readonly [K, ...K[]],
): DeleteBuilder<DB, T, Row, Pick<Row, K>>;
returning(
first: (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment,
...rest: readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[]
): DeleteBuilder<DB, T, Row, DbRow>;
Emit RETURNING (or MSSQL OUTPUT DELETED) for one or more columns.
Note: MySQL does not support DELETE ... RETURNING.
returning(first, ...rest)| Name | Type | Description |
|---|---|---|
first | K | — |
...rest | readonly K[] | — |
DeleteBuilder<DB, T, Row, Pick<Row, K>>returning(columns)Emit RETURNING for a non-empty array of columns.
| Name | Type | Description |
|---|---|---|
columns | readonly [K, ...K[]] | — |
DeleteBuilder<DB, T, Row, Pick<Row, K>>returning(first, ...rest)Emit RETURNING for columns, expressions, DbColumnRefs, or SqlFragments.
| Name | Type | Description |
|---|---|---|
first | (keyof Row & string) | DbExpr | DbColumnRef | SqlFragment | — |
...rest | readonly ((keyof Row & string) | DbExpr | DbColumnRef | SqlFragment)[] | — |
DeleteBuilder<DB, T, Row, DbRow>DeleteBuilder.returningAll
Section titled “DeleteBuilder.returningAll”returningAll(): DeleteBuilder<DB, T, Row, Row>;
Emit RETURNING * (or MSSQL OUTPUT DELETED.*).
DeleteBuilder<DB, T, Row, Row>DeleteBuilder.options
Section titled “DeleteBuilder.options”options(opts: DbQueryOptions): DeleteBuilder<DB, T, Row, ReturningRow>;
Merge per-query execution options (maxRows, maxBytes, timeoutMs).
| Name | Type | Description |
|---|---|---|
opts | DbQueryOptions | — |
DeleteBuilder<DB, T, Row, ReturningRow>DeleteBuilder.all
Section titled “DeleteBuilder.all”all(): [ReturningRow] extends [never] ? never : Promise<ReturningRow[]>;
Execute with RETURNING and return all deleted rows (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow[]>DeleteBuilder.first
Section titled “DeleteBuilder.first”first(): [ReturningRow] extends [never] ? never : Promise<ReturningRow | null>;
Execute with RETURNING and return the first deleted row or null (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow | null>DeleteBuilder.one
Section titled “DeleteBuilder.one”one(): [ReturningRow] extends [never] ? never : Promise<ReturningRow>;
Execute with RETURNING and expect one deleted row (never unless .returning*() was called).
[ReturningRow] extends [never] ? never : Promise<ReturningRow>BoundSqlRunner
Section titled “BoundSqlRunner”export interface BoundSqlRunner<Row = DbRow> {
options(opts: DbQueryOptions): BoundSqlRunner<Row>;
toSql(dialect?: DbDialect): RenderedSql;
execute(): Promise<DbExecuteResult>;
all(): Promise<Row[]>;
first(): Promise<Row | null>;
one(): Promise<Row>;
}
Executable tagged-template query runner returned by db.sql\…`andtx.sql`…``.
BoundSqlRunner.options
Section titled “BoundSqlRunner.options”options(opts: DbQueryOptions): BoundSqlRunner<Row>;
Merge per-query execution options (maxRows, maxBytes, timeoutMs).
| Name | Type | Description |
|---|---|---|
opts | DbQueryOptions | — |
BoundSqlRunner<Row>BoundSqlRunner.toSql
Section titled “BoundSqlRunner.toSql”toSql(dialect?: DbDialect): RenderedSql;
Render this template for dialect (or the bound handle’s dialect).
| Name | Type | Description |
|---|---|---|
dialect optional | DbDialect | — |
BoundSqlRunner.execute
Section titled “BoundSqlRunner.execute”execute(): Promise<DbExecuteResult>;
Execute the statement without returning rows and return { rowsAffected }.
BoundSqlRunner.all
Section titled “BoundSqlRunner.all”all(): Promise<Row[]>;
Execute and return all rows (bounded by DbQueryOptions).
Promise<Row[]>BoundSqlRunner.first
Section titled “BoundSqlRunner.first”first(): Promise<Row | null>;
Execute and return the first row, or null.
Promise<Row | null>BoundSqlRunner.one
Section titled “BoundSqlRunner.one”one(): Promise<Row>;
Execute and expect a single matching row.
Promise<Row>DbError— ("CARDINALITY"or"DATABASE"NoRows/TooManyRows) unless 1 row matched.
SqlTag
Section titled “SqlTag”export interface SqlTag {
(strings: TemplateStringsArray, ...values: readonly unknown[]): SqlFragment;
ident(name: string): DbColumnRef;
col(table: string, column: string): DbColumnRef;
raw(sql: string, params?: readonly DbParamValue[]): SqlFragment;
join(
parts: readonly (SqlFragment | DbColumnRef | DbTableRef | DbParamValue)[],
separator?: string,
): SqlFragment;
uuid(value: string | Uint8Array): DbTypedParam<string>;
uuid(value: string | Uint8Array | null): DbTypedParam<string | null>;
date(value: string | Date): DbTypedParam<string>;
date(value: string | Date | null): DbTypedParam<string | null>;
timestamp(value: string | Date | bigint): DbTypedParam<string>;
timestamp(value: string | Date | bigint | null): DbTypedParam<string | null>;
timestampTz(value: string | Date | bigint): DbTypedParam<string>;
timestampTz(value: string | Date | bigint | null): DbTypedParam<string | null>;
decimal(value: string | number | bigint): DbTypedParam<string>;
decimal(value: string | number | bigint | null): DbTypedParam<string | null>;
json<T = unknown>(value: T): DbTypedParam<T>;
}
Safe SQL tagged-template helper and rich-type parameter constructors.
(strings: TemplateStringsArray, ...values: readonly unknown[]): SqlFragment;
Build a parameterized SqlFragment from a tagged template literal.
| Name | Type | Description |
|---|---|---|
strings | TemplateStringsArray | — |
...values | readonly unknown[] | — |
SqlTag.ident
Section titled “SqlTag.ident”ident(name: string): DbColumnRef;
Construct a quoted identifier reference ("name").
| Name | Type | Description |
|---|---|---|
name | string | — |
SqlTag.col
Section titled “SqlTag.col”col(table: string, column: string): DbColumnRef;
Construct a table-qualified column reference ("table"."column").
| Name | Type | Description |
|---|---|---|
table | string | — |
column | string | — |
SqlTag.raw
Section titled “SqlTag.raw”raw(sql: string, params?: readonly DbParamValue[]): SqlFragment;
Construct a validated raw SQL expression fragment (rejects semicolons and
unbalanced parentheses; ? placeholders must match params.length).
| Name | Type | Description |
|---|---|---|
sql | string | — |
params optional | readonly DbParamValue[] | — |
SqlTag.join
Section titled “SqlTag.join”join(
parts: readonly (SqlFragment | DbColumnRef | DbTableRef | DbParamValue)[],
separator?: string,
): SqlFragment;
Join fragments, identifiers, or parameter values with separator (defaults to ", ").
| Name | Type | Description |
|---|---|---|
parts | readonly (SqlFragment | DbColumnRef | DbTableRef | DbParamValue)[] | — |
separator optional | string | — |
SqlTag.uuid
Section titled “SqlTag.uuid”uuid(value: string | Uint8Array): DbTypedParam<string>;
uuid(value: string | Uint8Array | null): DbTypedParam<string | null>;
Bind a non-null UUID (canonical string or 16-byte Uint8Array).
Bind a nullable UUID (null emits typed SQL NULL).
| Name | Type | Description |
|---|---|---|
value | string | Uint8Array | string | Uint8Array | null | — |
DbTypedParam<string>DbTypedParam<string | null>
SqlTag.date
Section titled “SqlTag.date”date(value: string | Date): DbTypedParam<string>;
date(value: string | Date | null): DbTypedParam<string | null>;
Bind a non-null ISO-8601 DATE (YYYY-MM-DD string or Date).
Bind a nullable DATE (null emits typed SQL NULL).
DbTypedParam<string>DbTypedParam<string | null>
SqlTag.timestamp
Section titled “SqlTag.timestamp”timestamp(value: string | Date | bigint): DbTypedParam<string>;
timestamp(value: string | Date | bigint | null): DbTypedParam<string | null>;
Bind a non-null TIMESTAMP (ISO-8601 string, Date, or Unix microseconds bigint).
Bind a nullable TIMESTAMP (null emits typed SQL NULL).
DbTypedParam<string>DbTypedParam<string | null>
SqlTag.timestampTz
Section titled “SqlTag.timestampTz”timestampTz(value: string | Date | bigint): DbTypedParam<string>;
timestampTz(value: string | Date | bigint | null): DbTypedParam<string | null>;
Bind a non-null TIMESTAMPTZ (ISO-8601 string with offset, Date, or Unix microseconds bigint).
Bind a nullable TIMESTAMPTZ (null emits typed SQL NULL).
DbTypedParam<string>DbTypedParam<string | null>
SqlTag.decimal
Section titled “SqlTag.decimal”decimal(value: string | number | bigint): DbTypedParam<string>;
decimal(value: string | number | bigint | null): DbTypedParam<string | null>;
Bind an exact base-10 DECIMAL (string, finite number, or bigint).
Bind a nullable DECIMAL (null emits typed SQL NULL).
| Name | Type | Description |
|---|---|---|
value | string | number | bigint | string | number | bigint | null | — |
DbTypedParam<string>DbTypedParam<string | null>
SqlTag.json
Section titled “SqlTag.json”json<T = unknown>(value: T): DbTypedParam<T>;
Bind an RFC 8259 JSON payload (cannot be undefined).
| Name | Type | Description |
|---|---|---|
value | T | — |
DbTypedParam<T>DatabaseHandle
Section titled “DatabaseHandle”export interface DatabaseHandle<DB = DbSchema> {
readonly dialect: DbDialect;
from<T extends (keyof DB & string) | (string & {}) | DbTableRef>(
table: T,
): SelectBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>, ResolveTableRow<DB, T>>;
insertInto<T extends (keyof DB & string) | DbTableRef>(
table: T,
): InsertBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
update<T extends (keyof DB & string) | DbTableRef>(
table: T,
): UpdateBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
deleteFrom<T extends (keyof DB & string) | DbTableRef>(
table: T,
): DeleteBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
sql<Row = DbRow>(
strings: TemplateStringsArray,
...values: readonly unknown[]
): BoundSqlRunner<Row>;
run<Row = DbRow>(
query: AnySelectBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row[]>;
run<ReturningRow = never>(
query: AnyMutationBuilder<ReturningRow>,
options?: DbQueryOptions,
): Promise<[ReturningRow] extends [never] ? DbExecuteResult : ReturningRow[]>;
run<Row = DbRow>(
fragment: SqlFragment,
options?: DbQueryOptions,
): Promise<Row[]>;
execute(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbExecuteResult>;
execute(
query: SqlFragment | AnyMutationBuilder<unknown>,
options?: DbQueryOptions,
): Promise<DbExecuteResult>;
query(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbRow[]>;
query<Row = DbRow>(
query: SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row[]>;
queryOne(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbRow | null>;
queryOne<Row = DbRow>(
query: SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row | null>;
close(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
}
Shared query-building and execution surface implemented by both
Database<DB> and Transaction<DB>.
| Property | Type | Description | Since |
|---|---|---|---|
dialect readonly | DbDialect | Native SQL dialect of this handle ("sqlite" | "postgres" | "mysql" | "mariadb" | "mssql"). | v0.0.0-alpha.2 |
DatabaseHandle.from
Section titled “DatabaseHandle.from”from<T extends (keyof DB & string) | (string & {}) | DbTableRef>(
table: T,
): SelectBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>, ResolveTableRow<DB, T>>;
Start a fluent SELECT query against table (a schema table, CTE name, or DbTableRef).
| Name | Type | Description |
|---|---|---|
table | T | — |
SelectBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>, ResolveTableRow<DB, T>>DatabaseHandle.insertInto
Section titled “DatabaseHandle.insertInto”insertInto<T extends (keyof DB & string) | DbTableRef>(
table: T,
): InsertBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Start a fluent INSERT INTO query against table.
| Name | Type | Description |
|---|---|---|
table | T | — |
InsertBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>DatabaseHandle.update
Section titled “DatabaseHandle.update”update<T extends (keyof DB & string) | DbTableRef>(
table: T,
): UpdateBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Start a fluent UPDATE query against table.
| Name | Type | Description |
|---|---|---|
table | T | — |
UpdateBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>DatabaseHandle.deleteFrom
Section titled “DatabaseHandle.deleteFrom”deleteFrom<T extends (keyof DB & string) | DbTableRef>(
table: T,
): DeleteBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>;
Start a fluent DELETE FROM query against table.
| Name | Type | Description |
|---|---|---|
table | T | — |
DeleteBuilder<DB, TableNameOf<T>, ResolveTableRow<DB, T>>DatabaseHandle.sql
Section titled “DatabaseHandle.sql”sql<Row = DbRow>(
strings: TemplateStringsArray,
...values: readonly unknown[]
): BoundSqlRunner<Row>;
Build an executable parameterized SQL query from a tagged template.
| Name | Type | Description |
|---|---|---|
strings | TemplateStringsArray | — |
...values | readonly unknown[] | — |
BoundSqlRunner<Row>DatabaseHandle.run
Section titled “DatabaseHandle.run”run<Row = DbRow>(
query: AnySelectBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row[]>;
run<ReturningRow = never>(
query: AnyMutationBuilder<ReturningRow>,
options?: DbQueryOptions,
): Promise<[ReturningRow] extends [never] ? DbExecuteResult : ReturningRow[]>;
run<Row = DbRow>(
fragment: SqlFragment,
options?: DbQueryOptions,
): Promise<Row[]>;
Execute a standalone unbound SelectBuilder on this handle and return its rows.
run(query, options?)| Name | Type | Description |
|---|---|---|
query | AnySelectBuilder<Row> | — |
options optional | DbQueryOptions | — |
Promise<Row[]>run(query, options?)Execute a standalone unbound mutation builder on this handle, returning DbExecuteResult unless .returning*() was configured.
| Name | Type | Description |
|---|---|---|
query | AnyMutationBuilder<ReturningRow> | — |
options optional | DbQueryOptions | — |
Promise<[ReturningRow] extends [never] ? DbExecuteResult : ReturningRow[]>run(fragment, options?)Execute a standalone SqlFragment on this handle and return its rows.
| Name | Type | Description |
|---|---|---|
fragment | SqlFragment | — |
options optional | DbQueryOptions | — |
Promise<Row[]>DatabaseHandle.execute
Section titled “DatabaseHandle.execute”execute(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbExecuteResult>;
execute(
query: SqlFragment | AnyMutationBuilder<unknown>,
options?: DbQueryOptions,
): Promise<DbExecuteResult>;
Execute a raw SQL statement with positional (?) or named (@name) parameters.
execute(sql, params?, options?)| Name | Type | Description |
|---|---|---|
sql | string | — |
params optional | DbParams | — |
options optional | DbQueryOptions | — |
execute(query, options?)Execute a SqlFragment or mutation builder without returning rows.
| Name | Type | Description |
|---|---|---|
query | SqlFragment | AnyMutationBuilder<unknown> | — |
options optional | DbQueryOptions | — |
DatabaseHandle.query
Section titled “DatabaseHandle.query”query(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbRow[]>;
query<Row = DbRow>(
query: SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row[]>;
Query a bounded batch of rows as plain objects keyed by column name.
Bounded by RowLimit::default() (1,000 rows, 1 MiB) unless overridden
via options. Signed 64-bit integer columns (i64) return number
within [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER] and bigint
outside it.
query(sql, params?, options?)| Name | Type | Description |
|---|---|---|
sql | string | — |
params optional | DbParams | — |
options optional | DbQueryOptions | — |
query(query, options?)Execute a SqlFragment, SelectBuilder, or RETURNING mutation builder and return all matching rows.
| Name | Type | Description |
|---|---|---|
query | SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row> | — |
options optional | DbQueryOptions | — |
Promise<Row[]>DatabaseHandle.queryOne
Section titled “DatabaseHandle.queryOne”queryOne(sql: string, params?: DbParams, options?: DbQueryOptions): Promise<DbRow | null>;
queryOne<Row = DbRow>(
query: SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row>,
options?: DbQueryOptions,
): Promise<Row | null>;
Query at most one row, or null when no row matched.
Rejects with code === "CARDINALITY" if more than one row matched.
queryOne(sql, params?, options?)| Name | Type | Description |
|---|---|---|
sql | string | — |
params optional | DbParams | — |
options optional | DbQueryOptions | — |
queryOne(query, options?)Execute a SqlFragment, SelectBuilder, or RETURNING mutation builder and return at most one row (null if none, CARDINALITY if >1).
| Name | Type | Description |
|---|---|---|
query | SqlFragment | AnySelectBuilder<Row> | AnyMutationBuilder<Row> | — |
options optional | DbQueryOptions | — |
Promise<Row | null>DatabaseHandle.close
Section titled “DatabaseHandle.close”close(): Promise<void>;
Close a pool handle and wait for worker cleanup (idempotent).
On a Transaction, calling close() directly throws DbError (code === "SQL").
Promise<void>DatabaseHandle.[Symbol.asyncDispose]
Section titled “DatabaseHandle.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Async disposal hook (await using). Closes a Database pool; on a
Transaction handle, resolves cleanly as a no-op because the enclosing
transaction() / savepoint() owns commit and rollback.
Promise<void>Transaction
Section titled “Transaction”export interface Transaction<DB = DbSchema> extends DatabaseHandle<DB> {
savepoint<R>(name: string, fn: (sp: Transaction<DB>) => Promise<R> | R): Promise<R>;
transaction<R>(fn: (tx: Transaction<DB>) => Promise<R> | R): Promise<R>;
}
Active single-connection database transaction with nested savepoint support.
Transaction.savepoint
Section titled “Transaction.savepoint”savepoint<R>(name: string, fn: (sp: Transaction<DB>) => Promise<R> | R): Promise<R>;
Execute fn inside a named SQL savepoint (SAVEPOINT -> RELEASE on
resolve, ROLLBACK TO + RELEASE on reject).
Concurrent overlapping savepoint() calls on the same handle reject with
DbError (code === "SQL"); use nested sp.savepoint(...) on the child
handle or await sequential calls instead.
| Name | Type | Description |
|---|---|---|
name | string | — |
fn | (sp: Transaction<DB>) => Promise<R> | R | — |
Promise<R>Transaction.transaction
Section titled “Transaction.transaction”transaction<R>(fn: (tx: Transaction<DB>) => Promise<R> | R): Promise<R>;
Nested transaction() calls on an active transaction handle always
reject with DbError (code === "SQL"); use savepoint() instead.
| Name | Type | Description |
|---|---|---|
fn | (tx: Transaction<DB>) => Promise<R> | R | — |
Promise<R>Database
Section titled “Database”export interface Database<DB = DbSchema> extends DatabaseHandle<DB> {
transaction<R>(fn: (tx: Transaction<DB>) => Promise<R> | R): Promise<R>;
}
Handle to an open database pool.
Database.transaction
Section titled “Database.transaction”transaction<R>(fn: (tx: Transaction<DB>) => Promise<R> | R): Promise<R>;
Execute fn inside a database transaction (COMMIT on resolve, ROLLBACK on reject).
| Name | Type | Description |
|---|---|---|
fn | (tx: Transaction<DB>) => Promise<R> | R | — |
Promise<R>Type Aliases
Section titled “Type Aliases”DbDialect
Section titled “DbDialect”export type DbDialect = "sqlite" | "postgres" | "mysql" | "mariadb" | "mssql";
SQL dialect identifier exposed on Database.dialect and Transaction.dialect.
export type DbRow = Record<string, unknown>;
Plain database result row record.
DbSchema
Section titled “DbSchema”export type DbSchema = Record<string, Record<string, unknown>>;
Optional schema map ({ tableName: { colName: colType } }) for generic
autocomplete and row inference on open<DB>() / openSqlite<DB>().
DbErrorCode
Section titled “DbErrorCode”export type DbErrorCode =
| "CONFIG"
| "DRIVER_UNAVAILABLE"
| "SQL"
| "PARAMETER"
| "CARDINALITY"
| "DATABASE"
| "CLOSED"
| "INVALID_PARAM";
Stable screaming-snake-case error codes reported on DbError.code.
DbConstraintKind
Section titled “DbConstraintKind”export type DbConstraintKind = "Unique" | "ForeignKey" | "NotNull" | "Check";
Static constraint classification reported on DbError.constraintKind.
DbConfig
Section titled “DbConfig”export type DbConfig = SqliteDbConfig | NetworkDbConfig;
Strict JSON configuration accepted by open(config).
DbParamValue
Section titled “DbParamValue”export type DbParamValue =
| null
| boolean
| number
| bigint
| string
| Uint8Array
| DbTypedParam;
Single scalar, binary, or typed SQL parameter value.
DbParams
Section titled “DbParams”export type DbParams =
| undefined
| null
| readonly DbParamValue[]
| Record<string, DbParamValue>;
Positional (?) or named (@name) parameters for a SQL statement.
CompareOp
Section titled “CompareOp”export type CompareOp =
| "="
| "=="
| "eq"
| "!="
| "<>"
| "ne"
| "<"
| "lt"
| "<="
| "le"
| "lte"
| ">"
| "gt"
| ">="
| "ge"
| "gte"
| "like"
| "notLike"
| "ilike"
| "iLike"
| "notIlike"
| "notILike";
Supported binary comparison operators for fluent where() / orWhere() calls.
TableNameOf
Section titled “TableNameOf”type TableNameOf<T> = T extends DbTableRef<infer N, string>
? N
: T extends string
? T
: never;
DbRowFor
Section titled “DbRowFor”type DbRowFor<DB, K> = K extends keyof DB
? DB[K] extends object
? DB[K]
: DbRow
: DbRow;
ResolveTableRow
Section titled “ResolveTableRow”type ResolveTableRow<DB, T> = DbRowFor<DB, TableNameOf<T>>;
IsInitialUnselected
Section titled “IsInitialUnselected”type IsInitialUnselected<TableRow, Current> =
string extends keyof TableRow
? string extends keyof Current
? true
: false
: [TableRow] extends [Current]
? [Current] extends [TableRow]
? true
: false
: false;
MergeSelected
Section titled “MergeSelected”type MergeSelected<TableRow, Current, Next> =
IsInitialUnselected<TableRow, Current> extends true ? Next : Current & Next;
JoinSelectedRow
Section titled “JoinSelectedRow”type JoinSelectedRow<TableRow, SelectedRow> =
IsInitialUnselected<TableRow, SelectedRow> extends true ? DbRow : SelectedRow;
Constants
Section titled “Constants”export const sql: SqlTag;
Safe SQL tagged template and parameter/identifier helpers.
export const func: {
<V = unknown>(name: string, ...args: readonly unknown[]): DbExpr<V>;
distinct<V = unknown>(name: string, ...args: readonly unknown[]): DbExpr<V>;
};
Construct a validated SQL function call expression (func("COUNT", "*")).
