Module: database/sqlite

Database initialisation and singleton access.

Supports two database backends selected by the DATABASE_URL environment variable:

DATABASE_URL value Backend Adapter
Not set / does not start with postgres:// SQLite (default) adapters/sqlite-adapter.js
Starts with postgres:// or postgresql:// PostgreSQL adapters/postgres-adapter.js

Both adapters expose the same interface (prepare, exec, transaction, pragma, close, dialect) so all repository modules work unchanged.

Schema management

All schema changes go through the versioned migration system in database/migrationRunner.js. Migration files live in database/migrations/ as numbered .sql files (001_, 002_, …). The migration runner is dialect-aware and translates SQLite-specific SQL when running against PostgreSQL.

Exports

  • getDatabase — Returns the singleton database adapter instance.
  • closeDatabase — Gracefully close the connection (shutdown hook).
  • getDatabaseDialect — Returns "sqlite" or "postgres".
Source:

Members

(inner) _db :Object|null

Database adapter instance

Type:
  • Object | null
Source:

Methods

(static) closeDatabase()

Gracefully close the database connection. For SQLite: checkpoints the WAL file before closing. For PostgreSQL: drains the connection pool (async). Called from shutdown hooks in index.js.

Source:

(static) getDatabase() → {Object}

Return the singleton database adapter instance.

On first call, detects the backend from DATABASE_URL, creates the appropriate adapter, and runs all pending migrations.

The returned object conforms to the db-adapter interface:

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

Database adapter instance

Type
Object

(static) getDatabaseDialect() → {"sqlite"|"postgres"}

Return the current database dialect.

Source:
Returns:

The active dialect.

Type
"sqlite" | "postgres"

(inner) detectDialect() → {"sqlite"|"postgres"}

Detect which database backend to use based on DATABASE_URL.

Source:
Returns:
Type
"sqlite" | "postgres"