interface DBAdapter

Database adapter interface for DB-agnostic operations.

Implement this interface to create drivers for specific databases. The DB class wraps adapters with Task/Stream semantics.

Adapters that support cursor-based streaming should implement the optional stream method. Adapters without stream buffer the full result set in memory.

For connection lifecycle management, use DBConnector which produces adapters. The adapter's close() method releases the connection (e.g., back to a pool) rather than terminating it — termination is the connector's responsibility.

Methods

query<T extends Record<string, any> = Record<string, any>>(
sql: string,
params?: unknown[],
): Promise<T[]>

Execute a SELECT query and return rows.

execute(
sql: string,
params?: unknown[],
): Promise<number>

Execute INSERT/UPDATE/DELETE and return affected row count.

close(): Promise<void>

Release the connection back to its source (e.g., pool). For pooled connections, this returns the client to the pool. For single connections, this may close the underlying connection.

optional
stream<T extends Record<string, any> = Record<string, any>>(
sql: string,
params?: unknown[],
): AsyncIterable<T>

Stream rows from a SELECT query using a cursor. If not implemented, the DB class falls back to buffering the full result.

Usage

import { type DBAdapter } from ".";