inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
52 lines (51 loc) • 2.37 kB
TypeScript
import * as pg from 'pg';
import { DBClient } from '../db/DBClient';
import { DBTransaction } from '../db/DBTransaction';
import { ConnectionPool } from '../db/ConnectionPool';
import { ConfigurationObject, PoolConfig } from '../db/ConfigurationObject';
import { Transaction } from '../transaction/TransactionManager';
export declare class PostgresTransaction extends DBTransaction {
postgresClient: PostgresClient;
connection: pg.Client;
/**
*
* @param {PostgresClient} postgresClient
* @param transaction
*/
constructor(postgresClient: PostgresClient, transaction: Transaction);
private getConnectionPromise(connectionPool);
runQueryOnPool(connection: pg.Client, sql: string, bindsArr: Array<any>): Promise<any>;
protected runQueryPrivate(sql: string, bindsArr: any[]): Promise<any>;
runQueryAssocPrivate(sql: string, bindsObj: object): Promise<any>;
doTransactionEnd(): Promise<void>;
}
export interface PostgresPoolConfig extends PoolConfig {
}
export interface PostgresConfigurationObject extends ConfigurationObject<PostgresPoolConfig> {
}
/**
* A MySQL client you can use to execute queries against MySQL
*/
export declare class PostgresClient extends DBClient {
static startMethod: string;
static stopMethod: string;
configuration: PostgresConfigurationObject;
name: string;
masterPool: ConnectionPool<pg.Client>;
slavePool: ConnectionPool<pg.Client>;
connectionPoolCreator: (config: PostgresPoolConfig) => ConnectionPool<pg.Client>;
constructor();
initialise(): void;
/**
* Runs a function in a transaction. The function must receive one parameter that will be of class
* {PostgresTransaction} and that you need to use to run all queries in this transaction
*
* @param {boolean} readonly Whether the transaction needs to be readonly or not
* @param {Function} func A function that returns a promise that will execute all the queries wanted in this transaction
* @returns {Promise} A promise that will execute the whole transaction
*/
runInTransaction(readonly: boolean, func: (transaction: PostgresTransaction) => Promise<any>): Promise<any>;
shutdown(): void;
getFullPoolConfig(partial: PostgresPoolConfig): PostgresPoolConfig;
getConnectionPoolForReadonly(readonly: Boolean): ConnectionPool<pg.Client>;
}