1 | import { Factory } from 'generic-pool';
|
2 | import { DBTransaction } from './DBTransaction';
|
3 | import { ConnectionPool, ConnectionConfig, PoolConfig } from './ConnectionPool';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export interface DBClientConfig<C extends ConnectionConfig> {
|
10 | name: string;
|
11 | master: PoolConfig<C>;
|
12 | slave?: PoolConfig<C>;
|
13 | }
|
14 | export declare abstract class DBClient<C, T extends DBTransaction<C>, CC extends ConnectionConfig, PC extends DBClientConfig<CC>> {
|
15 | static startMethod: string;
|
16 | static stopMethod: string;
|
17 | clientConfiguration: PC;
|
18 | name: string;
|
19 | masterPool: ConnectionPool<C>;
|
20 | slavePool: ConnectionPool<C>;
|
21 | constructor(clientConfiguration: PC);
|
22 | abstract getNewDBTransaction(readonly: boolean, connectionPool: ConnectionPool<C>): T;
|
23 | abstract getDefaultConnectionConfig(): CC;
|
24 | /**
|
25 | * Runs a function in a transaction. The function must receive one parameter that will be of class
|
26 | * {MysqlTransaction} and that you need to use to run all queries in this transaction
|
27 | *
|
28 | * @param {boolean} readonly Whether the transaction needs to be readonly or not
|
29 | * @param {Function} func A function that returns a promise that will execute all the queries wanted in this transaction
|
30 | * @returns {Promise} A promise that will execute the whole transaction
|
31 | */
|
32 | runInTransaction(readonly: boolean, func: (transaction: DBTransaction<C>) => Promise<any>): Promise<any>;
|
33 | getPoolForReadonly(readonly: boolean): ConnectionPool<C>;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | read<P>(sql: string, ...binds: any[]): Promise<P[]>;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | executeSql(readonly: boolean, sql: string, ...binds: any[]): Promise<any>;
|
48 | abstract getConnectionFactory(name: string, connectionConfig: CC): Factory<C>;
|
49 | initialise(): Promise<void>;
|
50 | stop(): Promise<void>;
|
51 | ping(readonly: boolean): Promise<void>;
|
52 | abstract getPingQuery(): string;
|
53 | }
|