UNPKG

@hirosystems/api-toolkit

Version:
63 lines (62 loc) 2.42 kB
import * as postgres from 'postgres'; /** Postgres client instance */ export type PgSqlClient = postgres.Sql<any> | postgres.TransactionSql<any>; /** Postgres pending query or query fragment */ export type PgSqlQuery = postgres.PendingQuery<postgres.Row[]>; export type PgSslMode = 'require' | 'allow' | 'prefer' | 'verify-full' | boolean | object; /** Postgres connection URI string */ export type PgConnectionUri = string; /** Postgres connection values */ export type PgConnectionVars = { database?: string; user?: string; password?: string; host?: string; port?: number; schema?: string; ssl?: PgSslMode; application_name?: string; }; /** Postgres connection arguments */ export type PgConnectionArgs = PgConnectionUri | PgConnectionVars; /** Postgres connection options */ export type PgConnectionOptions = { /** Time to wait before automatically closing an idle connection (s) */ idleTimeout?: number; /** Maximum allowed duration of any statement (ms) */ statementTimeout?: number; /** Maximum time a connection can exist (s) */ maxLifetime?: number; /** Max number of connections */ poolMax?: number; }; /** * Takes in connection arguments provided via an object or a connection string and returns them with * a standardized application name format. If no connection args are provided, they are built from * standard postgres ENV vars. * @param args - Connection arguments * @param usage - Usage string * @returns PgConnectionVars */ export declare function standardizedConnectionArgs(args?: PgConnectionArgs, usage?: string): PgConnectionArgs; /** * Connects to Postgres. This function will also test the connection first to make sure all * connection parameters were specified correctly. * @param args - Connection options * @returns configured `Pool` object */ export declare function connectPostgres({ usageName, connectionArgs, connectionConfig, }: { usageName: string; connectionArgs?: PgConnectionArgs; connectionConfig?: PgConnectionOptions; }): Promise<PgSqlClient>; /** * Creates a Postgres client based on the provided connection arguments. * @param args - Connection options * @returns PgSqlClient */ export declare function getPostgres({ usageName, connectionArgs, connectionConfig, }: { usageName: string; connectionArgs?: PgConnectionArgs; connectionConfig?: PgConnectionOptions; }): PgSqlClient;