tspace-mysql 1.9.4 → 1.9.5
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.
- package/README.md +376 -72
- package/dist/cli/dump/db.js +3 -15
- package/dist/cli/dump/db.js.map +1 -1
- package/dist/cli/index.js +0 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrations/make-db.js +1 -1
- package/dist/cli/migrations/make-db.js.map +1 -1
- package/dist/cli/migrations/make-model.js +1 -6
- package/dist/cli/migrations/make-model.js.map +1 -1
- package/dist/lib/config/index.d.ts +6 -5
- package/dist/lib/config/index.js +18 -8
- package/dist/lib/config/index.js.map +1 -1
- package/dist/lib/constants/index.d.ts +1 -1
- package/dist/lib/constants/index.js +1 -1
- package/dist/lib/constants/index.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +2 -1
- package/dist/lib/core/Abstracts/AbstractDB.d.ts +5 -3
- package/dist/lib/core/Abstracts/AbstractDB.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractModel.d.ts +1 -2
- package/dist/lib/core/Abstracts/AbstractModel.js +0 -1
- package/dist/lib/core/Abstracts/AbstractModel.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractView.d.ts +2 -1
- package/dist/lib/core/Abstracts/AbstractView.js.map +1 -1
- package/dist/lib/core/Blueprint.d.ts +13 -3
- package/dist/lib/core/Blueprint.js +16 -1
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +172 -19
- package/dist/lib/core/Builder.js +564 -197
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Cache/DBCache.js +6 -5
- package/dist/lib/core/Cache/DBCache.js.map +1 -1
- package/dist/lib/core/Cache/index.js +1 -1
- package/dist/lib/core/Cache/index.js.map +1 -1
- package/dist/lib/core/Contracts/Audit.d.ts +5 -3
- package/dist/lib/core/Contracts/Audit.js +18 -2
- package/dist/lib/core/Contracts/Audit.js.map +1 -1
- package/dist/lib/core/DB.d.ts +148 -190
- package/dist/lib/core/DB.js +459 -525
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +40 -15
- package/dist/lib/core/Driver/index.js +3 -0
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.d.ts +3 -2
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +7 -5
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +42 -17
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +281 -154
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +4 -3
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +7 -5
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +40 -15
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +205 -157
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.d.ts +3 -2
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +6 -14
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +42 -17
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +251 -144
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.d.ts +3 -2
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +7 -5
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +45 -19
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +471 -287
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +3 -2
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +8 -6
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +47 -19
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +331 -203
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -1
- package/dist/lib/core/Model.d.ts +255 -52
- package/dist/lib/core/Model.js +459 -117
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/core/Package.d.ts +5 -0
- package/dist/lib/core/Package.js +7 -2
- package/dist/lib/core/Package.js.map +1 -1
- package/dist/lib/core/Pool.d.ts +1 -1
- package/dist/lib/core/Pool.js +53 -75
- package/dist/lib/core/Pool.js.map +1 -1
- package/dist/lib/core/Queue/index.d.ts +2 -11
- package/dist/lib/core/Queue/index.js +3 -3
- package/dist/lib/core/Queue/index.js.map +1 -1
- package/dist/lib/core/Queue/types.d.ts +32 -3
- package/dist/lib/core/Queue/worker-lock.d.ts +17 -0
- package/dist/lib/core/Queue/worker-lock.js +28 -0
- package/dist/lib/core/Queue/worker-lock.js.map +1 -0
- package/dist/lib/core/Queue/worker.d.ts +37 -23
- package/dist/lib/core/Queue/worker.js +385 -171
- package/dist/lib/core/Queue/worker.js.map +1 -1
- package/dist/lib/core/RelationManager.js +1 -1
- package/dist/lib/core/RelationManager.js.map +1 -1
- package/dist/lib/core/Repository.d.ts +164 -29
- package/dist/lib/core/Repository.js +181 -40
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +11 -7
- package/dist/lib/core/Schema.js +249 -80
- package/dist/lib/core/Schema.js.map +1 -1
- package/dist/lib/core/SqlLike.js +4 -4
- package/dist/lib/core/SqlLike.js.map +1 -1
- package/dist/lib/core/StateManager.d.ts +19 -0
- package/dist/lib/core/StateManager.js +9 -4
- package/dist/lib/core/StateManager.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +17 -3
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/core/View.d.ts +3 -1
- package/dist/lib/core/View.js +18 -25
- package/dist/lib/core/View.js.map +1 -1
- package/dist/lib/core/index.d.ts +2 -0
- package/dist/lib/core/index.js +3 -1
- package/dist/lib/core/index.js.map +1 -1
- package/dist/lib/types/index.d.ts +77 -90
- package/dist/lib/types/repository/index.d.ts +18 -26
- package/dist/lib/utils/index.d.ts +7 -3
- package/dist/lib/utils/index.js +99 -37
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +1 -2
- package/dist/cli/dump/table.d.ts +0 -4
- package/dist/cli/dump/table.js +0 -41
- package/dist/cli/dump/table.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/Cache/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/Cache/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,uCAAwC;AACxC,6CAA2C;AAC3C,yCAA2C;AAM3C,MAAM,KAAK;IACD,OAAO,CAAe;IAE9B;QACE,IAAI,CAAC,aAAa,CAAC,eAAM,CAAC,KAAkC,CAAC,CAAC;QAE9D,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAiC;QAC7C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,GAAG;QACd,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EA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
event: Blueprint<
|
|
9
|
+
event: Blueprint<T.Default<"INSERTD" | "UPDATED" | "DELETED" | "SELECTED">>;
|
|
10
10
|
user_id: Blueprint<number>;
|
|
11
11
|
metadata: Blueprint<any>;
|
|
12
|
-
auditable_ids: Blueprint<
|
|
12
|
+
auditable_ids: Blueprint<any>;
|
|
13
13
|
old_values: Blueprint<any>;
|
|
14
14
|
new_values: Blueprint<any>;
|
|
15
|
+
changes: Blueprint<any>;
|
|
15
16
|
created_at: Blueprint<T.DateTime | null>;
|
|
16
17
|
updated_at: Blueprint<T.DateTime | null>;
|
|
17
18
|
};
|
|
18
19
|
type TS = T.Schema<typeof schema>;
|
|
19
|
-
|
|
20
|
+
type TR = T.Relation<{}>;
|
|
21
|
+
declare class Audit extends Model<TS, TR> {
|
|
20
22
|
protected boot(): void;
|
|
21
23
|
static tracking(instance: Model<any, any, any>, { sql, fn }: {
|
|
22
24
|
sql: string;
|
|
@@ -8,12 +8,13 @@ const schema = {
|
|
|
8
8
|
uuid: Blueprint_1.Blueprint.varchar(50).null(),
|
|
9
9
|
model: Blueprint_1.Blueprint.varchar(100).notNull(),
|
|
10
10
|
query: Blueprint_1.Blueprint.longText().notNull(),
|
|
11
|
-
event: Blueprint_1.Blueprint.
|
|
11
|
+
event: Blueprint_1.Blueprint.enum('SELECTED', 'INSERTD', 'UPDATED', 'DELETED').default('SELECTED'),
|
|
12
12
|
user_id: Blueprint_1.Blueprint.int().notNull(),
|
|
13
13
|
metadata: Blueprint_1.Blueprint.json().null(),
|
|
14
|
-
auditable_ids: Blueprint_1.Blueprint.
|
|
14
|
+
auditable_ids: Blueprint_1.Blueprint.json().null(),
|
|
15
15
|
old_values: Blueprint_1.Blueprint.json().null(),
|
|
16
16
|
new_values: Blueprint_1.Blueprint.json().null(),
|
|
17
|
+
changes: Blueprint_1.Blueprint.json().null(),
|
|
17
18
|
created_at: Blueprint_1.Blueprint.timestamp().null(),
|
|
18
19
|
updated_at: Blueprint_1.Blueprint.timestamp().null(),
|
|
19
20
|
};
|
|
@@ -77,6 +78,20 @@ class Audit extends Model_1.Model {
|
|
|
77
78
|
.save();
|
|
78
79
|
}
|
|
79
80
|
if (updateRegex.test(sql)) {
|
|
81
|
+
const getChanges = (oldData, newData, key) => {
|
|
82
|
+
const oldMap = new Map(oldData.map(item => [item[key], item]));
|
|
83
|
+
return newData.flatMap(item => {
|
|
84
|
+
const oldItem = oldMap.get(item[key]);
|
|
85
|
+
if (!oldItem)
|
|
86
|
+
return [];
|
|
87
|
+
const changes = Object.fromEntries(Object.keys(item)
|
|
88
|
+
.filter(k => !Object.is(oldItem[k], item[k]))
|
|
89
|
+
.map(k => [k, item[k]]));
|
|
90
|
+
return Object.keys(changes).length
|
|
91
|
+
? [{ [key]: item[key], ...changes }]
|
|
92
|
+
: [];
|
|
93
|
+
});
|
|
94
|
+
};
|
|
80
95
|
const values = await new Model_1.Model()
|
|
81
96
|
.copyModel(instance, {
|
|
82
97
|
where: true,
|
|
@@ -111,6 +126,7 @@ class Audit extends Model_1.Model {
|
|
|
111
126
|
new_values: changed.length
|
|
112
127
|
? JSON.stringify(changed)
|
|
113
128
|
: null,
|
|
129
|
+
changes: getChanges(values, changed, instance['$state'].get('PRIMARY_KEY'))
|
|
114
130
|
})
|
|
115
131
|
.void()
|
|
116
132
|
.bind(instance['$pool'].get())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Audit.js","sourceRoot":"","sources":["../../../../src/lib/core/Contracts/Audit.ts"],"names":[],"mappings":";;;AAAA,oCAAsC;AACtC,4CAA0C;AAG1C,MAAM,MAAM,GAAG;IACX,EAAE,EAAgB,qBAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,aAAa,EAAE;IACrE,IAAI,EAAc,qBAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE;IAC9C,KAAK,EAAa,qBAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAA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,OAAO,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QAEhD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IAClB,CAAC;CACJ;AAEQ,sBAAK;AACd,kBAAe,KAAK,CAAA"}
|
package/dist/lib/core/DB.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractDB } from "./Abstracts/AbstractDB";
|
|
2
|
-
import type {
|
|
2
|
+
import type { T } from "./UtilityTypes";
|
|
3
|
+
import type { TConstant, TClone, TDump, TPoolConnected, TConnectionOptions, TConnection, TRawStringQuery, TFreezeStringQuery, TPoolEvent } from "../types";
|
|
3
4
|
/**
|
|
4
5
|
* The 'DB' class is a component of the database system
|
|
5
6
|
* @param {string?} table table name
|
|
@@ -168,45 +169,17 @@ declare class DB extends AbstractDB {
|
|
|
168
169
|
*/
|
|
169
170
|
static query<T = any>(sql: string, parameters?: (boolean | number | string | any[] | null)[] | Record<string, any>): Promise<T>;
|
|
170
171
|
/**
|
|
171
|
-
* The '
|
|
172
|
-
*
|
|
173
|
-
* @param {string} sql - The SQL statement to execute.
|
|
174
|
-
* @returns {AsyncGenerator<T>} An async generator that yields result rows.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```ts
|
|
178
|
-
* import { DB } from "tspace-mysql";
|
|
179
|
-
*
|
|
180
|
-
* for await (const row of DB.stream('SELECT * FROM users')) {
|
|
181
|
-
* console.log(row);
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
stream<T = any>(sql: string, parameters?: (boolean | number | string | any[] | null)[] | Record<string, any>): AsyncGenerator<T>;
|
|
186
|
-
/**
|
|
187
|
-
* The 'stream' method is used to executes a SQL statement and asynchronously yields result rows.
|
|
172
|
+
* The 'from' method is used to define the from table name.
|
|
188
173
|
*
|
|
189
174
|
* @static
|
|
190
|
-
* @param {string} sql - The SQL statement to execute.
|
|
191
|
-
* @returns {AsyncGenerator<T>} An async generator that yields result rows.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* import { DB } from "tspace-mysql";
|
|
196
|
-
*
|
|
197
|
-
* for await (const row of DB.stream('SELECT * FROM users')) {
|
|
198
|
-
* console.log(row);
|
|
199
|
-
* }
|
|
200
|
-
*/
|
|
201
|
-
static stream<T = any>(sql: string, parameters?: (boolean | number | string | any[] | null)[] | Record<string, any>): AsyncGenerator<T>;
|
|
202
|
-
/**
|
|
203
|
-
* The 'from' method is used to define the from table name.
|
|
204
175
|
* @param {string} table table name
|
|
205
176
|
* @returns {this} this
|
|
206
177
|
*/
|
|
207
178
|
static from(table: string): DB;
|
|
208
179
|
/**
|
|
209
180
|
* The 'table' method is used to define the table name.
|
|
181
|
+
*
|
|
182
|
+
* @static
|
|
210
183
|
* @param {string} table table name
|
|
211
184
|
* @returns {DB} DB
|
|
212
185
|
*/
|
|
@@ -214,11 +187,19 @@ declare class DB extends AbstractDB {
|
|
|
214
187
|
/**
|
|
215
188
|
* The 'alias' method is used to set the table name.
|
|
216
189
|
*
|
|
190
|
+
* @static
|
|
217
191
|
* @param {string} sql raw sql from make a new alias for this table
|
|
218
192
|
* @param {string} alias alias name
|
|
219
193
|
* @returns {DB} DB
|
|
220
194
|
*/
|
|
221
195
|
static alias(sql: string, alias: string): DB;
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @static
|
|
199
|
+
* @override
|
|
200
|
+
* @returns {this} this
|
|
201
|
+
*/
|
|
202
|
+
static dd(debug?: boolean): DB;
|
|
222
203
|
/**
|
|
223
204
|
* The 'jsonObject' method is used to specify select data to JSON objects.
|
|
224
205
|
* @param {string} object table name
|
|
@@ -228,6 +209,7 @@ declare class DB extends AbstractDB {
|
|
|
228
209
|
jsonObject(object: Record<string, string>, alias: string): string;
|
|
229
210
|
/**
|
|
230
211
|
* The 'jsonObject' method is used to specify select data to JSON objects.
|
|
212
|
+
*
|
|
231
213
|
* @static
|
|
232
214
|
* @param {string} object table name
|
|
233
215
|
* @param {string} alias
|
|
@@ -236,6 +218,7 @@ declare class DB extends AbstractDB {
|
|
|
236
218
|
static jsonObject(object: Record<string, string>, alias: string): string;
|
|
237
219
|
/**
|
|
238
220
|
* The 'JSONObject' method is used to specify select data to JSON objects.
|
|
221
|
+
*
|
|
239
222
|
* @param {string} object table name
|
|
240
223
|
* @param {string} alias
|
|
241
224
|
* @returns {string} string
|
|
@@ -243,6 +226,7 @@ declare class DB extends AbstractDB {
|
|
|
243
226
|
JSONObject(object: Record<string, string>, alias: string): string;
|
|
244
227
|
/**
|
|
245
228
|
* The 'JSONObject' method is used to specify select data to JSON objects.
|
|
229
|
+
*
|
|
246
230
|
* @static
|
|
247
231
|
* @param {string} object table name
|
|
248
232
|
* @param {string} alias
|
|
@@ -257,6 +241,7 @@ declare class DB extends AbstractDB {
|
|
|
257
241
|
constants(key?: keyof TConstant): string | object;
|
|
258
242
|
/**
|
|
259
243
|
* The 'constants' method is used to return constants with key or none in 'DB' or 'Model'.
|
|
244
|
+
*
|
|
260
245
|
* @static
|
|
261
246
|
* @param {string} key
|
|
262
247
|
* @returns {string | object} string || object
|
|
@@ -274,6 +259,7 @@ declare class DB extends AbstractDB {
|
|
|
274
259
|
}[], final?: string): string | [];
|
|
275
260
|
/**
|
|
276
261
|
* select by cases
|
|
262
|
+
*
|
|
277
263
|
* @static
|
|
278
264
|
* @param {arrayObject} cases array object {when , then }
|
|
279
265
|
* @param {string?} final else condition
|
|
@@ -284,16 +270,26 @@ declare class DB extends AbstractDB {
|
|
|
284
270
|
then: string;
|
|
285
271
|
}[], final?: string): string | [];
|
|
286
272
|
/**
|
|
287
|
-
* The 'generateUUID' methid is used to generate a universal unique identifier.
|
|
273
|
+
* The 'generateUUID' methid is used to generate a universal unique identifier (UUID).
|
|
274
|
+
*
|
|
275
|
+
* @param options - Options for UUID generation.
|
|
276
|
+
* @param options.v - UUID version to generate: 4 (random) or 7 (time-ordered). Defaults to 7.
|
|
288
277
|
* @returns {string} string
|
|
289
278
|
*/
|
|
290
|
-
generateUUID(
|
|
279
|
+
generateUUID({ v }?: {
|
|
280
|
+
v?: 4 | 7;
|
|
281
|
+
}): string;
|
|
291
282
|
/**
|
|
292
|
-
* The 'generateUUID' methid is used to generate a universal unique identifier.
|
|
283
|
+
* The 'generateUUID' methid is used to generate a universal unique identifier (UUID).
|
|
284
|
+
*
|
|
285
|
+
* @param options - Options for UUID generation.
|
|
286
|
+
* @param options.v - UUID version to generate: 4 (random) or 7 (time-ordered). Defaults to 7.
|
|
293
287
|
* @static
|
|
294
288
|
* @returns {string} string
|
|
295
289
|
*/
|
|
296
|
-
static generateUUID(
|
|
290
|
+
static generateUUID({ v }?: {
|
|
291
|
+
v?: 4 | 7;
|
|
292
|
+
}): string;
|
|
297
293
|
/**
|
|
298
294
|
* The 'snakeCase' methid is used to covert value to snakeCase pattern.
|
|
299
295
|
* @returns {string} string
|
|
@@ -321,6 +317,8 @@ declare class DB extends AbstractDB {
|
|
|
321
317
|
escape(value: string): string;
|
|
322
318
|
/**
|
|
323
319
|
* The 'escape' methid is used to escaping SQL injections.
|
|
320
|
+
*
|
|
321
|
+
* @static
|
|
324
322
|
* @returns {string} string
|
|
325
323
|
*/
|
|
326
324
|
static escape(value: string): string;
|
|
@@ -331,6 +329,8 @@ declare class DB extends AbstractDB {
|
|
|
331
329
|
escapeXSS(value: string): string;
|
|
332
330
|
/**
|
|
333
331
|
* The 'escapeXSS' methid is used to escaping XSS characters.
|
|
332
|
+
*
|
|
333
|
+
* @static
|
|
334
334
|
* @returns {string} string
|
|
335
335
|
*/
|
|
336
336
|
static escapeXSS(value: string): string;
|
|
@@ -425,9 +425,8 @@ declare class DB extends AbstractDB {
|
|
|
425
425
|
*
|
|
426
426
|
* Transactions are typically used when you want to ensure that a series of database operations either all succeed or all fail together,
|
|
427
427
|
* ensuring data integrity.
|
|
428
|
-
*
|
|
429
|
-
* @
|
|
430
|
-
* @property {number | undefined} options.nodeId
|
|
428
|
+
*
|
|
429
|
+
* @param {TPoolConnected} pool
|
|
431
430
|
* @returns {ConnectionTransaction} object - Connection for the transaction
|
|
432
431
|
* @type {object} connection
|
|
433
432
|
* @property {function} connection.query - execute query sql then release connection to pool
|
|
@@ -435,10 +434,7 @@ declare class DB extends AbstractDB {
|
|
|
435
434
|
* @property {function} connection.commit - commit transaction of query
|
|
436
435
|
* @property {function} connection.rollback - rollback transaction of query
|
|
437
436
|
*/
|
|
438
|
-
beginTransaction(
|
|
439
|
-
primaryId?: number;
|
|
440
|
-
nodeId?: number;
|
|
441
|
-
}): Promise<TConnectionTransaction>;
|
|
437
|
+
beginTransaction(pool?: TPoolConnected): Promise<TConnection>;
|
|
442
438
|
/**
|
|
443
439
|
* The 'beginTransaction' is a method used to initiate a database transaction within your application's code.
|
|
444
440
|
*
|
|
@@ -446,10 +442,9 @@ declare class DB extends AbstractDB {
|
|
|
446
442
|
*
|
|
447
443
|
* Transactions are typically used when you want to ensure that a series of database operations either all succeed or all fail together,
|
|
448
444
|
* ensuring data integrity.
|
|
449
|
-
* @param {object} options
|
|
450
|
-
* @property {number | undefined} options.primaryId
|
|
451
|
-
* @property {number | undefined} options.nodeId
|
|
452
445
|
* @static
|
|
446
|
+
*
|
|
447
|
+
* @param {TPoolConnected} pool
|
|
453
448
|
* @returns {ConnectionTransaction} object - Connection for the transaction
|
|
454
449
|
* @type {object} connection
|
|
455
450
|
* @property {function} connection.query - execute query sql then release connection to pool
|
|
@@ -457,12 +452,9 @@ declare class DB extends AbstractDB {
|
|
|
457
452
|
* @property {function} connection.commit - commit transaction of query
|
|
458
453
|
* @property {function} connection.rollback - rollback transaction of query
|
|
459
454
|
*/
|
|
460
|
-
static beginTransaction(
|
|
461
|
-
primaryId?: number;
|
|
462
|
-
nodeId?: number;
|
|
463
|
-
}): Promise<TConnectionTransaction>;
|
|
455
|
+
static beginTransaction(pool?: TPoolConnected): Promise<TConnection>;
|
|
464
456
|
/**
|
|
465
|
-
* Execute a database transaction.
|
|
457
|
+
* The 'transaction' is a method used to Execute a database transaction.
|
|
466
458
|
*
|
|
467
459
|
* This method will:
|
|
468
460
|
* - Acquire a connection from the pool
|
|
@@ -478,9 +470,11 @@ declare class DB extends AbstractDB {
|
|
|
478
470
|
* @returns {Promise<T>} The result returned from the handler.
|
|
479
471
|
*
|
|
480
472
|
*/
|
|
481
|
-
transaction<T>(handler: (conn: TConnection) => Promise<T
|
|
473
|
+
transaction<T>(handler: (conn: TConnection) => Promise<T>, { pool }?: {
|
|
474
|
+
pool?: TPoolConnected;
|
|
475
|
+
}): Promise<T>;
|
|
482
476
|
/**
|
|
483
|
-
* Execute a database transaction.
|
|
477
|
+
* The 'transaction' is a method used to Execute a database transaction.
|
|
484
478
|
*
|
|
485
479
|
* This method will:
|
|
486
480
|
* - Acquire a connection from the pool
|
|
@@ -489,6 +483,7 @@ declare class DB extends AbstractDB {
|
|
|
489
483
|
* - Commit if successful
|
|
490
484
|
* - Rollback if any error occurs
|
|
491
485
|
*
|
|
486
|
+
* @static
|
|
492
487
|
* @template T
|
|
493
488
|
* @param {(conn: TConnection) => Promise<T>} handler - Async function that receives the transaction connection.
|
|
494
489
|
* All queries inside this handler MUST use the provided `conn` instance.
|
|
@@ -496,7 +491,9 @@ declare class DB extends AbstractDB {
|
|
|
496
491
|
* @returns {Promise<T>} The result returned from the handler.
|
|
497
492
|
*
|
|
498
493
|
*/
|
|
499
|
-
static transaction<T>(handler: (conn: TConnection) => Promise<T
|
|
494
|
+
static transaction<T>(handler: (conn: TConnection) => Promise<T>, { pool }?: {
|
|
495
|
+
pool?: TPoolConnected;
|
|
496
|
+
}): Promise<T>;
|
|
500
497
|
/**
|
|
501
498
|
* The 'getActiveConnections' method is used to return active connections
|
|
502
499
|
*
|
|
@@ -506,6 +503,7 @@ declare class DB extends AbstractDB {
|
|
|
506
503
|
/**
|
|
507
504
|
* The 'getActiveConnections' method is used to return active connections
|
|
508
505
|
*
|
|
506
|
+
* @static
|
|
509
507
|
* @returns {Promise<number>} this
|
|
510
508
|
*/
|
|
511
509
|
static getActiveConnections(): Promise<number>;
|
|
@@ -518,175 +516,135 @@ declare class DB extends AbstractDB {
|
|
|
518
516
|
/**
|
|
519
517
|
* The 'getMaxConnections' method is used to return max connections
|
|
520
518
|
*
|
|
519
|
+
* @static
|
|
521
520
|
* @returns {Promise<number>} this
|
|
522
521
|
*/
|
|
523
522
|
static getMaxConnections(): Promise<number>;
|
|
524
523
|
/**
|
|
525
|
-
*
|
|
524
|
+
* This'clone' method is used to clone the current database into a new database
|
|
525
|
+
* on the same server or another server.
|
|
526
526
|
*
|
|
527
|
-
* @
|
|
528
|
-
* @
|
|
529
|
-
* @
|
|
527
|
+
* @property {string} database - Target database name.
|
|
528
|
+
* @property {string[]} excludes - Tables to exclude from the clone.
|
|
529
|
+
* @property {object} to - Target server connection.
|
|
530
|
+
* @property {string} to.host - Target server host.
|
|
531
|
+
* @property {number} to.port - Target server port.
|
|
532
|
+
* @property {string} to.username - Target server username.
|
|
533
|
+
* @property {string} to.password - Target server password.
|
|
534
|
+
* @returns {Promise<void>}
|
|
530
535
|
*/
|
|
531
|
-
|
|
536
|
+
clone({ database, excludes, only, value, to }: TClone): Promise<void>;
|
|
532
537
|
/**
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
538
|
+
* This'clone' method is used to clone the current database into a new database
|
|
539
|
+
* on the same server or another server.
|
|
540
|
+
*
|
|
541
|
+
* @static
|
|
542
|
+
* @property {string} database - Target database name.
|
|
543
|
+
* @property {string[]} excludes - Tables to exclude from the clone.
|
|
544
|
+
* @property {object} to - Target server connection.
|
|
545
|
+
* @property {string} to.host - Target server host.
|
|
546
|
+
* @property {number} to.port - Target server port.
|
|
547
|
+
* @property {string} to.username - Target server username.
|
|
548
|
+
* @property {string} to.password - Target server password.
|
|
549
|
+
* @returns {Promise<void>}
|
|
550
|
+
*/
|
|
551
|
+
static clone({ database, only, excludes, value, to }: TClone): Promise<void>;
|
|
540
552
|
/**
|
|
541
553
|
*
|
|
542
|
-
* This '
|
|
543
|
-
* @type
|
|
544
|
-
* @property {string}
|
|
545
|
-
* @
|
|
546
|
-
* @property {string}
|
|
547
|
-
* @property {
|
|
548
|
-
* @property {string} backup.to.username
|
|
549
|
-
* @property {string} backup.to.password
|
|
554
|
+
* This 'dump' method is used to Dumps a database into a SQL file
|
|
555
|
+
* @type {Object} opt
|
|
556
|
+
* @property {string?} opt.database
|
|
557
|
+
* @property {string} opt.filePath
|
|
558
|
+
* @property {string[]} opt.excludes
|
|
559
|
+
* @property {boolean?} opt.value
|
|
550
560
|
* @returns {Promise<void>}
|
|
551
561
|
*/
|
|
552
|
-
|
|
562
|
+
dump({ filePath, excludes, only, database, value }: TDump): Promise<void>;
|
|
553
563
|
/**
|
|
564
|
+
* This 'dump' method is used to Dumps a database into a SQL file
|
|
554
565
|
*
|
|
555
|
-
*
|
|
556
|
-
* @type
|
|
557
|
-
* @property {string}
|
|
558
|
-
* @
|
|
559
|
-
* @property {string}
|
|
560
|
-
* @property {
|
|
561
|
-
* @property {string} backup.to.username
|
|
562
|
-
* @property {string} backup.to.password
|
|
566
|
+
* @static
|
|
567
|
+
* @type {Object} opt
|
|
568
|
+
* @property {string?} opt.database
|
|
569
|
+
* @property {string} opt.filePath
|
|
570
|
+
* @property {string[]} opt.excludes
|
|
571
|
+
* @property {boolean?} opt.value
|
|
563
572
|
* @returns {Promise<void>}
|
|
564
573
|
*/
|
|
565
|
-
static
|
|
574
|
+
static dump({ filePath, database, excludes, only, value, }: TDump): Promise<void>;
|
|
566
575
|
/**
|
|
576
|
+
* This 'session' method is used to manage database session variables.
|
|
567
577
|
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* @property {string} backup.database
|
|
571
|
-
* @property {string} backup.filePath
|
|
572
|
-
* @type {object?} backup.connection
|
|
573
|
-
* @property {string} backup.connection.host
|
|
574
|
-
* @property {number} backup.connection.port
|
|
575
|
-
* @property {number} backup.connection.database
|
|
576
|
-
* @property {string} backup.connection.username
|
|
577
|
-
* @property {string} backup.connection.password
|
|
578
|
-
* @returns {Promise<void>}
|
|
579
|
-
*/
|
|
580
|
-
backupToFile({ filePath, database, connection, }: TBackupToFile): Promise<void>;
|
|
581
|
-
/**
|
|
578
|
+
* Provides methods to get and set session variables for the current
|
|
579
|
+
* database connection.
|
|
582
580
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* @property {string} backup.connection.host
|
|
589
|
-
* @property {number} backup.connection.port
|
|
590
|
-
* @property {number} backup.connection.database
|
|
591
|
-
* @property {string} backup.connection.username
|
|
592
|
-
* @property {string} backup.connection.password
|
|
593
|
-
* @returns {Promise<void>}
|
|
594
|
-
*/
|
|
595
|
-
static backupToFile({ filePath, database, connection, }: TBackupToFile): Promise<void>;
|
|
596
|
-
/**
|
|
581
|
+
* Supported drivers:
|
|
582
|
+
* - MySQL
|
|
583
|
+
* - MariaDB
|
|
584
|
+
* - PostgreSQL
|
|
585
|
+
* - SQLite
|
|
597
586
|
*
|
|
598
|
-
*
|
|
599
|
-
* @type {Object} backup
|
|
600
|
-
* @property {string} backup.database
|
|
601
|
-
* @property {string} backup.filePath
|
|
602
|
-
* @type {object?} backup.connection
|
|
603
|
-
* @property {string} backup.connection.host
|
|
604
|
-
* @property {number} backup.connection.port
|
|
605
|
-
* @property {number} backup.connection.database
|
|
606
|
-
* @property {string} backup.connection.username
|
|
607
|
-
* @property {string} backup.connection.password
|
|
608
|
-
* @returns {Promise<void>}
|
|
609
|
-
*/
|
|
610
|
-
backupSchemaToFile({ filePath, database, connection, }: TBackupToFile): Promise<void>;
|
|
611
|
-
/**
|
|
587
|
+
* MongoDB is not supported.
|
|
612
588
|
*
|
|
613
|
-
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```ts
|
|
591
|
+
* await DB.session().set('db', 'primary');
|
|
614
592
|
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
* @property {string} backup.connection.host
|
|
620
|
-
* @property {number} backup.connection.port
|
|
621
|
-
* @property {number} backup.connection.database
|
|
622
|
-
* @property {string} backup.connection.username
|
|
623
|
-
* @property {string} backup.connection.password
|
|
624
|
-
* @returns {Promise<void>}
|
|
593
|
+
* const value = await db.session().get('db');
|
|
594
|
+
* console.log(value) // primary
|
|
595
|
+
*
|
|
596
|
+
* ```
|
|
625
597
|
*/
|
|
626
|
-
|
|
598
|
+
session(): {
|
|
599
|
+
get(name: string): Promise<string | null>;
|
|
600
|
+
set(name: string, value: string): Promise<void>;
|
|
601
|
+
delete(name: string): Promise<void>;
|
|
602
|
+
};
|
|
627
603
|
/**
|
|
604
|
+
* This 'session' method is used to manage database session variables.
|
|
628
605
|
*
|
|
629
|
-
*
|
|
606
|
+
* Provides methods to get and set session variables for the current
|
|
607
|
+
* database connection.
|
|
630
608
|
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* @property {number} backup.connection.port
|
|
637
|
-
* @property {number} backup.connection.database
|
|
638
|
-
* @property {string} backup.connection.username
|
|
639
|
-
* @property {string} backup.connection.password
|
|
640
|
-
* @returns {Promise<void>}
|
|
641
|
-
*/
|
|
642
|
-
backupTableToFile({ filePath, table, connection, }: TBackupTableToFile): Promise<void>;
|
|
643
|
-
/**
|
|
609
|
+
* Supported drivers:
|
|
610
|
+
* - MySQL
|
|
611
|
+
* - MariaDB
|
|
612
|
+
* - PostgreSQL
|
|
613
|
+
* - SQLite
|
|
644
614
|
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* @
|
|
648
|
-
*
|
|
649
|
-
* @
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
615
|
+
* MongoDB is not supported.
|
|
616
|
+
*
|
|
617
|
+
* @static
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* await DB.session().set('db', 'primary');
|
|
622
|
+
*
|
|
623
|
+
* const value = await db.session().get('db');
|
|
624
|
+
* console.log(value) // primary
|
|
625
|
+
*
|
|
626
|
+
* ```
|
|
656
627
|
*/
|
|
657
|
-
static
|
|
628
|
+
static session(): {
|
|
629
|
+
get(name: string): Promise<string | null>;
|
|
630
|
+
set(name: string, value: string): Promise<void>;
|
|
631
|
+
delete(name: string): Promise<void>;
|
|
632
|
+
};
|
|
658
633
|
/**
|
|
634
|
+
* This 'timestamp' method is used to convert a date into a timestamp.
|
|
659
635
|
*
|
|
660
|
-
*
|
|
661
|
-
* @
|
|
662
|
-
* @property {string} backup.database
|
|
663
|
-
* @property {string} backup.filePath
|
|
664
|
-
* @type {object?} backup.connection
|
|
665
|
-
* @property {string} backup.connection.host
|
|
666
|
-
* @property {number} backup.connection.port
|
|
667
|
-
* @property {number} backup.connection.database
|
|
668
|
-
* @property {string} backup.connection.username
|
|
669
|
-
* @property {string} backup.connection.password
|
|
670
|
-
* @returns {Promise<void>}
|
|
636
|
+
* @type {string | Date} dateString
|
|
637
|
+
* @returns {T.DateTime}
|
|
671
638
|
*/
|
|
672
|
-
|
|
639
|
+
timestamp(dateString?: string | Date): T.DateTime;
|
|
673
640
|
/**
|
|
641
|
+
* This 'timestamp' method is used to convert a date into a timestamp.
|
|
674
642
|
*
|
|
675
|
-
*
|
|
676
|
-
* @type {
|
|
677
|
-
* @
|
|
678
|
-
* @property {string} backup.filePath
|
|
679
|
-
* @type {object?} backup.connection
|
|
680
|
-
* @property {string} backup.connection.host
|
|
681
|
-
* @property {number} backup.connection.port
|
|
682
|
-
* @property {number} backup.connection.database
|
|
683
|
-
* @property {string} backup.connection.username
|
|
684
|
-
* @property {string} backup.connection.password
|
|
685
|
-
* @returns {Promise<void>}
|
|
643
|
+
* @static
|
|
644
|
+
* @type {string | Date} dateString
|
|
645
|
+
* @returns {T.DateTime}
|
|
686
646
|
*/
|
|
687
|
-
static
|
|
688
|
-
private _backup;
|
|
689
|
-
private _backupToString;
|
|
647
|
+
static timestamp(dateString?: string | Date): T.DateTime;
|
|
690
648
|
private _initialDB;
|
|
691
649
|
}
|
|
692
650
|
export { DB };
|