import { Driver, DriverQueryResult, EntityManager, IdAssigner, JoinRowTodo, ParsedFindQuery, PreloadPlugin, RuntimeConfig, Todo } from "joist-core"; import pg from "pg"; //#region src/drivers/PostgresDriver.d.ts interface PostgresDriverOpts { idAssigner?: IdAssigner; /** Sets a default `PreloadPlugin` for any `EntityManager` that uses this driver. */ preloadPlugin?: PreloadPlugin; /** Called after each query is executed, useful for testing/debugging. */ onQuery?: (sql: string) => void; /** * Experimental: keeps entity find results as raw wire bytes and decodes each row/column cell * lazily on field access, instead of eagerly materializing POJO rows. * * Applies to unpaginated `em.find`, `em.load`, and o2m/o2o/recursive relation loads against * the pure-JS pg client. Other loaders deliberately stay classic: paginated finds (small * pages, measured neutral), m2m join-table rows (narrow + fully read, where materialized rows * measured faster, and `JoinRows` owns/mutates them), lazy columns, and id/count loaders. * * Lazy queries also request *binary* result format (prototype), decoding int/bool/float/text * cells — and, via the fast paths `setupLatestPgTypes` registers, date/timestamptz cells — * wire-bytes -> value with no intermediate strings; numeric/exotic cells render to pg's * canonical text and reuse the active text parsers for parity. `JOIST_LAZY_BINARY=0` * reverts lazy queries to text-format results. It * uses classic rows when the choice is knowable up-front (patching pg-protocol failed, or the * client is unsupported, i.e. pg-native — both warn once). If a connection turns out * mid-query to use an unpatched pg-protocol copy (a duplicate `pg` install), the query fails * with a descriptive error — a misconfiguration CI builds/smoketests will catch immediately. * Note deferred decoding also defers custom-parser errors from `await em.find` to first field * access. See JS-ROW-STORE-DESIGN.md. */ lazyRows?: boolean; } /** * Implements the `Driver` interface for Postgres. * * This is the canonical driver implementation and leverages several aspects of * Postgres for the best performance, i.e.: * * - Deferred foreign key constraints are used to allow bulk inserting/updating * all entities without any topographic sorting/ordering issues. * * - Sequences are used to bulk-assign + then bulk-insert all entities, to again * avoid issues with ordering issues (cannot bulk insert A w/o knowing the id of B). * * - We use a pg-specific bulk update syntax. * * Query pipelining is enabled for clients created after driver construction unless the pool was * configured with `pipeline: false`. */ declare class PostgresDriver implements Driver { #private; readonly pool: pg.Pool; readonly lazyRows: boolean; /** Defined only when `lazyRows` is enabled; its presence is the capability signal the EM checks. */ readonly executeFindRowData: Driver["executeFindRowData"]; constructor(pool: pg.Pool, opts?: PostgresDriverOpts); executeFind(em: EntityManager, parsed: ParsedFindQuery, settings: { limit?: number; offset?: number; }): Promise; /** Returns PostgreSQL's native command count and raw rows, including null counts for DDL. */ executeQuery(em: EntityManager, sql: string, bindings: readonly any[]): Promise; transaction(em: EntityManager, fn: (txn: pg.PoolClient) => Promise): Promise; assignNewIds(_: EntityManager, todos: Record): Promise; flush(em: EntityManager, entityTodos: Record, joinRows: Record): Promise; get defaultPlugins(): { preloadPlugin: any; }; private getMaybeInTxnClient; } /** * Configures the `pg` driver with the best type parsers. * * In particular, pg's default `TIMESTAMPTZ` parser is very inefficient, and even just * pulling in the latest `pg-types` and installing the fixed parser makes a noticable * difference. */ declare function setupLatestPgTypes(temporal: RuntimeConfig["temporal"]): void; //#endregion export { PostgresDriver, PostgresDriverOpts, setupLatestPgTypes }; //# sourceMappingURL=PostgresDriver.d.mts.map