Module: database/adapters/sqlite-adapter

SQLite adapter implementing the db-adapter interface.

Wraps better-sqlite3 to provide the standard adapter API used by all repository modules. This is the default adapter when no DATABASE_URL environment variable is set (or when it does not start with postgres://).

Adapter interface

Every adapter must expose:

  • prepare(sql) → statement-like object with .run(), .get(), .all()
  • exec(sql) — execute raw SQL (DDL, multi-statement)
  • transaction(fn) — wrap fn in a transaction, return a callable
  • pragma(str) — execute a PRAGMA (no-op on non-SQLite)
  • close() — close the connection
  • dialect"sqlite" or "postgres"
Source:

Members

(inner) dialect :"sqlite"

Type:
  • "sqlite"
Source:

Methods

(static) createSqliteAdapter(optsopt) → {Object}

Create a SQLite adapter instance.

Parameters:
Name Type Attributes Description
opts Object <optional>
Properties
Name Type Attributes Description
dbPath string <optional>

— Override the database file path.

Source:
Returns:

Adapter conforming to the db-adapter interface.

Type
Object

(inner) close()

Gracefully close the database connection. Checkpoints the WAL file before closing.

Source:

(inner) exec(sql)

Execute raw SQL (DDL, multi-statement scripts).

Parameters:
Name Type Description
sql string
Source:

(inner) pragma(str) → {*}

Execute a PRAGMA statement.

Parameters:
Name Type Description
str string

— e.g. "journal_mode = WAL"

Source:
Returns:
Type
*

(inner) prepare(sql) → {Object}

Prepare a SQL statement. Returns the native better-sqlite3 Statement which already has .run(), .get(), .all() methods.

Parameters:
Name Type Description
sql string
Source:
Returns:

better-sqlite3 Statement

Type
Object

(inner) transaction(fn) → {function}

Wrap a function in a database transaction. Returns a callable that executes fn inside BEGIN/COMMIT.

Parameters:
Name Type Description
fn function
Source:
Returns:
Type
function