plainconstconst plain: (r: Readonly<Record<string, unknown>>) => Record<string, unknown>A row as a plain object whose wide integers are numbers.
Driver adapters (commons data 0056-sql-drivers): the Driver of the library (exec and query, both of one text) made from the client a caller already has. Each adapter is typed by the shape of the client it takes, not by its package, so that this library depends on none of them: node:sqlite's DatabaseSync (and bun:sqlite's Database), a pg client or pool, PGlite, DuckDB's node-api connection and Bun's SQL. driverFor picks the adapter from the shape. A row is a plain object, and a wide integer a number.
import { DatabaseSync } from "node:sqlite";
const driver = sqliteDriver(new DatabaseSync(":memory:"));
await driver.exec("CREATE TABLE t (id INTEGER)");plainconstconst plain: (r: Readonly<Record<string, unknown>>) => Record<string, unknown>A row as a plain object whose wide integers are numbers.
SqliteClientinterfaceinterface SqliteClientWhat node:sqlite and bun:sqlite give: statements run by exec, rows read by a prepared statement.
| Member | Type | What it is |
|---|---|---|
exec | (sql: string) => unknown | |
prepare | (sql: string) => { all(): readonly Readonly<Record<string, unknown>>[]; } |
sqliteDriverconstconst sqliteDriver: (db: SqliteClient) => DriverThe driver of a SQLite database.
PgClientinterfaceinterface PgClientWhat pg's Client and Pool give: one query of text, whose result has rows (an array of results where the text had several statements).
| Member | Type | What it is |
|---|---|---|
query | (sql: string) => PromiseLike<readonly { readonly rows: readonly Readonly<Record<string, unknown>>[]; }[] | { readonly rows: readonly Readonly<Record<string, unknown>>[]; }> |
pgDriverconstconst pgDriver: (client: PgClient) => DriverThe driver of a PostgreSQL connection made by pg.
PgliteClientinterfaceno test imports itinterface PgliteClientWhat PGlite gives: exec for text of many statements, query for one.
| Member | Type | What it is |
|---|---|---|
exec | (sql: string) => PromiseLike<unknown> | |
query | (sql: string) => PromiseLike<{ readonly rows: readonly Readonly<Record<string, unknown>>[]; }> |
pgliteDriverconstconst pgliteDriver: (db: PgliteClient) => DriverThe driver of a PGlite database.
DuckdbClientinterfaceinterface DuckdbClientWhat DuckDB's node-api connection gives.
| Member | Type | What it is |
|---|---|---|
run | (sql: string) => PromiseLike<unknown> | |
runAndReadAll | (sql: string) => PromiseLike<{ getRowObjectsJson(): readonly Readonly<Record<string, unknown>>[]; }> |
duckdbDriverconstconst duckdbDriver: (conn: DuckdbClient) => DriverThe driver of a DuckDB connection.
BunSqlClientinterfaceno test imports itinterface BunSqlClientWhat Bun's SQL gives: unsafe runs text and gives rows.
| Member | Type | What it is |
|---|---|---|
unsafe | (sql: string) => PromiseLike<readonly Readonly<Record<string, unknown>>[]> |
bunSqlDriverconstconst bunSqlDriver: (sql: BunSqlClient) => DriverThe driver of a connection made by Bun's SQL.
AnyClienttypeno test imports ittype AnyClient = SqliteClient | PgClient | PgliteClient | DuckdbClient | BunSqlClient;A client that driverFor knows by its shape.
driverForfunctionfunction driverFor(client: AnyClient): DriverThe driver for a client, by its shape: DuckDB's (runAndReadAll), Bun's (unsafe), SQLite's (prepare and exec), PGlite's (exec and query) or pg's (query).