IF Commons GitHub

sql/drivers/mod

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0056-sql-drivers FR-001, 0056-sql-drivers FR-002, 0056-sql-drivers FR-003

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)");

Source: commons/data/sql/drivers/mod.ts

10 of 13 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

plainconst
const plain: (r: Readonly<Record<string, unknown>>) => Record<string, unknown>

A row as a plain object whose wide integers are numbers.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

SqliteClientinterface
interface SqliteClient

What node:sqlite and bun:sqlite give: statements run by exec, rows read by a prepared statement.

MemberTypeWhat it is
exec(sql: string) => unknown
prepare(sql: string) => { all(): readonly Readonly<Record<string, unknown>>[]; }

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

sqliteDriverconst
const sqliteDriver: (db: SqliteClient) => Driver

The driver of a SQLite database.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

PgClientinterface
interface PgClient

What pg's Client and Pool give: one query of text, whose result has rows (an array of results where the text had several statements).

MemberTypeWhat it is
query(sql: string) => PromiseLike<readonly { readonly rows: readonly Readonly<Record<string, unknown>>[]; }[] | { readonly rows: readonly Readonly<Record<string, unknown>>[]; }>

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

pgDriverconst
const pgDriver: (client: PgClient) => Driver

The driver of a PostgreSQL connection made by pg.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

PgliteClientinterfaceno test imports it
interface PgliteClient

What PGlite gives: exec for text of many statements, query for one.

MemberTypeWhat it is
exec(sql: string) => PromiseLike<unknown>
query(sql: string) => PromiseLike<{ readonly rows: readonly Readonly<Record<string, unknown>>[]; }>
pgliteDriverconst
const pgliteDriver: (db: PgliteClient) => Driver

The driver of a PGlite database.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

DuckdbClientinterface
interface DuckdbClient

What DuckDB's node-api connection gives.

MemberTypeWhat it is
run(sql: string) => PromiseLike<unknown>
runAndReadAll(sql: string) => PromiseLike<{ getRowObjectsJson(): readonly Readonly<Record<string, unknown>>[]; }>

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

duckdbDriverconst
const duckdbDriver: (conn: DuckdbClient) => Driver

The driver of a DuckDB connection.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

BunSqlClientinterfaceno test imports it
interface BunSqlClient

What Bun's SQL gives: unsafe runs text and gives rows.

MemberTypeWhat it is
unsafe(sql: string) => PromiseLike<readonly Readonly<Record<string, unknown>>[]>
bunSqlDriverconst
const bunSqlDriver: (sql: BunSqlClient) => Driver

The driver of a connection made by Bun's SQL.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

AnyClienttypeno test imports it
type AnyClient = SqliteClient | PgClient | PgliteClient | DuckdbClient | BunSqlClient;

A client that driverFor knows by its shape.

driverForfunction
function driverFor(client: AnyClient): Driver

The 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).

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.