import { type PoolConfig } from "@neondatabase/serverless"; import type { NeonHttpDatabase } from "drizzle-orm/neon-http"; import type { NeonDatabase as NeonWsDatabase } from "drizzle-orm/neon-serverless"; import type { PostgresJsDatabase } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import { type DbTimeoutOptions } from "./connection-config.js"; export type DbAdapter = "edge" | "node" | "serverless"; export interface DisposableDbClient { db: TDb; dispose: () => Promise; } export interface DbClientOptions = Record> { schema?: TSchema; adapter?: DbAdapter; replicas?: string[]; nodeMaxConnections?: number; serverlessPool?: Omit; /** * Query/connection timeouts (ms) applied per adapter. Defaults: * `statementMs: 10_000`, `queryMs: 15_000`, `connectMs: 10_000` — queries * now fail fast instead of pinning a Worker isolate for its full lifetime. * Pass `false` per field to disable. The `edge` (neon-http) adapter does * not support client-side timeouts and ignores this option entirely — * http queries rely on the server-side default `statement_timeout` and * the Workers runtime's own limits. See {@link DbTimeoutOptions}. */ timeouts?: DbTimeoutOptions; } /** * Union of the drizzle driver flavors a Voyant deployment can wire up: * `PostgresJsDatabase` (node adapter / direct TCP), `NeonHttpDatabase` * (edge adapter / Neon HTTP), and `NeonWsDatabase` (edge adapter / Neon * serverless WebSocket — the only Workers-compatible flavor that * supports real Postgres transactions). Use this as the parameter type * for `resolveDb`-style callbacks in module factories so consumers * don't need `as unknown as ...` casts when wiring different drivers. */ export type AnyDrizzleDb = Record> = PostgresJsDatabase | NeonHttpDatabase | NeonWsDatabase; export declare function createDbClient = Record>(connectionString: string, options?: DbClientOptions): (PostgresJsDatabase & { $client: postgres.Sql<{}>; }) | (PostgresJsDatabase> & { $client: postgres.Sql<{}>; }) | NeonWsDatabase | (NeonHttpDatabase & { $client: import("@neondatabase/serverless").NeonQueryFunction; }) | (NeonHttpDatabase> & { $client: import("@neondatabase/serverless").NeonQueryFunction; }); /** * Create a per-request Neon WebSocket pool + drizzle client. * * Timeout defaults (overridable via `timeouts`, or per-field via `pool`): * `statement_timeout: 10_000`, `query_timeout: 15_000`, * `connectionTimeoutMillis: 10_000`. Both `statement_timeout` (server-side) * and `query_timeout` (client-side) are set because transaction-mode poolers * (PgBouncer) may ignore `statement_timeout` as a startup parameter — see * {@link resolveServerlessPoolConfig}. * * Warns (once per connection string) when pointed at a Neon direct endpoint * instead of the `-pooler` host. */ export declare function createServerlessDbClient = Record>(connectionString: string, options?: { schema?: TSchema; pool?: Omit; timeouts?: DbTimeoutOptions; }): DisposableDbClient>; /** * Run `fn` with a scoped transaction-capable client (Neon WebSocket * Pool), disposing it on settle. For code paths that need * `db.transaction(...)` but run outside the request middleware that * normally provides the transactional client — event handlers, workflow * steps, scheduled jobs, scripts. * * const result = await withServerlessDb(env.DATABASE_URL, (db) => * db.transaction(async (tx) => { ... }), * ) */ export declare function withServerlessDb = Record>(connectionString: string, fn: (db: NeonWsDatabase) => Promise, options?: { schema?: TSchema; pool?: Omit; timeouts?: DbTimeoutOptions; }): Promise; /** * Get the main database instance for the configured `DATABASE_URL`. * (Single-database deployments; region is chosen per deployment.) */ export declare function getDb(adapter?: DbAdapter): NeonWsDatabase> | (PostgresJsDatabase> & { $client: postgres.Sql<{}>; }) | (NeonHttpDatabase> & { $client: import("@neondatabase/serverless").NeonQueryFunction; }); export declare const db: (PostgresJsDatabase> & { $client: postgres.Sql<{}>; }) | (NeonHttpDatabase> & { $client: import("@neondatabase/serverless").NeonQueryFunction; }) | (PostgresJsDatabase> & { $client: postgres.Sql<{}>; }) | NeonWsDatabase> | (NeonHttpDatabase> & { $client: import("@neondatabase/serverless").NeonQueryFunction; }); export * from "./connection-config.js"; export * from "./helpers.js"; export * from "./lib/index.js"; export * from "./lifecycle.js"; export * from "./queries/index.js"; export { withOptionalTransaction } from "./transaction.js"; export * from "./transaction-capability.js"; export * from "./types.js"; export * from "./utils.js"; //# sourceMappingURL=index.d.ts.map