UNPKG

inceptum

Version:

hipages take on the foundational library for enterprise-grade apps written in NodeJS

90 lines (89 loc) 3.82 kB
import * as mysql from 'mysql'; import { DBTransaction } from '../db/DBTransaction'; import { ConnectionPool } from '../db/ConnectionPool'; import { ConfigurationObject, PoolConfig } from '../db/ConfigurationObject'; import { Transaction } from '../transaction/TransactionManager'; import { DBClient } from '../db/DBClient'; export declare class MysqlTransaction extends DBTransaction { mysqlClient: MysqlClient; connection: mysql.IConnection; /** * * @param {MysqlClient} myslqClient * @param transaction */ constructor(mysqlClient: MysqlClient, transaction: Transaction); runQueryOnPool(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 MySQLPoolConfig extends PoolConfig { /** * The source IP address to use for TCP connection */ localAddress?: string; /** * The path to a unix domain socket to connect to. When used host and port are ignored */ socketPath?: string; /** * The timezone used to store local dates. (Default: 'local') */ timezone?: string; /** * object with ssl parameters or a string containing name of ssl profile */ ssl?: any; /** * The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout, * because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds) */ acquireTimeout?: number; /** * Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue * the connection request and call it when one becomes available. If false, the pool will immediately call back with an error. * (Default: true) */ waitForConnections?: boolean; /** * The maximum number of connections to create at once. (Default: 10) */ connectionLimit?: number; /** * The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there * is no limit to the number of queued connection requests. (Default: 0) */ queueLimit?: number; } export interface MySQLConfigurationObject extends ConfigurationObject<MySQLPoolConfig> { enable57Mode?: boolean; } /** * A MySQL client you can use to execute queries against MySQL */ export declare class MysqlClient extends DBClient { static startMethod: string; static stopMethod: string; configuration: MySQLConfigurationObject; name: string; masterPool: ConnectionPool<mysql.IConnection>; slavePool: ConnectionPool<mysql.IConnection>; enable57Mode: boolean; connectionPoolCreator: (config: MySQLPoolConfig) => ConnectionPool<mysql.IConnection>; constructor(); initialise(): void; /** * Runs a function in a transaction. The function must receive one parameter that will be of class * {MysqlTransaction} 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: DBTransaction) => Promise<any>): Promise<any>; shutdown(): void; getFullPoolConfig(partial: MySQLPoolConfig): MySQLPoolConfig; getConnectionPoolForReadonly(readonly: Boolean): ConnectionPool<mysql.IConnection>; ping(readonly: boolean): Promise<void>; }