/// import type { ConnectionOptions } from 'tls'; import { QueryableType } from '@databases/shared'; import DataTypeID from '@databases/pg-data-type-id'; import { isSQLError, SQLError, SQLErrorCode } from '@databases/pg-errors'; import sql, { SQLQuery, isSqlQuery } from '@databases/sql'; import IsolationLevel from './types/IsolationLevel'; import Queryable, { Transaction, Connection, ConnectionPool, isTransaction, isConnection, isConnectionPool } from './types/Queryable'; import { TypeOverridesConfig } from './TypeOverrides'; import EventHandlers from './types/EventHandlers'; import pgFormat from './format'; export type { SQLQuery, SQLError, Queryable, Transaction, Connection, ConnectionPool, }; export { pgFormat, sql, isSqlQuery, isSQLError, SQLErrorCode, DataTypeID, QueryableType, IsolationLevel, isTransaction, isConnection, isConnectionPool, }; export interface ClientConfig { /** * How would you like bigints to be returned from the database? * * If you choose `number` you may get inexact values for numbers greater than Number.MAX_SAFE_INTEGER */ bigIntMode?: 'string' | 'number' | 'bigint'; /** * @deprecated use bigIntMode */ bigIntAsString?: boolean; types?: TypeOverridesConfig['overrides']; /** * Defaults to process.env.DATABASE_URL */ connectionString?: string | false; /** * Application name to provide to postgres when connecting. * This can be useful when diagnosing performance issues on * the Postgres database server. * * Can also be specified via the connection string, or using * the "PGAPPNAME" environment variable. */ applicationName?: string; /** * Fallback value to use as "applicationName" if no "applicationName" * was provided via the connection string or environment variables. */ fallbackApplicationName?: string; user?: string; password?: string; host?: string | string[]; database?: string; port?: number | (number | null)[]; /** * Forces change of the default database schema(s) for every fresh * connection, i.e. the library will execute SET search_path TO schema_1, schema_2, ... * in the background whenever a fresh physical connection is allocated. */ schema?: string | string[]; /** * SSL Mode, defaults to "prefer" * * false is equivalent to "disable" * true is equivalent to "require" */ ssl?: false | true | 'disable' | 'prefer' | 'require' | 'no-verify' | ConnectionOptions; /** * number of milliseconds before a statement in query will time out, * * default is no timeout */ statementTimeoutMilliseconds?: number; /** * number of milliseconds before a query call will timeout, * * default is no timeout */ queryTimeoutMilliseconds?: number; /** * number of milliseconds before terminating any session with * an open idle transaction, * * default is no timeout */ idleInTransactionSessionTimeoutMilliseconds?: number; /** * Passed to `new Connection(...)`, * defaults to false */ keepAlive?: boolean; /** * Passed to `new Connection(...)`, * defaults to 0 */ keepAliveInitialDelayMilliseconds?: number; /** * Maximum times to use a single connection from a connection pool before * discarding it and requesting a fresh connection. * defaults to Infinity */ maxUses?: number; } export interface ConnectionPoolConfig extends ClientConfig, EventHandlers { /** * maximum number of clients the pool should contain * by default this is set to 10. */ poolSize?: number; /** * number of milliseconds a client must sit idle in the pool and not be checked out * before it is disconnected from the backend and discarded * * default is 30_000 (30 seconds) - set to 0 to disable auto-disconnection of idle clients */ idleTimeoutMilliseconds?: number; /** * Number of milliseconds to wait before timing out when connecting a new client * by default this is 10 seconds. Set this to 0 to disable the timeout altogether. * * N.B. if you have multiple hosts, or an SSL mode of "prefer" (which is the default), * this will be the timeout per attempt, meaning the total timeout is this value, * multiplied by the number of possible connetion details to attempt. */ connectionTimeoutMilliseconds?: number; /** * Number of milliseconds to wait for a connection from the connection pool. This * must always be greater than the connectionTimeoutMilliseconds otherwise waiting * for the pool will timeout before the connection times out. * * Defaults to the maximum of 60 seconds or connectionTimeoutMilliseconds * number of hosts * 2 */ queueTimeoutMilliseconds?: number; /** * Number of milliseconds to wait for a lock on a connection/transaction. This is * helpful for catching cases where you have accidentally attempted to query a connection * within a transaction that is on that connection, or attempted to query an outer transaction * within a nested transaction. * * Defaults to 60 seconds */ acquireLockTimeoutMilliseconds?: number; onError?: (err: Error) => void; } export default function createConnectionPool(connectionConfig?: string | ConnectionPoolConfig | undefined): ConnectionPool;