Socket
Book a DemoSign in
Socket

@valencets/db

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@valencets/db

PostgreSQL connection, config validation, and migration runner for Valence. The package validates `DbConfig`, creates `postgres` pools with explicit SSL modes, maps database errors into `DbError`, and applies SQL migrations under an advisory lock.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

@valencets/db

PostgreSQL connection, config validation, and migration runner for Valence. The package validates DbConfig, creates postgres pools with explicit SSL modes, maps database errors into DbError, and applies SQL migrations under an advisory lock.

Full documentation on the wiki.

Config

DbConfig includes:

  • host, port, database, username, password
  • pool sizing and timeout settings
  • sslmode?: 'disable' | 'require' | 'verify-ca' | 'verify-full'
  • sslrootcert?: string

Verified TLS modes require sslrootcert. The package boundary expects certificate contents, not a file path.

Migrations

loadMigrations() reads NNN-name.sql files, validates version uniqueness, and sorts them deterministically.

runMigrations():

  • reserves one database session for the full migration run
  • acquires a session-scoped advisory lock
  • applies each unapplied migration inside its own transaction
  • records applied versions in _migrations

getMigrationStatus() returns the applied migration list, and treats a fresh database with no _migrations table as zero applied migrations.

Testing

The package also publishes query-path test helpers at @valencets/db/test:

  • makeMockPool() for fixed successful query results
  • makeRejectingPool() for raw rejected SQL-boundary failures
  • makeSequentialPool() for deterministic per-call result sequences

These shared helpers are intentionally limited to stateless query-path tests. Tests that need session-affine behavior such as reserve() and release() should use local inline mocks instead of the shared helper surface.

Quick Start

pnpm install
pnpm build
pnpm --filter=@valencets/db test

FAQs

Package last updated on 24 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts