baja-lite 1.8.8 → 1.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/boot-remote.d.ts +1 -1
  2. package/boot-remote.js +6 -1
  3. package/boot.d.ts +1 -1
  4. package/boot.js +6 -1
  5. package/cache.d.ts +91 -0
  6. package/cache.js +515 -0
  7. package/const/index.d.ts +2 -0
  8. package/const/index.js +2 -0
  9. package/const/symbols.d.ts +73 -0
  10. package/const/symbols.js +78 -0
  11. package/const/types.d.ts +504 -0
  12. package/const/types.js +127 -0
  13. package/db/dao/format-dialects.d.ts +6 -0
  14. package/db/dao/format-dialects.js +8 -0
  15. package/db/dao/mysql.d.ts +44 -0
  16. package/db/dao/mysql.js +303 -0
  17. package/db/dao/postgresql.d.ts +44 -0
  18. package/db/dao/postgresql.js +322 -0
  19. package/db/dao/sqlite-remote.d.ts +46 -0
  20. package/db/dao/sqlite-remote.js +226 -0
  21. package/db/dao/sqlite.d.ts +41 -0
  22. package/db/dao/sqlite.js +237 -0
  23. package/db/index.d.ts +8 -0
  24. package/db/index.js +8 -0
  25. package/db/service.d.ts +778 -0
  26. package/db/service.js +1651 -0
  27. package/db/sql-template.d.ts +46 -0
  28. package/db/sql-template.js +660 -0
  29. package/db/stream-query.d.ts +607 -0
  30. package/db/stream-query.js +1626 -0
  31. package/index.d.ts +4 -1
  32. package/index.js +4 -1
  33. package/logger.d.ts +46 -0
  34. package/logger.js +35 -0
  35. package/package.json +1 -1
  36. package/sqlite.d.ts +1 -1
  37. package/sqlite.js +2 -1
  38. package/{test-mysql.js → test/test-mysql.js} +3 -2
  39. package/{test-postgresql.js → test/test-postgresql.js} +3 -2
  40. package/{test-sqlite.js → test/test-sqlite.js} +3 -2
  41. package/sql.d.ts +0 -2222
  42. package/sql.js +0 -5503
  43. /package/{test-mysql.d.ts → test/test-mysql.d.ts} +0 -0
  44. /package/{test-postgresql.d.ts → test/test-postgresql.d.ts} +0 -0
  45. /package/{test-sqlite.d.ts → test/test-sqlite.d.ts} +0 -0
  46. /package/{test-xml.d.ts → test/test-xml.d.ts} +0 -0
  47. /package/{test-xml.js → test/test-xml.js} +0 -0
package/const/types.js ADDED
@@ -0,0 +1,127 @@
1
+ import { DEFAULT_MAX_DEAL, _daoConnection, _daoDB, _inTransaction } from '../const/symbols.js';
2
+ // ===== 枚举 =====
3
+ export var MapperIfUndefined;
4
+ (function (MapperIfUndefined) {
5
+ MapperIfUndefined[MapperIfUndefined["Null"] = 0] = "Null";
6
+ MapperIfUndefined[MapperIfUndefined["Skip"] = 1] = "Skip";
7
+ MapperIfUndefined[MapperIfUndefined["Zero"] = 2] = "Zero";
8
+ MapperIfUndefined[MapperIfUndefined["EmptyString"] = 3] = "EmptyString";
9
+ })(MapperIfUndefined || (MapperIfUndefined = {}));
10
+ ;
11
+ export var SyncMode;
12
+ (function (SyncMode) {
13
+ /** 同步执行 */
14
+ SyncMode[SyncMode["Sync"] = 0] = "Sync";
15
+ /** 异步执行 */
16
+ SyncMode[SyncMode["Async"] = 1] = "Async";
17
+ })(SyncMode || (SyncMode = {}));
18
+ export var InsertMode;
19
+ (function (InsertMode) {
20
+ /**
21
+ # 默认使用
22
+ ** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
23
+ ** 批量执行有性能优势,但无法利用数据库的sql预编译功能
24
+ */
25
+ InsertMode[InsertMode["Insert"] = 0] = "Insert";
26
+ /**
27
+ # 利用临时表
28
+ ## 执行步骤
29
+ 1. 建立临时表(从正式表复制)
30
+ 2. 数据全部进入临时表
31
+ 3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
32
+ 4. 删除临时表
33
+ ## 注意
34
+ 1. 适用于:主键不会冲突、非自增
35
+ 2. 临时表的结构复制正式表
36
+ */
37
+ InsertMode[InsertMode["InsertWithTempTable"] = 1] = "InsertWithTempTable";
38
+ /**
39
+ * 如果不存在则插入
40
+ * 来源是数据库,根据ID或者指定字段查询
41
+ */
42
+ InsertMode[InsertMode["InsertIfNotExists"] = 2] = "InsertIfNotExists";
43
+ /**
44
+ # 插入或者更新
45
+ 1. 判断依据是主键,来源是从数据库查询
46
+ */
47
+ InsertMode[InsertMode["Replace"] = 3] = "Replace";
48
+ })(InsertMode || (InsertMode = {}));
49
+ export var DeleteMode;
50
+ (function (DeleteMode) {
51
+ /**
52
+ ##常规删除 默认
53
+ ### 例一
54
+ `DELETE FROM WHERE (id = 1) OR (id = 2)`
55
+ ### 例二
56
+ `DELETE FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
57
+ */
58
+ DeleteMode[DeleteMode["Common"] = 0] = "Common";
59
+ /*
60
+ ## 借助临时表
61
+ ### 注意:必须保证where的字段都相同,否则会漏删数据
62
+ DELETE FROM 正式表 INNER JOIN 临时表 WHERE 字段1 = 字段1 AND 字段2 = 字段2
63
+ */
64
+ DeleteMode[DeleteMode["TempTable"] = 1] = "TempTable";
65
+ })(DeleteMode || (DeleteMode = {}));
66
+ export var SelectMode;
67
+ (function (SelectMode) {
68
+ /**
69
+ ##常规 默认
70
+ ### 例一
71
+ `SELECT * FROM WHERE (id = 1) OR (id = 2)`
72
+ ### 例二
73
+ `SELECT * FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
74
+ */
75
+ SelectMode[SelectMode["Common"] = 0] = "Common";
76
+ /*
77
+ ## 借助临时表
78
+ ### 注意:必须保证where的字段都相同,否则会漏删数据
79
+ SELECT * FROM 正式表 INNER JOIN 临时表 WHERE 字段1 = 字段1 AND 字段2 = 字段2
80
+ */
81
+ SelectMode[SelectMode["TempTable"] = 1] = "TempTable";
82
+ })(SelectMode || (SelectMode = {}));
83
+ export var TemplateResult;
84
+ (function (TemplateResult) {
85
+ /** 确定返回一条记录,如果不是一个,将报错,返回类型是T */
86
+ TemplateResult[TemplateResult["AssertOne"] = 0] = "AssertOne";
87
+ /** 可能返回一条记录,返回类型是T|null */
88
+ TemplateResult[TemplateResult["NotSureOne"] = 1] = "NotSureOne";
89
+ /** 返回多条记录 */
90
+ TemplateResult[TemplateResult["Many"] = 2] = "Many";
91
+ /** 仅查询记录数量 */
92
+ TemplateResult[TemplateResult["Count"] = 3] = "Count";
93
+ })(TemplateResult || (TemplateResult = {}));
94
+ export var SelectResult;
95
+ (function (SelectResult) {
96
+ /** 一行一列 确定非空 */
97
+ SelectResult[SelectResult["R_C_Assert"] = 0] = "R_C_Assert";
98
+ /** 一行一列 可能空 */
99
+ SelectResult[SelectResult["R_C_NotSure"] = 1] = "R_C_NotSure";
100
+ /** 一行多列 确定非空 */
101
+ SelectResult[SelectResult["R_CS_Assert"] = 2] = "R_CS_Assert";
102
+ /** 一行多列 可能空 */
103
+ SelectResult[SelectResult["R_CS_NotSure"] = 3] = "R_CS_NotSure";
104
+ /** 多行一列 */
105
+ SelectResult[SelectResult["RS_C"] = 4] = "RS_C";
106
+ /** 多行多列 */
107
+ SelectResult[SelectResult["RS_CS"] = 5] = "RS_CS";
108
+ })(SelectResult || (SelectResult = {}));
109
+ export var ColumnMode;
110
+ (function (ColumnMode) {
111
+ ColumnMode[ColumnMode["NONE"] = 0] = "NONE";
112
+ ColumnMode[ColumnMode["HUMP"] = 1] = "HUMP";
113
+ })(ColumnMode || (ColumnMode = {}));
114
+ // ===== 常量 =====
115
+ export const SqliteMemory = ':memory:';
116
+ export const _defOption = {
117
+ maxDeal: DEFAULT_MAX_DEAL,
118
+ skipUndefined: true,
119
+ skipNull: true,
120
+ skipEmptyString: true
121
+ };
122
+ /** 缓存存储后端。`redis` 走 ioredis 全局共享;`memory` 走进程内 LRU + Promise-based single-flight。 */
123
+ export var StorageType;
124
+ (function (StorageType) {
125
+ StorageType[StorageType["Redis"] = 0] = "Redis";
126
+ StorageType[StorageType["Memory"] = 1] = "Memory";
127
+ })(StorageType || (StorageType = {}));
@@ -0,0 +1,6 @@
1
+ export declare const formatDialects: {
2
+ 0: import("sql-formatter").DialectOptions;
3
+ 2: import("sql-formatter").DialectOptions;
4
+ 4: import("sql-formatter").DialectOptions;
5
+ 1: import("sql-formatter").DialectOptions;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { DBType } from 'baja-lite-field';
2
+ import { mysql, postgresql, sqlite } from 'sql-formatter';
3
+ export const formatDialects = {
4
+ [DBType.Mysql]: mysql,
5
+ [DBType.Sqlite]: sqlite,
6
+ [DBType.SqliteRemote]: sqlite,
7
+ [DBType.Postgresql]: postgresql,
8
+ };
@@ -0,0 +1,44 @@
1
+ import { _daoConnection, _daoDB, _inTransaction } from '../../const/symbols.js';
2
+ import { Connection, Dao, SyncMode } from '../../const/types.js';
3
+ export declare class MysqlConnection implements Connection {
4
+ [_daoConnection]: any;
5
+ [_inTransaction]: boolean;
6
+ constructor(conn: any);
7
+ execute(sync: SyncMode.Sync, sql?: string, params?: any): {
8
+ affectedRows: number;
9
+ insertId: bigint;
10
+ };
11
+ execute(sync: SyncMode.Async, sql?: string, params?: any): Promise<{
12
+ affectedRows: number;
13
+ insertId: bigint;
14
+ }>;
15
+ pluck<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T | null;
16
+ pluck<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T | null>;
17
+ get<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T | null;
18
+ get<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T | null>;
19
+ raw<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T[];
20
+ raw<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T[]>;
21
+ query<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T[];
22
+ query<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T[]>;
23
+ release(sync: SyncMode.Sync): void;
24
+ release(sync: SyncMode.Async): Promise<void>;
25
+ }
26
+ export declare class Mysql implements Dao {
27
+ [_daoDB]: any;
28
+ private keepAliveTimer?;
29
+ private isClosing;
30
+ constructor(pool: any);
31
+ keepAlive(): Promise<void>;
32
+ createConnection(sync: SyncMode.Sync): Connection | null;
33
+ createConnection(sync: SyncMode.Async): Promise<Connection | null>;
34
+ transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
35
+ transaction<T = any>(sync: SyncMode.Async, fn: (conn: Connection) => Promise<T>, conn?: Connection | null): Promise<T | null>;
36
+ close(sync: SyncMode.Sync): void;
37
+ close(sync: SyncMode.Async): Promise<void>;
38
+ backup(sync: SyncMode.Sync, name: string): void;
39
+ backup(sync: SyncMode.Async, name: string): Promise<void>;
40
+ remove(sync: SyncMode.Sync): void;
41
+ remove(sync: SyncMode.Async): Promise<void>;
42
+ restore(sync: SyncMode.Sync, name: string): void;
43
+ restore(sync: SyncMode.Async, name: string): Promise<void>;
44
+ }
@@ -0,0 +1,303 @@
1
+ var _a;
2
+ import { _daoConnection, _daoDB, _GlobalSqlOption, _inTransaction, _LoggerService, _MysqlKeepAliveTime, DEFAULT_KEEPALIVE_INTERVAL } from '../../const/symbols.js';
3
+ import { SyncMode } from '../../const/types.js';
4
+ export class MysqlConnection {
5
+ constructor(conn) {
6
+ this[_a] = false;
7
+ this[_daoConnection] = conn;
8
+ }
9
+ execute(sync, sql, params) {
10
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
11
+ if (!sql) {
12
+ return { affectedRows: 0, insertId: 0n };
13
+ }
14
+ ;
15
+ if (sync === SyncMode.Sync) {
16
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
17
+ return { affectedRows: 0, insertId: 0n };
18
+ }
19
+ ;
20
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
21
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
22
+ }
23
+ return (async () => {
24
+ try {
25
+ const [_result] = await this[_daoConnection].execute(sql, params);
26
+ const result = _result;
27
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
28
+ globalThis[_LoggerService].verbose?.(result);
29
+ }
30
+ return { affectedRows: result.affectedRows, insertId: result.insertId };
31
+ }
32
+ catch (error) {
33
+ globalThis[_LoggerService].error(error.message, { cause: error });
34
+ throw error;
35
+ }
36
+ })();
37
+ }
38
+ pluck(sync, sql, params) {
39
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
40
+ if (!sql) {
41
+ return null;
42
+ }
43
+ ;
44
+ if (sync === SyncMode.Sync) {
45
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
46
+ return null;
47
+ }
48
+ ;
49
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
50
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
51
+ }
52
+ return (async () => {
53
+ try {
54
+ const [result] = await this[_daoConnection].query(sql, params);
55
+ if (result && result[0]) {
56
+ const r = Object.values(result[0])[0];
57
+ return r === null ? null : r;
58
+ }
59
+ return null;
60
+ }
61
+ catch (error) {
62
+ globalThis[_LoggerService].error(`
63
+ error: ${error},
64
+ sql: ${sql},
65
+ params: ${params}
66
+ `);
67
+ throw error;
68
+ }
69
+ })();
70
+ }
71
+ get(sync, sql, params) {
72
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
73
+ if (!sql) {
74
+ return null;
75
+ }
76
+ ;
77
+ if (sync === SyncMode.Sync) {
78
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
79
+ return null;
80
+ }
81
+ ;
82
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
83
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
84
+ }
85
+ return (async () => {
86
+ try {
87
+ const [result] = await this[_daoConnection].query(sql, params);
88
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
89
+ globalThis[_LoggerService].verbose?.(result);
90
+ }
91
+ if (result && result[0]) {
92
+ return result[0];
93
+ }
94
+ return null;
95
+ }
96
+ catch (error) {
97
+ globalThis[_LoggerService].error(`
98
+ error: ${error},
99
+ sql: ${sql},
100
+ params: ${params}
101
+ `);
102
+ throw error;
103
+ }
104
+ })();
105
+ }
106
+ raw(sync, sql, params) {
107
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
108
+ if (!sql) {
109
+ return [];
110
+ }
111
+ ;
112
+ if (sync === SyncMode.Sync) {
113
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
114
+ return [];
115
+ }
116
+ ;
117
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
118
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
119
+ }
120
+ return (async () => {
121
+ try {
122
+ const [result] = await this[_daoConnection].query(sql, params);
123
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
124
+ globalThis[_LoggerService].verbose?.(result);
125
+ }
126
+ // 修复 fall-through:原代码 `if (result) resolve(...); resolve([])` 第二行
127
+ // 是 no-op,但写法埋雷。
128
+ if (result) {
129
+ return result.map((i) => Object.values(i)[0]);
130
+ }
131
+ return [];
132
+ }
133
+ catch (error) {
134
+ globalThis[_LoggerService].error(`
135
+ error: ${error},
136
+ sql: ${sql},
137
+ params: ${params}
138
+ `);
139
+ throw error;
140
+ }
141
+ })();
142
+ }
143
+ query(sync, sql, params) {
144
+ globalThis[_LoggerService].debug?.(sql, params ?? '');
145
+ if (!sql) {
146
+ return [];
147
+ }
148
+ ;
149
+ if (sync === SyncMode.Sync) {
150
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
151
+ return [];
152
+ }
153
+ ;
154
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
155
+ globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
156
+ }
157
+ return (async () => {
158
+ try {
159
+ const [result] = await this[_daoConnection].query(sql, params);
160
+ if (globalThis[_GlobalSqlOption].log === 'trace') {
161
+ globalThis[_LoggerService].verbose?.(result);
162
+ }
163
+ return result;
164
+ }
165
+ catch (error) {
166
+ globalThis[_LoggerService].error(`
167
+ error: ${error},
168
+ sql: ${sql},
169
+ params: ${params}
170
+ `);
171
+ throw error;
172
+ }
173
+ })();
174
+ }
175
+ release(sync) {
176
+ try {
177
+ this[_daoConnection]?.release();
178
+ }
179
+ catch (error) {
180
+ }
181
+ if (sync === SyncMode.Async) {
182
+ return Promise.resolve();
183
+ }
184
+ }
185
+ }
186
+ _a = _inTransaction;
187
+ export class Mysql {
188
+ constructor(pool) {
189
+ this.isClosing = false;
190
+ this[_daoDB] = pool;
191
+ this.keepAlive();
192
+ }
193
+ async keepAlive() {
194
+ if (this.isClosing)
195
+ return;
196
+ let connection = null;
197
+ try {
198
+ connection = await this.createConnection(SyncMode.Async);
199
+ if (connection) {
200
+ await connection.query(SyncMode.Async, 'SELECT 1 FROM DUAL');
201
+ // (globalThis[_LoggerService]! as LoggerService).debug?.('keepAlive->', data?.[0]?.[1]);
202
+ }
203
+ }
204
+ catch (error) {
205
+ globalThis[_LoggerService].error('keepAlive error', error);
206
+ }
207
+ finally {
208
+ if (connection) {
209
+ await connection.release(SyncMode.Async);
210
+ }
211
+ if (!this.isClosing) {
212
+ this.keepAliveTimer = setTimeout(() => this.keepAlive(), globalThis[_MysqlKeepAliveTime] ?? DEFAULT_KEEPALIVE_INTERVAL);
213
+ }
214
+ }
215
+ }
216
+ createConnection(sync) {
217
+ if (sync === SyncMode.Sync) {
218
+ globalThis[_LoggerService].error('MYSQL not supported sync mode');
219
+ return null;
220
+ }
221
+ ;
222
+ return (async () => {
223
+ try {
224
+ const connection = await this[_daoDB].getConnection();
225
+ globalThis[_LoggerService].debug?.('create new connection!');
226
+ return new MysqlConnection(connection);
227
+ }
228
+ catch (error) {
229
+ globalThis[_LoggerService].error(error.message, { cause: error });
230
+ throw error;
231
+ }
232
+ })();
233
+ }
234
+ transaction(sync, fn, conn) {
235
+ if (sync === SyncMode.Sync) {
236
+ globalThis[_LoggerService].warn('MYSQL not supported sync mode');
237
+ return null;
238
+ }
239
+ ;
240
+ return (async () => {
241
+ let needCommit = false;
242
+ let newConn = false;
243
+ if (!conn) {
244
+ conn = await this.createConnection(SyncMode.Async) ?? undefined;
245
+ newConn = true;
246
+ }
247
+ if (conn?.[_inTransaction] !== true) {
248
+ needCommit = true;
249
+ globalThis[_LoggerService].debug?.('beginTransaction begin!');
250
+ await conn[_daoConnection].beginTransaction();
251
+ globalThis[_LoggerService].debug?.('beginTransaction end!');
252
+ }
253
+ conn[_inTransaction] = true;
254
+ try {
255
+ const result = await fn(conn);
256
+ if (needCommit) {
257
+ globalThis[_LoggerService].debug?.('commit begin!');
258
+ await conn[_daoConnection].commit();
259
+ globalThis[_LoggerService].debug?.('commit end!');
260
+ }
261
+ return result;
262
+ }
263
+ catch (error) {
264
+ if (needCommit) {
265
+ globalThis[_LoggerService].debug?.('rollback begin!');
266
+ await conn[_daoConnection].rollback();
267
+ globalThis[_LoggerService].debug?.('rollback end!');
268
+ }
269
+ globalThis[_LoggerService].error(error.message, { cause: error });
270
+ throw error;
271
+ }
272
+ finally {
273
+ try {
274
+ if (needCommit) {
275
+ conn[_inTransaction] = false;
276
+ }
277
+ if (newConn) {
278
+ globalThis[_LoggerService].debug?.('release begin!');
279
+ conn[_daoConnection].release();
280
+ globalThis[_LoggerService].debug?.('release end!');
281
+ }
282
+ }
283
+ catch (error) {
284
+ // 释放连接失败通常不影响业务逻辑,记录日志即可
285
+ globalThis[_LoggerService].warn?.('Failed to release connection in finally block', error);
286
+ }
287
+ }
288
+ })();
289
+ }
290
+ close(sync) {
291
+ this.isClosing = true;
292
+ if (this.keepAliveTimer) {
293
+ clearTimeout(this.keepAliveTimer);
294
+ }
295
+ return this[_daoDB]?.destroy();
296
+ }
297
+ backup(sync, name) {
298
+ }
299
+ remove(sync) {
300
+ }
301
+ restore(sync, name) {
302
+ }
303
+ }
@@ -0,0 +1,44 @@
1
+ import { _daoConnection, _daoDB, _inTransaction } from '../../const/symbols.js';
2
+ import { Connection, Dao, SyncMode } from '../../const/types.js';
3
+ export declare class PostgresqlConnection implements Connection {
4
+ [_daoConnection]: any;
5
+ [_inTransaction]: boolean;
6
+ constructor(conn: any);
7
+ execute(sync: SyncMode.Sync, sql?: string, params?: any): {
8
+ affectedRows: number;
9
+ insertId: bigint;
10
+ };
11
+ execute(sync: SyncMode.Async, sql?: string, params?: any): Promise<{
12
+ affectedRows: number;
13
+ insertId: bigint;
14
+ }>;
15
+ pluck<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T | null;
16
+ pluck<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T | null>;
17
+ get<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T | null;
18
+ get<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T | null>;
19
+ raw<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T[];
20
+ raw<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T[]>;
21
+ query<T = any>(sync: SyncMode.Sync, sql?: string, params?: any): T[];
22
+ query<T = any>(sync: SyncMode.Async, sql?: string, params?: any): Promise<T[]>;
23
+ release(sync: SyncMode.Sync): void;
24
+ release(sync: SyncMode.Async): Promise<void>;
25
+ }
26
+ export declare class Postgresql implements Dao {
27
+ [_daoDB]: any;
28
+ private keepAliveTimer?;
29
+ private isClosing;
30
+ constructor(pool: any);
31
+ keepAlive(): Promise<void>;
32
+ createConnection(sync: SyncMode.Sync): Connection | null;
33
+ createConnection(sync: SyncMode.Async): Promise<Connection | null>;
34
+ transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
35
+ transaction<T = any>(sync: SyncMode.Async, fn: (conn: Connection) => Promise<T>, conn?: Connection | null): Promise<T | null>;
36
+ close(sync: SyncMode.Sync): void;
37
+ close(sync: SyncMode.Async): Promise<void>;
38
+ backup(sync: SyncMode.Sync, name: string): void;
39
+ backup(sync: SyncMode.Async, name: string): Promise<void>;
40
+ remove(sync: SyncMode.Sync): void;
41
+ remove(sync: SyncMode.Async): Promise<void>;
42
+ restore(sync: SyncMode.Sync, name: string): void;
43
+ restore(sync: SyncMode.Async, name: string): Promise<void>;
44
+ }