import { DeleteBuilder } from "../builders/delete.js"; import { InsertBuilder } from "../builders/insert.js"; import { RelationalQueryBuilder } from "../builders/relational.js"; import { SelectBuilder, SelectBuilderIntermediate, type SelectedFields } from "../builders/select.js"; import { UpdateBuilder } from "../builders/update.js"; import { type Table } from "../schema/table.js"; import type { ColumnConfig } from "../types/index.js"; import type { SchemaConfig } from "../types/relations.js"; import type { QueryExecutor } from "./query.js"; import type { SQLChunk } from "./sql.js"; export declare abstract class BaseQueryExecutor implements QueryExecutor { abstract execute>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; abstract executeSingle>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; abstract raw>(query: string, params?: unknown[]): Promise; select(): SelectBuilderIntermediate; select(fields: TSelection): SelectBuilderIntermediate; select>(table: Table): SelectBuilder; insert>(table: Table): InsertBuilder; update>(table: Table): UpdateBuilder; delete>(table: Table): DeleteBuilder; } export interface DBConfig { /** Postgres connection URL, e.g. postgres://user:pass@host:5432/dbname */ url: string; /** Max connections in the pool (default: 10) */ max?: number; /** Connection idle timeout in ms (default: 10000) */ idleTimeout?: number; /** Max connection lifetime in ms */ maxLifetime?: number; /** Whether to use TLS (default: auto-detect from URL) */ tls?: boolean; /** * Auto-create the database if it doesn't exist (default: true). * Connects to the "postgres" maintenance DB to run CREATE DATABASE. */ autoCreateDB?: boolean; /** * The database schema object (tables). Enables the db.tableName.findMany() relational API. */ schema?: TSchema; /** Query execution timeout in ms */ queryTimeout?: number; /** Whether to log executed queries or custom log callback */ logQueries?: boolean | ((sql: string, params: unknown[], durationMs: number) => void); /** Whether to include execution timing in log output */ logQueryTiming?: boolean; } export type TransactionOptions = { isolation?: "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE"; }; /** Validate PostgreSQL connection string format */ export declare function validateConnectionString(url: string): void; export declare class BungresDB extends BaseQueryExecutor { private readonly _sql; private readonly _config; private _ready; private _lastQuery; private _activeQueries; constructor(config: DBConfig | string); /** Wait for DB-init to complete before running any query */ private ready; /** Get last executed query details */ getLastQuery(): { sql: string; params: unknown[]; duration: number; } | null; /** Get pool status & metrics */ getPoolStatus(): { total: number; active: number; idle: number; waiting: number; }; /** Execute low-level query with error handling, logging, and timeouts */ private _executeQuery; /** Execute a built query and return all rows */ execute>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; /** Execute a built query and return the first row or null */ executeSingle>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; /** Execute raw SQL string */ raw>(query: string, params?: unknown[]): Promise; /** * Run a callback inside a transaction. * Automatically rolls back if the callback throws. */ transaction(fn: (tx: BungresTransaction) => Promise, options?: TransactionOptions): Promise; /** Close the connection pool */ close(): Promise; } export declare class BungresTransaction extends BaseQueryExecutor { private readonly _sql; private _savepointCounter; constructor(sql: InstanceType); private _executeQuery; execute>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; executeSingle>(builder: { toSQL(): SQLChunk; } | SQLChunk): Promise; raw>(query: string, params?: unknown[]): Promise; /** * Run a nested transaction using SAVEPOINT. * If the callback throws, it rolls back to the savepoint, leaving the outer transaction intact. */ transaction(fn: (tx: BungresTransaction) => Promise): Promise; } export type BungresDBClient = BungresDB & { [K in keyof TSchema]: RelationalQueryBuilder; }; /** * Idiomatic bungres entrypoint — mirrors the `drizzle(config)` pattern. * * @example * import { bungres } from "@bungres/orm"; * import * as schema from "./schema"; * * export const db = bungres({ url: Bun.env.DATABASE_URL!, schema }); */ export declare function bungres>(config: DBConfig | string): BungresDBClient; /** @internal kept for internal package use only */ export declare const createDB: typeof bungres; //# sourceMappingURL=db.d.ts.map