tspace-mysql 1.3.2 → 1.3.4
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/dist/lib/connection/index.js +6 -8
- package/dist/lib/connection/options.d.ts +3 -0
- package/dist/lib/connection/options.js +4 -1
- package/dist/lib/constants/index.js +1 -0
- package/dist/lib/tspace/AbstractBuilder.d.ts +1 -0
- package/dist/lib/tspace/AbstractDB.d.ts +2 -0
- package/dist/lib/tspace/Builder.d.ts +7 -0
- package/dist/lib/tspace/Builder.js +27 -6
- package/dist/lib/tspace/DB.d.ts +0 -1
- package/dist/lib/tspace/DB.js +0 -9
- package/dist/lib/tspace/Model.js +11 -14
- package/package.json +1 -1
|
@@ -79,22 +79,20 @@ class PoolConnection {
|
|
|
79
79
|
}
|
|
80
80
|
_defaultOptions() {
|
|
81
81
|
return new Map(Object.entries({
|
|
82
|
+
multipleStatements: options_1.default.MULTIPLE_STATEMENTS || false,
|
|
83
|
+
enableKeepAlive: options_1.default.ENABLE_KEEP_ALIVE || false,
|
|
84
|
+
keepAliveInitialDelay: options_1.default.KEEP_ALIVE_DELAY || 0,
|
|
82
85
|
connectionLimit: Number(options_1.default.CONNECTION_LIMIT),
|
|
83
86
|
dateStrings: Boolean(options_1.default.DATE_STRINGS),
|
|
84
87
|
connectTimeout: Number(options_1.default.TIMEOUT),
|
|
85
88
|
waitForConnections: Boolean(options_1.default.WAIT_FOR_CONNECTIONS),
|
|
86
89
|
queueLimit: Number(options_1.default.QUEUE_LIMIT),
|
|
87
|
-
multipleStatements: true,
|
|
88
90
|
charset: String(options_1.default.CHARSET),
|
|
89
91
|
host: String(options_1.default.HOST),
|
|
90
|
-
port: Number.isNaN(Number(options_1.default.PORT))
|
|
91
|
-
? 3306
|
|
92
|
-
: Number(options_1.default.PORT),
|
|
92
|
+
port: Number.isNaN(Number(options_1.default.PORT)) ? 3306 : Number(options_1.default.PORT),
|
|
93
93
|
database: String(options_1.default.DATABASE),
|
|
94
94
|
user: String(options_1.default.USERNAME),
|
|
95
|
-
password: String(options_1.default.PASSWORD)
|
|
96
|
-
? String(options_1.default.PASSWORD)
|
|
97
|
-
: ''
|
|
95
|
+
password: String(options_1.default.PASSWORD) === '' ? '' : String(options_1.default.PASSWORD)
|
|
98
96
|
}));
|
|
99
97
|
}
|
|
100
98
|
_loadOptions() {
|
|
@@ -110,7 +108,7 @@ class PoolConnection {
|
|
|
110
108
|
"password" : "",
|
|
111
109
|
"connectionLimit" : "",
|
|
112
110
|
"dateStrings" : "",
|
|
113
|
-
"
|
|
111
|
+
"connectTimeout" : "",
|
|
114
112
|
"waitForConnections" : "",
|
|
115
113
|
"queueLimit" : "",
|
|
116
114
|
"charset" : ""
|
|
@@ -11,5 +11,8 @@ declare const _default: Readonly<{
|
|
|
11
11
|
CONNECTION_ERROR?: string | boolean | undefined;
|
|
12
12
|
WAIT_FOR_CONNECTIONS?: string | boolean | undefined;
|
|
13
13
|
DATE_STRINGS?: string | boolean | undefined;
|
|
14
|
+
KEEP_ALIVE_DELAY?: string | number | undefined;
|
|
15
|
+
ENABLE_KEEP_ALIVE?: string | boolean | undefined;
|
|
16
|
+
MULTIPLE_STATEMENTS?: string | boolean | undefined;
|
|
14
17
|
}>;
|
|
15
18
|
export default _default;
|
|
@@ -30,7 +30,10 @@ const env = {
|
|
|
30
30
|
CHARSET: process.env.DB_CHARSET || process.env.TSPACE_CHARSET || 'utf8mb4',
|
|
31
31
|
CONNECTION_ERROR: process.env.DB_CONNECTION_ERROR || process.env.TSPACE_CONNECTION_ERROR || true,
|
|
32
32
|
WAIT_FOR_CONNECTIONS: process.env.DB_WAIT_FOR_CONNECTIONS || process.env.TSPACE_WAIT_FOR_CONNECTIONS || true,
|
|
33
|
-
DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true
|
|
33
|
+
DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true,
|
|
34
|
+
KEEP_ALIVE_DELAY: process.env.DB_KEEP_ALIVE_DELAY || process.env.TSPACE_KEEP_ALIVE_DELAY || 0,
|
|
35
|
+
ENABLE_KEEP_ALIVE: process.env.DB_ENABLE_KEEP_ALIVE || process.env.TSPACE_ENABLE_KEEP_ALIVE || false,
|
|
36
|
+
MULTIPLE_STATEMENTS: process.env.MULTIPLE_STATEMENTS || process.env.TSPACE_MULTIPLE_STATEMENTS || false
|
|
34
37
|
};
|
|
35
38
|
for (const [key, value] of Object.entries(env)) {
|
|
36
39
|
if (value == null)
|
|
@@ -46,6 +46,7 @@ declare abstract class AbstractBuilder {
|
|
|
46
46
|
abstract whereNotSubQuery(column: string, subQuery: string): this;
|
|
47
47
|
abstract orWhereSubQuery(column: string, subQuery: string): this;
|
|
48
48
|
abstract whereBetween(column: string, arrayValue: Array<any>): this;
|
|
49
|
+
abstract whereNotBetween(column: string, arrayValue: Array<any>): this;
|
|
49
50
|
abstract having(condition: string): this;
|
|
50
51
|
abstract havingRaw(condition: string): this;
|
|
51
52
|
abstract join(pk: string, fk: string): this;
|
|
@@ -3,6 +3,8 @@ import { Connection, ConnectionOptions } from './Interface';
|
|
|
3
3
|
declare abstract class AbstractDB extends Builder {
|
|
4
4
|
abstract table(tableName: string): void;
|
|
5
5
|
abstract beginTransaction(): Promise<any>;
|
|
6
|
+
abstract makeObject(value: any): Record<string, any> | null;
|
|
7
|
+
abstract makeArray(value: any): Array<any>;
|
|
6
8
|
abstract generateUUID(): string;
|
|
7
9
|
abstract raw(sql: string): string;
|
|
8
10
|
abstract constants(constants?: string): string | {
|
|
@@ -182,6 +182,13 @@ declare class Builder extends AbstractBuilder {
|
|
|
182
182
|
* @return {this}
|
|
183
183
|
*/
|
|
184
184
|
whereBetween(column: string, array: Array<any>): this;
|
|
185
|
+
/**
|
|
186
|
+
* where not between using [value1, value2]
|
|
187
|
+
* @param {string} column
|
|
188
|
+
* @param {array} array
|
|
189
|
+
* @return {this}
|
|
190
|
+
*/
|
|
191
|
+
whereNotBetween(column: string, array: Array<any>): this;
|
|
185
192
|
/**
|
|
186
193
|
* where null using NULL
|
|
187
194
|
* @param {string} column
|
|
@@ -268,7 +268,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
268
268
|
this._queryWhereIsExists()
|
|
269
269
|
? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
|
|
270
270
|
: `${this.$constants('WHERE')}`,
|
|
271
|
-
`${this._bindTableAndColumnInQueryWhere(column)} = ${id}`,
|
|
271
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = ${this.$utils.escape(id)}`,
|
|
272
272
|
].join(' '));
|
|
273
273
|
return this;
|
|
274
274
|
}
|
|
@@ -404,7 +404,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
404
404
|
: `${this.$constants('WHERE')}`,
|
|
405
405
|
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
406
406
|
`${this.$constants('IN')}`,
|
|
407
|
-
`(${
|
|
407
|
+
`(${subQuery})`
|
|
408
408
|
].join(' '));
|
|
409
409
|
return this;
|
|
410
410
|
}
|
|
@@ -421,7 +421,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
421
421
|
: `${this.$constants('WHERE')}`,
|
|
422
422
|
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
423
423
|
`${this.$constants('NOT_IN')}`,
|
|
424
|
-
`(${
|
|
424
|
+
`(${subQuery})`
|
|
425
425
|
].join(' '));
|
|
426
426
|
return this;
|
|
427
427
|
}
|
|
@@ -438,7 +438,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
438
438
|
: `${this.$constants('WHERE')}`,
|
|
439
439
|
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
440
440
|
`${this.$constants('IN')}`,
|
|
441
|
-
`(${
|
|
441
|
+
`(${subQuery})`
|
|
442
442
|
].join(' '));
|
|
443
443
|
return this;
|
|
444
444
|
}
|
|
@@ -455,7 +455,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
455
455
|
: `${this.$constants('WHERE')}`,
|
|
456
456
|
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
457
457
|
`${this.$constants('NOT_IN')}`,
|
|
458
|
-
`(${
|
|
458
|
+
`(${subQuery})`
|
|
459
459
|
].join(' '));
|
|
460
460
|
return this;
|
|
461
461
|
}
|
|
@@ -476,7 +476,28 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
476
476
|
? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
|
|
477
477
|
: `${this.$constants('WHERE')}`,
|
|
478
478
|
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
|
|
479
|
-
|
|
479
|
+
`${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
|
|
480
|
+
].join(' '));
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* where not between using [value1, value2]
|
|
485
|
+
* @param {string} column
|
|
486
|
+
* @param {array} array
|
|
487
|
+
* @return {this}
|
|
488
|
+
*/
|
|
489
|
+
whereNotBetween(column, array) {
|
|
490
|
+
if (!Array.isArray(array))
|
|
491
|
+
throw new Error("Value is't array");
|
|
492
|
+
if (!array.length)
|
|
493
|
+
return this;
|
|
494
|
+
const [value1, value2] = array;
|
|
495
|
+
this.$state.set('WHERE', [
|
|
496
|
+
this._queryWhereIsExists()
|
|
497
|
+
? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
|
|
498
|
+
: `${this.$constants('WHERE')}`,
|
|
499
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_BETWEEN')}`,
|
|
500
|
+
`${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
|
|
480
501
|
].join(' '));
|
|
481
502
|
return this;
|
|
482
503
|
}
|
package/dist/lib/tspace/DB.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { AbstractDB } from './AbstractDB';
|
|
|
2
2
|
import { Connection, ConnectionOptions, ConnectionTransaction } from './Interface';
|
|
3
3
|
declare class DB extends AbstractDB {
|
|
4
4
|
constructor(table?: string);
|
|
5
|
-
union(a: string, b: string): Promise<any[]>;
|
|
6
5
|
/**
|
|
7
6
|
* Covert result to array
|
|
8
7
|
* @param {any} result table name
|
package/dist/lib/tspace/DB.js
CHANGED
|
@@ -32,15 +32,6 @@ class DB extends AbstractDB_1.AbstractDB {
|
|
|
32
32
|
this.table(table);
|
|
33
33
|
return new Proxy(this, ProxyHandler_1.proxyHandler);
|
|
34
34
|
}
|
|
35
|
-
union(a, b) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return yield this.queryStatement([
|
|
38
|
-
a,
|
|
39
|
-
'UNION',
|
|
40
|
-
b
|
|
41
|
-
].join(' '));
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
35
|
/**
|
|
45
36
|
* Covert result to array
|
|
46
37
|
* @param {any} result table name
|
package/dist/lib/tspace/Model.js
CHANGED
|
@@ -1803,10 +1803,6 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
1803
1803
|
return [];
|
|
1804
1804
|
const query = yield relation.query;
|
|
1805
1805
|
this._assertError(query == null, `Unknown callback query in [Relation : ${relation.name}]`);
|
|
1806
|
-
const relationIsHasOneOrBelongsTo = [
|
|
1807
|
-
this.$constants('RELATIONSHIP').hasOne,
|
|
1808
|
-
this.$constants('RELATIONSHIP').belongsTo
|
|
1809
|
-
].some(r => r === relation.relation);
|
|
1810
1806
|
const dataFromRelation = yield query
|
|
1811
1807
|
.bind(this.$pool.get())
|
|
1812
1808
|
.whereIn(foreignKey, dataPerentId)
|
|
@@ -2265,7 +2261,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2265
2261
|
_insertNotExistsModel() {
|
|
2266
2262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2267
2263
|
this._assertError(!this.$state.get('WHERE'), "Can't insert [insertNotExists] without where condition");
|
|
2268
|
-
const clone = new Model().copyModel(this, { where: true });
|
|
2264
|
+
const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
|
|
2269
2265
|
const check = (yield clone.exists()) || false;
|
|
2270
2266
|
if (check)
|
|
2271
2267
|
return null;
|
|
@@ -2275,7 +2271,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2275
2271
|
});
|
|
2276
2272
|
if (!result)
|
|
2277
2273
|
return null;
|
|
2278
|
-
return yield new Model().copyModel(this).where('id', id).first();
|
|
2274
|
+
return yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
|
|
2279
2275
|
});
|
|
2280
2276
|
}
|
|
2281
2277
|
_insertModel() {
|
|
@@ -2290,6 +2286,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2290
2286
|
return null;
|
|
2291
2287
|
return yield new Model().copyModel(this)
|
|
2292
2288
|
.where('id', id)
|
|
2289
|
+
.bind(this.$pool.get())
|
|
2293
2290
|
.first();
|
|
2294
2291
|
});
|
|
2295
2292
|
}
|
|
@@ -2304,7 +2301,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2304
2301
|
if (!result)
|
|
2305
2302
|
return null;
|
|
2306
2303
|
const arrayId = [...Array(result)].map((_, i) => i + id);
|
|
2307
|
-
const data = new Model().copyModel(this).whereIn('id', arrayId).get();
|
|
2304
|
+
const data = new Model().copyModel(this).bind(this.$pool.get()).whereIn('id', arrayId).get();
|
|
2308
2305
|
const resultData = data || [];
|
|
2309
2306
|
this.$state.set('RESULT', resultData);
|
|
2310
2307
|
return resultData;
|
|
@@ -2313,7 +2310,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2313
2310
|
_updateOrInsertModel() {
|
|
2314
2311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2315
2312
|
this._assertError(!this.$state.get('WHERE'), "Can not update or insert [updateOrInsert] without where condition");
|
|
2316
|
-
const clone = new Model().copyModel(this, { where: true });
|
|
2313
|
+
const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
|
|
2317
2314
|
const check = (yield clone.exists()) || false;
|
|
2318
2315
|
switch (check) {
|
|
2319
2316
|
case false: {
|
|
@@ -2325,7 +2322,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2325
2322
|
return null;
|
|
2326
2323
|
if (!result)
|
|
2327
2324
|
return null;
|
|
2328
|
-
const data = yield new Model().copyModel(this).where('id', id).first();
|
|
2325
|
+
const data = yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
|
|
2329
2326
|
const resultData = data == null
|
|
2330
2327
|
? null
|
|
2331
2328
|
: Object.assign(Object.assign({}, data), { action_status: 'insert' });
|
|
@@ -2340,7 +2337,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2340
2337
|
return null;
|
|
2341
2338
|
if (!result)
|
|
2342
2339
|
return null;
|
|
2343
|
-
const data = yield new Model().copyModel(this, { where: true }).get();
|
|
2340
|
+
const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
|
|
2344
2341
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2345
2342
|
for (const v of data)
|
|
2346
2343
|
v.action_status = 'update';
|
|
@@ -2357,7 +2354,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2357
2354
|
_insertOrSelectModel() {
|
|
2358
2355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2359
2356
|
this._assertError(!this.$state.get('WHERE'), "Can not update or insert [updateOrInsert] without where condition");
|
|
2360
|
-
const clone = new Model().copyModel(this, { where: true });
|
|
2357
|
+
const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
|
|
2361
2358
|
const check = (yield clone.exists()) || false;
|
|
2362
2359
|
switch (check) {
|
|
2363
2360
|
case false: {
|
|
@@ -2369,7 +2366,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2369
2366
|
return null;
|
|
2370
2367
|
if (!result)
|
|
2371
2368
|
return null;
|
|
2372
|
-
const data = yield new Model().copyModel(this).where('id', id).first();
|
|
2369
|
+
const data = yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
|
|
2373
2370
|
const resultData = data == null
|
|
2374
2371
|
? null
|
|
2375
2372
|
: Object.assign(Object.assign({}, data), { action_status: 'insert' });
|
|
@@ -2379,7 +2376,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2379
2376
|
case true: {
|
|
2380
2377
|
if (this.$state.get('VOID'))
|
|
2381
2378
|
return null;
|
|
2382
|
-
const data = yield new Model().copyModel(this, { where: true }).get();
|
|
2379
|
+
const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
|
|
2383
2380
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2384
2381
|
for (const v of data)
|
|
2385
2382
|
v.action_status = 'select';
|
|
@@ -2402,7 +2399,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
2402
2399
|
return null;
|
|
2403
2400
|
if (result == null || !result)
|
|
2404
2401
|
return null;
|
|
2405
|
-
const data = yield new Model().copyModel(this, { where: true }).get();
|
|
2402
|
+
const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
|
|
2406
2403
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2407
2404
|
this.$state.set('RESULT', data);
|
|
2408
2405
|
return data || [];
|