IF Commons GitHub

physical/adapters/sqlite

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-sql-port FR-005

The port of a SQLite database: a connection of node:sqlite or of bun:sqlite (typed by the shape both have, so that this library depends on neither), or a file opened by the runtime that is running. A write is BEGIN IMMEDIATE, so that a second writer waits (the busy timeout) and never fails halfway; a file is opened in write-ahead mode, so that readers do not stop the writer. Two connections to one file in one process share a gate, since a connection that waits for the lock of another in the same thread would never get it.

import { openSqliteFile } from "@intellectual-frontiers/anyfs-sql/sqlite";
const port = await openSqliteFile("fleet.db");

Source: commons/anyfs-sql/src/physical/adapters/sqlite.ts

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

SqliteStatementinterfaceno test imports it
interface SqliteStatement

A prepared statement of node:sqlite or bun:sqlite.

MemberTypeWhat it is
all(...params: unknown[]) => unknown[]
run(...params: unknown[]) => unknown
SqliteDatabaseinterfaceno test imports it
interface SqliteDatabase

A connection of node:sqlite (DatabaseSync) or bun:sqlite (Database).

MemberTypeWhat it is
exec(sql: string) => unknown
prepare(sql: string) => SqliteStatement
close() => unknown
SqliteOptionstypeno test imports it
type SqliteOptions = {
  /** The gate that serializes this connection with others to the same file in this process: made for the connection where not given. */
  readonly gate?: Gate;
  /** How long a writer waits for the lock of another process, in milliseconds (5000 where not given). */
  readonly busyMs?: number;
};

What a SQLite port may be given.

sqlitePortfunctionno test imports it
function sqlitePort(db: SqliteDatabase, options?: SqliteOptions): SqlPort

The port of a connection of SQLite.

openSqliteFilefunction
function openSqliteFile(file: string, options?: SqliteOptions): Promise<Result<SqlPort, string>>

Opens a SQLite file (or :memory:) with the module of the runtime that is running: bun:sqlite in Bun and node:sqlite in Node.

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

fingerprintOfFilefunctionno test imports it
function fingerprintOfFile(file: string): Promise<string>

What tells a copy of a database file from the original: the device and the file of the file system object (dev:ino), which cp does not keep and a rename does. A database opened with a fingerprint other than the one it holds is a copy and takes a new replica identity. memory for a database in memory; where the file system has no file number, the resolved name.

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