/** * Database connection management for `@atlex/orm`. * * Wraps a single Knex instance and provides Atlex-friendly validation and * lifecycle helpers (ping/close). Knex is an internal implementation detail. */ import type { Knex } from 'knex'; export interface DatabaseConfig { driver: 'pg' | 'mysql2' | 'better-sqlite3'; host?: string; port?: number; database: string; username?: string; password?: string; /** * PostgreSQL only: primary schema for unqualified table names (often `DB_SCHEMA` in env). * Knex `search_path` is set to `[schema, "public"]` when set and not `"public"`, else `["public"]`. * Non-`public` schemas are created with `CREATE SCHEMA IF NOT EXISTS` on each new pool connection * (Postgres ignores missing names in `search_path`, which would otherwise send tables to `public`). */ schema?: string; filename?: string; pool?: { min?: number; max?: number; acquireTimeoutMillis?: number; }; /** When true, Knex prints every query. Prefer enabling via DB_DEBUG=true in .env rather than hard-coding. */ debug?: boolean; } export declare class Connection { private static _default; private readonly knexInstance; private readonly driverName; private constructor(); /** * Resolve a new `Connection` from a `DatabaseConfig`. * * @param config - Database configuration. * @returns A new `Connection` instance. * @example * const conn = Connection.resolve({ driver: 'pg', host: 'localhost', database: 'app' }) */ static resolve(config: DatabaseConfig): Connection; /** * Get the currently set default connection. * * @returns The default `Connection`. * @example * const conn = Connection.default() */ static default(): Connection; /** * Set the default connection used by the ORM. * * @param conn - Connection to set as default. * @returns void * @example * Connection.setDefault(conn) */ static setDefault(conn: Connection): void; /** * @internal Clears the default connection reference (Vitest / isolated integration tests only). */ static clearDefaultForTests(): void; /** * Escape hatch to access the underlying Knex instance. * This is intentionally typed as `unknown` to avoid leaking Knex types * into the public API surface. * * @returns The internal Knex instance. * @example * const knex = conn.getKnex() as any // not recommended; prefer QueryBuilder */ getKnex(): unknown; /** @internal */ _knex(): Knex; /** * Verify connectivity by executing a trivial query. * * @returns True if connectivity is working. * @example * await conn.ping() */ ping(): Promise; /** * Close/destroy the connection pool. * * @returns void * @example * await conn.close() */ close(): Promise; /** * Read-only driver identifier. * * @returns Driver string. * @example * console.log(conn.driver) */ get driver(): string; } //# sourceMappingURL=Connection.d.ts.map