tspace-mysql 1.3.4 → 1.3.6
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 +181 -30
- package/dist/cli/generate/model.js +1 -1
- package/dist/lib/connection/index.d.ts +2 -0
- package/dist/lib/connection/index.js +82 -31
- package/dist/lib/connection/options.d.ts +5 -4
- package/dist/lib/connection/options.js +5 -3
- package/dist/lib/constants/index.js +6 -1
- package/dist/lib/tspace/AbstractBuilder.d.ts +3 -6
- package/dist/lib/tspace/AbstractBuilder.js +3 -6
- package/dist/lib/tspace/AbstractModel.d.ts +2 -0
- package/dist/lib/tspace/Builder.d.ts +52 -16
- package/dist/lib/tspace/Builder.js +278 -171
- package/dist/lib/tspace/DB.d.ts +4 -0
- package/dist/lib/tspace/DB.js +9 -24
- package/dist/lib/tspace/Model.d.ts +338 -43
- package/dist/lib/tspace/Model.js +535 -221
- package/dist/lib/tspace/Schema.d.ts +8 -3
- package/dist/lib/tspace/Schema.js +17 -0
- package/dist/lib/tspace/StateHandler.d.ts +12 -0
- package/dist/lib/tspace/StateHandler.js +55 -0
- package/package.json +2 -1
|
@@ -31,6 +31,7 @@ const utils_1 = require("../utils");
|
|
|
31
31
|
const constants_1 = require("../constants");
|
|
32
32
|
const DB_1 = require("./DB");
|
|
33
33
|
const connection_1 = require("../connection");
|
|
34
|
+
const StateHandler_1 = require("./StateHandler");
|
|
34
35
|
class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
35
36
|
constructor() {
|
|
36
37
|
super();
|
|
@@ -130,8 +131,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
130
131
|
* @return {this} this
|
|
131
132
|
*/
|
|
132
133
|
when(condition, callback) {
|
|
133
|
-
if (condition)
|
|
134
|
-
|
|
134
|
+
if (!condition)
|
|
135
|
+
return this;
|
|
136
|
+
const cb = callback(this);
|
|
137
|
+
if (cb instanceof Promise)
|
|
138
|
+
throw new Error('"when" is not supported a Promise');
|
|
135
139
|
return this;
|
|
136
140
|
}
|
|
137
141
|
/**
|
|
@@ -227,21 +231,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
227
231
|
].join(' '));
|
|
228
232
|
return this;
|
|
229
233
|
}
|
|
230
|
-
/**
|
|
231
|
-
*
|
|
232
|
-
* @param {string} tableAndLocalKey
|
|
233
|
-
* @param {string?} tableAndForeignKey
|
|
234
|
-
* @return {this}
|
|
235
|
-
*/
|
|
236
|
-
whereReference(tableAndLocalKey, tableAndForeignKey) {
|
|
237
|
-
this.$state.set('WHERE', [
|
|
238
|
-
this._queryWhereIsExists()
|
|
239
|
-
? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
|
|
240
|
-
: `${this.$constants('WHERE')}`,
|
|
241
|
-
`${tableAndLocalKey} = ${tableAndForeignKey}`
|
|
242
|
-
].join(' '));
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
234
|
/**
|
|
246
235
|
*
|
|
247
236
|
* where exists
|
|
@@ -480,6 +469,27 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
480
469
|
].join(' '));
|
|
481
470
|
return this;
|
|
482
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* where between using [value1, value2]
|
|
474
|
+
* @param {string} column
|
|
475
|
+
* @param {array} array
|
|
476
|
+
* @return {this}
|
|
477
|
+
*/
|
|
478
|
+
orWhereBetween(column, array) {
|
|
479
|
+
if (!Array.isArray(array))
|
|
480
|
+
throw new Error("Value is't array");
|
|
481
|
+
if (!array.length)
|
|
482
|
+
return this;
|
|
483
|
+
const [value1, value2] = array;
|
|
484
|
+
this.$state.set('WHERE', [
|
|
485
|
+
this._queryWhereIsExists()
|
|
486
|
+
? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
|
|
487
|
+
: `${this.$constants('WHERE')}`,
|
|
488
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
|
|
489
|
+
`${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
|
|
490
|
+
].join(' '));
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
483
493
|
/**
|
|
484
494
|
* where not between using [value1, value2]
|
|
485
495
|
* @param {string} column
|
|
@@ -516,6 +526,21 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
516
526
|
].join(' '));
|
|
517
527
|
return this;
|
|
518
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* where null using NULL
|
|
531
|
+
* @param {string} column
|
|
532
|
+
* @return {this}
|
|
533
|
+
*/
|
|
534
|
+
orWhereNull(column) {
|
|
535
|
+
this.$state.set('WHERE', [
|
|
536
|
+
this._queryWhereIsExists()
|
|
537
|
+
? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
|
|
538
|
+
: `${this.$constants('WHERE')}`,
|
|
539
|
+
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
540
|
+
`${this.$constants('IS_NULL')}`
|
|
541
|
+
].join(' '));
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
519
544
|
/**
|
|
520
545
|
* where not null using NULL
|
|
521
546
|
* @param {string} column
|
|
@@ -531,6 +556,21 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
531
556
|
].join(' '));
|
|
532
557
|
return this;
|
|
533
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* where not null using NULL
|
|
561
|
+
* @param {string} column
|
|
562
|
+
* @return {this}
|
|
563
|
+
*/
|
|
564
|
+
orWhereNotNull(column) {
|
|
565
|
+
this.$state.set('WHERE', [
|
|
566
|
+
this._queryWhereIsExists()
|
|
567
|
+
? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
|
|
568
|
+
: `${this.$constants('WHERE')}`,
|
|
569
|
+
`${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
570
|
+
`${this.$constants('IS_NOT_NULL')}`
|
|
571
|
+
].join(' '));
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
534
574
|
/**
|
|
535
575
|
* where sensitive (uppercase, lowercase)
|
|
536
576
|
* @param {string} column
|
|
@@ -562,6 +602,27 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
562
602
|
whereStrict(column, operator, value) {
|
|
563
603
|
return this.whereSensitive(column, operator, value);
|
|
564
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* or where sensitive (uppercase, lowercase)
|
|
607
|
+
* @param {string} column
|
|
608
|
+
* @param {string?} operator = < > != !< !>
|
|
609
|
+
* @param {any?} value
|
|
610
|
+
* @return {this}
|
|
611
|
+
*/
|
|
612
|
+
orWhereSensitive(column, operator, value) {
|
|
613
|
+
[value, operator] = this._valueAndOperator(value, operator, arguments.length === 2);
|
|
614
|
+
value = this.$utils.escape(value);
|
|
615
|
+
value = this._valueTrueFalse(value);
|
|
616
|
+
this.$state.set('WHERE', [
|
|
617
|
+
this._queryWhereIsExists()
|
|
618
|
+
? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
|
|
619
|
+
: `${this.$constants('WHERE')}`,
|
|
620
|
+
`BINARY ${this._bindTableAndColumnInQueryWhere(column)}`,
|
|
621
|
+
`${operator}`,
|
|
622
|
+
`${this._checkValueHasRaw(this.$utils.escape(value))}`
|
|
623
|
+
].join(' '));
|
|
624
|
+
return this;
|
|
625
|
+
}
|
|
565
626
|
/**
|
|
566
627
|
* where group query
|
|
567
628
|
* @param {function} callback callback query
|
|
@@ -571,9 +632,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
571
632
|
var _a;
|
|
572
633
|
const db = new DB_1.DB((_a = this.$state.get('TABLE_NAME')) === null || _a === void 0 ? void 0 : _a.replace(/`/g, ''));
|
|
573
634
|
const repository = callback(db);
|
|
574
|
-
if (
|
|
575
|
-
throw new Error(
|
|
576
|
-
|
|
635
|
+
if (repository instanceof Promise)
|
|
636
|
+
throw new Error('"whereQuery" is not supported a Promise');
|
|
637
|
+
if (!(repository instanceof DB_1.DB))
|
|
638
|
+
throw new Error(`Unknown callback query: '[${repository}]'`);
|
|
577
639
|
const where = (repository === null || repository === void 0 ? void 0 : repository.$state.get('WHERE')) || '';
|
|
578
640
|
if (where === '')
|
|
579
641
|
return this;
|
|
@@ -586,6 +648,39 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
586
648
|
].join(' '));
|
|
587
649
|
return this;
|
|
588
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* where group query
|
|
653
|
+
* @param {function} callback callback query
|
|
654
|
+
* @return {this}
|
|
655
|
+
*/
|
|
656
|
+
whereGroup(callback) {
|
|
657
|
+
return this.whereQuery(callback);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* where group query
|
|
661
|
+
* @param {function} callback callback query
|
|
662
|
+
* @return {this}
|
|
663
|
+
*/
|
|
664
|
+
orWhereQuery(callback) {
|
|
665
|
+
var _a;
|
|
666
|
+
const db = new DB_1.DB((_a = this.$state.get('TABLE_NAME')) === null || _a === void 0 ? void 0 : _a.replace(/`/g, ''));
|
|
667
|
+
const repository = callback(db);
|
|
668
|
+
if (repository instanceof Promise)
|
|
669
|
+
throw new Error('"whereQuery" is not supported a Promise');
|
|
670
|
+
if (!(repository instanceof DB_1.DB))
|
|
671
|
+
throw new Error(`Unknown callback query: '[${repository}]'`);
|
|
672
|
+
const where = (repository === null || repository === void 0 ? void 0 : repository.$state.get('WHERE')) || '';
|
|
673
|
+
if (where === '')
|
|
674
|
+
return this;
|
|
675
|
+
const query = where.replace('WHERE', '');
|
|
676
|
+
this.$state.set('WHERE', [
|
|
677
|
+
this._queryWhereIsExists()
|
|
678
|
+
? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
|
|
679
|
+
: `${this.$constants('WHERE')}`,
|
|
680
|
+
`(${query})`
|
|
681
|
+
].join(' '));
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
589
684
|
/**
|
|
590
685
|
* select by cases
|
|
591
686
|
* @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}]
|
|
@@ -1248,8 +1343,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1248
1343
|
].join(' ');
|
|
1249
1344
|
const rawColumns = yield this.queryStatement(sql);
|
|
1250
1345
|
const columns = rawColumns.map((column) => column.Field);
|
|
1251
|
-
const removeExcept = columns.filter((column) => !this.$state.get('EXCEPT').includes(column));
|
|
1252
|
-
return removeExcept
|
|
1346
|
+
const removeExcept = columns.filter((column) => !String(this.$state.get('EXCEPT')).includes(column));
|
|
1347
|
+
return removeExcept;
|
|
1253
1348
|
});
|
|
1254
1349
|
}
|
|
1255
1350
|
/**
|
|
@@ -1339,7 +1434,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1339
1434
|
* @return {promise<Pagination>}
|
|
1340
1435
|
*/
|
|
1341
1436
|
pagination(paginationOptions) {
|
|
1342
|
-
var _a, _b;
|
|
1437
|
+
var _a, _b, _c;
|
|
1343
1438
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1344
1439
|
let limit = 15;
|
|
1345
1440
|
let page = 1;
|
|
@@ -1352,7 +1447,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1352
1447
|
const prevPage = currentPage - 1 === 0 ? 1 : currentPage - 1;
|
|
1353
1448
|
const offset = (page - 1) * limit;
|
|
1354
1449
|
let sql = this._buildQuery();
|
|
1355
|
-
sql = sql.replace(this.$state.get('LIMIT'), `${limit} ${this.$constants('OFFSET')} ${offset}`);
|
|
1356
1450
|
if (!sql.includes(this.$constants('LIMIT'))) {
|
|
1357
1451
|
sql = [
|
|
1358
1452
|
`${sql}`,
|
|
@@ -1361,6 +1455,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1361
1455
|
`${this.$constants('OFFSET')} ${offset}`
|
|
1362
1456
|
].join(' ');
|
|
1363
1457
|
}
|
|
1458
|
+
else {
|
|
1459
|
+
sql = sql.replace(this.$state.get('LIMIT'), `${this.$constants('LIMIT')} ${limit} ${this.$constants('OFFSET')} ${offset}`);
|
|
1460
|
+
}
|
|
1364
1461
|
const result = yield this.queryStatement(sql);
|
|
1365
1462
|
if ((_a = this.$state.get('HIDDEN')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1366
1463
|
this._hiddenColumn(result);
|
|
@@ -1382,17 +1479,22 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1382
1479
|
`${this.$constants('COUNT')}(*)`,
|
|
1383
1480
|
`${this.$constants('AS')} total`
|
|
1384
1481
|
].join(' '));
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1482
|
+
const sqlTotal = [
|
|
1483
|
+
this.$state.get('SELECT'),
|
|
1484
|
+
this.$state.get('FROM'),
|
|
1485
|
+
this.$state.get('TABLE_NAME'),
|
|
1486
|
+
this.$state.get('WHERE'),
|
|
1487
|
+
].join(' ');
|
|
1488
|
+
const count = yield this.queryStatement(sqlTotal);
|
|
1489
|
+
const total = ((_b = count === null || count === void 0 ? void 0 : count.shift()) === null || _b === void 0 ? void 0 : _b.total) || 0;
|
|
1388
1490
|
let lastPage = Math.ceil(total / limit) || 0;
|
|
1389
1491
|
lastPage = lastPage > 1 ? lastPage : 1;
|
|
1390
|
-
const totalPage = (
|
|
1492
|
+
const totalPage = (_c = result === null || result === void 0 ? void 0 : result.length) !== null && _c !== void 0 ? _c : 0;
|
|
1391
1493
|
return {
|
|
1392
1494
|
meta: {
|
|
1495
|
+
total: total,
|
|
1496
|
+
limit: limit,
|
|
1393
1497
|
total_page: totalPage,
|
|
1394
|
-
total,
|
|
1395
|
-
limit,
|
|
1396
1498
|
current_page: currentPage,
|
|
1397
1499
|
last_page: lastPage,
|
|
1398
1500
|
next_page: nextPage,
|
|
@@ -1430,7 +1532,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1430
1532
|
var _a, _b;
|
|
1431
1533
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1432
1534
|
if ((_a = this.$state.get('EXCEPT')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1433
|
-
this.select(yield this.exceptColumns());
|
|
1535
|
+
this.select(...yield this.exceptColumns());
|
|
1434
1536
|
this.limit(1);
|
|
1435
1537
|
let sql = this._buildQuery();
|
|
1436
1538
|
const result = yield this.queryStatement(sql);
|
|
@@ -1452,7 +1554,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1452
1554
|
const hook = this.$state.get('HOOK');
|
|
1453
1555
|
for (let i in hook)
|
|
1454
1556
|
yield hook[i](r);
|
|
1455
|
-
return r;
|
|
1557
|
+
return this.resultHandler(r);
|
|
1456
1558
|
});
|
|
1457
1559
|
}
|
|
1458
1560
|
/**
|
|
@@ -1474,7 +1576,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1474
1576
|
var _a, _b;
|
|
1475
1577
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1476
1578
|
if ((_a = this.$state.get('EXCEPT')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1477
|
-
this.select(yield this.exceptColumns());
|
|
1579
|
+
this.select(...yield this.exceptColumns());
|
|
1478
1580
|
let sql = this._buildQuery();
|
|
1479
1581
|
if (!sql.includes(this.$constants('LIMIT')))
|
|
1480
1582
|
sql = `${sql} ${this.$constants('LIMIT')} 1`;
|
|
@@ -1499,7 +1601,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1499
1601
|
const hook = this.$state.get('HOOK');
|
|
1500
1602
|
for (let i in hook)
|
|
1501
1603
|
yield hook[i](data);
|
|
1502
|
-
return data;
|
|
1604
|
+
return this.resultHandler(data);
|
|
1503
1605
|
}
|
|
1504
1606
|
const data = (result === null || result === void 0 ? void 0 : result.shift()) || null;
|
|
1505
1607
|
if (data == null) {
|
|
@@ -1511,7 +1613,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1511
1613
|
const hook = this.$state.get('HOOK');
|
|
1512
1614
|
for (let i in hook)
|
|
1513
1615
|
yield hook[i](data);
|
|
1514
|
-
return data;
|
|
1616
|
+
return this.resultHandler(data);
|
|
1515
1617
|
});
|
|
1516
1618
|
}
|
|
1517
1619
|
/**
|
|
@@ -1533,7 +1635,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1533
1635
|
var _a, _b;
|
|
1534
1636
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1535
1637
|
if ((_a = this.$state.get('EXCEPT')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1536
|
-
this.select(yield this.exceptColumns());
|
|
1638
|
+
this.select(...yield this.exceptColumns());
|
|
1537
1639
|
const sql = this._buildQuery();
|
|
1538
1640
|
const result = yield this.queryStatement(sql);
|
|
1539
1641
|
if ((_b = this.$state.get('HIDDEN')) === null || _b === void 0 ? void 0 : _b.length)
|
|
@@ -1549,7 +1651,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1549
1651
|
const hook = this.$state.get('HOOK');
|
|
1550
1652
|
for (let i in hook)
|
|
1551
1653
|
yield hook[i](data || []);
|
|
1552
|
-
return data || [];
|
|
1654
|
+
return this.resultHandler(data || []);
|
|
1553
1655
|
}
|
|
1554
1656
|
if (this.$state.get('PLUCK')) {
|
|
1555
1657
|
const pluck = this.$state.get('PLUCK');
|
|
@@ -1560,12 +1662,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1560
1662
|
const hook = this.$state.get('HOOK');
|
|
1561
1663
|
for (let i in hook)
|
|
1562
1664
|
yield hook[i](newData || []);
|
|
1563
|
-
return newData || [];
|
|
1665
|
+
return this.resultHandler(newData || []);
|
|
1564
1666
|
}
|
|
1565
1667
|
const hook = this.$state.get('HOOK');
|
|
1566
1668
|
for (let i in hook)
|
|
1567
1669
|
yield hook[i](result || []);
|
|
1568
|
-
return result || [];
|
|
1670
|
+
return this.resultHandler(result || []);
|
|
1569
1671
|
});
|
|
1570
1672
|
}
|
|
1571
1673
|
/**
|
|
@@ -1587,12 +1689,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1587
1689
|
var _a, _b;
|
|
1588
1690
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1589
1691
|
if ((_a = this.$state.get('EXCEPT')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1590
|
-
this.select(yield this.exceptColumns());
|
|
1692
|
+
this.select(...yield this.exceptColumns());
|
|
1591
1693
|
const sql = this._buildQuery();
|
|
1592
1694
|
const result = yield this.queryStatement(sql);
|
|
1593
1695
|
if ((_b = this.$state.get('HIDDEN')) === null || _b === void 0 ? void 0 : _b.length)
|
|
1594
1696
|
this._hiddenColumn(result);
|
|
1595
|
-
return JSON.stringify(result);
|
|
1697
|
+
return this.resultHandler(JSON.stringify(result));
|
|
1596
1698
|
});
|
|
1597
1699
|
}
|
|
1598
1700
|
/**
|
|
@@ -1607,7 +1709,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1607
1709
|
const sql = this._buildQuery();
|
|
1608
1710
|
const result = yield this.queryStatement(sql);
|
|
1609
1711
|
const toArray = result.map((data) => data[column]);
|
|
1610
|
-
return toArray;
|
|
1712
|
+
return this.resultHandler(toArray);
|
|
1611
1713
|
});
|
|
1612
1714
|
}
|
|
1613
1715
|
/**
|
|
@@ -1622,11 +1724,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1622
1724
|
this.$state.set('SELECT', [
|
|
1623
1725
|
`${this.$constants('SELECT')}`,
|
|
1624
1726
|
`${this.$constants('COUNT')}(${column})`,
|
|
1625
|
-
`${this.$constants('AS')} total
|
|
1727
|
+
`${this.$constants('AS')} \`total\``
|
|
1626
1728
|
].join(' '));
|
|
1627
1729
|
const sql = this._buildQuery();
|
|
1628
1730
|
const result = yield this.queryStatement(sql);
|
|
1629
|
-
|
|
1731
|
+
this.$state.resetState();
|
|
1732
|
+
return Number(this.resultHandler(((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.total) || 0));
|
|
1630
1733
|
});
|
|
1631
1734
|
}
|
|
1632
1735
|
/**
|
|
@@ -1644,9 +1747,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1644
1747
|
`${this.$state.get('FROM')}`,
|
|
1645
1748
|
`${this.$state.get('TABLE_NAME')}`,
|
|
1646
1749
|
`${this.$state.get('WHERE')}`,
|
|
1647
|
-
`${this.$constants('LIMIT')} 1) ${this.$constants('AS')}
|
|
1750
|
+
`${this.$constants('LIMIT')} 1) ${this.$constants('AS')} \`exists\``
|
|
1648
1751
|
].join(' '));
|
|
1649
|
-
return !!((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.exists) || false;
|
|
1752
|
+
return Boolean(this.resultHandler(!!((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.exists) || false));
|
|
1650
1753
|
});
|
|
1651
1754
|
}
|
|
1652
1755
|
/**
|
|
@@ -1661,11 +1764,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1661
1764
|
this.$state.set('SELECT', [
|
|
1662
1765
|
`${this.$constants('SELECT')}`,
|
|
1663
1766
|
`${this.$constants('AVG')}(${column})`,
|
|
1664
|
-
`${this.$constants('AS')} avg
|
|
1767
|
+
`${this.$constants('AS')} \`avg\``
|
|
1665
1768
|
].join(' '));
|
|
1666
1769
|
const sql = this._buildQuery();
|
|
1667
1770
|
const result = yield this.queryStatement(sql);
|
|
1668
|
-
return ((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.avg) || 0;
|
|
1771
|
+
return Number(this.resultHandler(((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.avg) || 0));
|
|
1669
1772
|
});
|
|
1670
1773
|
}
|
|
1671
1774
|
/**
|
|
@@ -1677,10 +1780,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1677
1780
|
sum(column = 'id') {
|
|
1678
1781
|
var _a;
|
|
1679
1782
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1680
|
-
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('SUM')}(${column}) ${this.$constants('AS')} sum
|
|
1783
|
+
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('SUM')}(${column}) ${this.$constants('AS')} \`sum\``);
|
|
1681
1784
|
const sql = this._buildQuery();
|
|
1682
1785
|
const result = yield this.queryStatement(sql);
|
|
1683
|
-
return ((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.sum) || 0;
|
|
1786
|
+
return Number(this.resultHandler(((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.sum) || 0));
|
|
1684
1787
|
});
|
|
1685
1788
|
}
|
|
1686
1789
|
/**
|
|
@@ -1692,10 +1795,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1692
1795
|
max(column = 'id') {
|
|
1693
1796
|
var _a;
|
|
1694
1797
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1695
|
-
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MAX')}(${column}) ${this.$constants('AS')} max
|
|
1798
|
+
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MAX')}(${column}) ${this.$constants('AS')} \`max\``);
|
|
1696
1799
|
const sql = this._buildQuery();
|
|
1697
1800
|
const result = yield this.queryStatement(sql);
|
|
1698
|
-
return ((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.max) || 0;
|
|
1801
|
+
return Number(this.resultHandler(((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.max) || 0));
|
|
1699
1802
|
});
|
|
1700
1803
|
}
|
|
1701
1804
|
/**
|
|
@@ -1707,10 +1810,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1707
1810
|
min(column = 'id') {
|
|
1708
1811
|
var _a;
|
|
1709
1812
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1710
|
-
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MIN')}(${column}) ${this.$constants('AS')} min
|
|
1813
|
+
this.$state.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MIN')}(${column}) ${this.$constants('AS')} \`min\``);
|
|
1711
1814
|
const sql = this._buildQuery();
|
|
1712
1815
|
const result = yield this.queryStatement(sql);
|
|
1713
|
-
return ((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.min) || 0;
|
|
1816
|
+
return Number(this.resultHandler(((_a = result === null || result === void 0 ? void 0 : result.shift()) === null || _a === void 0 ? void 0 : _a.min) || 0));
|
|
1714
1817
|
});
|
|
1715
1818
|
}
|
|
1716
1819
|
/**
|
|
@@ -1732,8 +1835,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1732
1835
|
].join(' '));
|
|
1733
1836
|
const result = yield this.actionStatement({ sql: this.$state.get('DELETE') });
|
|
1734
1837
|
if (result)
|
|
1735
|
-
return (_a = !!result) !== null && _a !== void 0 ? _a : false;
|
|
1736
|
-
return false;
|
|
1838
|
+
return Boolean(this.resultHandler((_a = !!result) !== null && _a !== void 0 ? _a : false));
|
|
1839
|
+
return Boolean(this.resultHandler(false));
|
|
1737
1840
|
});
|
|
1738
1841
|
}
|
|
1739
1842
|
/**
|
|
@@ -1742,7 +1845,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1742
1845
|
* @return {promise<boolean>}
|
|
1743
1846
|
*/
|
|
1744
1847
|
forceDelete() {
|
|
1745
|
-
var _a;
|
|
1848
|
+
var _a, _b;
|
|
1746
1849
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1747
1850
|
this.$state.set('DELETE', [
|
|
1748
1851
|
`${this.$constants('DELETE')}`,
|
|
@@ -1752,8 +1855,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1752
1855
|
].join(' '));
|
|
1753
1856
|
const result = yield this.actionStatement({ sql: this.$state.get('DELETE') });
|
|
1754
1857
|
if (result)
|
|
1755
|
-
return (_a = !!result) !== null && _a !== void 0 ? _a : false;
|
|
1756
|
-
return false;
|
|
1858
|
+
return Boolean(this.resultHandler((_a = !!result) !== null && _a !== void 0 ? _a : false));
|
|
1859
|
+
return Boolean(this.resultHandler((_b = !!result) !== null && _b !== void 0 ? _b : false));
|
|
1757
1860
|
});
|
|
1758
1861
|
}
|
|
1759
1862
|
/**
|
|
@@ -1796,7 +1899,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1796
1899
|
data: newData
|
|
1797
1900
|
});
|
|
1798
1901
|
});
|
|
1799
|
-
return resultData;
|
|
1902
|
+
return this.resultHandler(!resultData);
|
|
1800
1903
|
});
|
|
1801
1904
|
}
|
|
1802
1905
|
/**
|
|
@@ -1883,8 +1986,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1883
1986
|
`${this.$constants('FROM')}`,
|
|
1884
1987
|
`\`${table.replace(/\`/g, '')}\``
|
|
1885
1988
|
].join(' ');
|
|
1886
|
-
const
|
|
1887
|
-
|
|
1989
|
+
const raws = yield this.queryStatement(sql);
|
|
1990
|
+
return raws.map((r) => {
|
|
1888
1991
|
const schema = [];
|
|
1889
1992
|
schema.push(`${r.Field}`);
|
|
1890
1993
|
schema.push(`${r.Type}`);
|
|
@@ -1908,7 +2011,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1908
2011
|
}
|
|
1909
2012
|
return schema.join(' ');
|
|
1910
2013
|
});
|
|
1911
|
-
return schemas;
|
|
1912
2014
|
});
|
|
1913
2015
|
}
|
|
1914
2016
|
/**
|
|
@@ -2134,9 +2236,30 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2134
2236
|
return true;
|
|
2135
2237
|
});
|
|
2136
2238
|
}
|
|
2239
|
+
resultHandler(data) {
|
|
2240
|
+
this.$state.set('RESULT', data);
|
|
2241
|
+
this.$state.resetState();
|
|
2242
|
+
this.$logger.reset();
|
|
2243
|
+
return data;
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
*
|
|
2247
|
+
* @param {string} tableAndLocalKey
|
|
2248
|
+
* @param {string?} tableAndForeignKey
|
|
2249
|
+
* @return {this}
|
|
2250
|
+
*/
|
|
2251
|
+
whereReference(tableAndLocalKey, tableAndForeignKey) {
|
|
2252
|
+
this.$state.set('WHERE', [
|
|
2253
|
+
this._queryWhereIsExists()
|
|
2254
|
+
? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
|
|
2255
|
+
: `${this.$constants('WHERE')}`,
|
|
2256
|
+
`${tableAndLocalKey} = ${tableAndForeignKey}`
|
|
2257
|
+
].join(' '));
|
|
2258
|
+
return this;
|
|
2259
|
+
}
|
|
2137
2260
|
_queryWhereIsExists() {
|
|
2138
2261
|
var _a;
|
|
2139
|
-
return ((_a = this.$state.get('WHERE')) === null || _a === void 0 ? void 0 : _a.includes(this.$constants('WHERE'))) || false;
|
|
2262
|
+
return ((_a = String(this.$state.get('WHERE'))) === null || _a === void 0 ? void 0 : _a.includes(this.$constants('WHERE'))) || false;
|
|
2140
2263
|
}
|
|
2141
2264
|
_bindTableAndColumnInQueryWhere(column) {
|
|
2142
2265
|
return `${this.$state.get('TABLE_NAME')}.\`${column}\``;
|
|
@@ -2163,21 +2286,18 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2163
2286
|
sql: this.$state.get('INSERT'),
|
|
2164
2287
|
returnId: true
|
|
2165
2288
|
});
|
|
2166
|
-
if (this.$state.get('VOID'))
|
|
2167
|
-
return null;
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
return (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
2177
|
-
}
|
|
2178
|
-
return null;
|
|
2289
|
+
if (this.$state.get('VOID') || !result)
|
|
2290
|
+
return this.resultHandler(null);
|
|
2291
|
+
const sql = [
|
|
2292
|
+
`${this.$state.get('SELECT')}`,
|
|
2293
|
+
`${this.$state.get('FROM')}`,
|
|
2294
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2295
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
2296
|
+
].join(' ');
|
|
2297
|
+
const data = yield this.queryStatement(sql);
|
|
2298
|
+
return this.resultHandler((data === null || data === void 0 ? void 0 : data.shift()) || null);
|
|
2179
2299
|
}
|
|
2180
|
-
default: return null;
|
|
2300
|
+
default: return this.resultHandler(null);
|
|
2181
2301
|
}
|
|
2182
2302
|
});
|
|
2183
2303
|
}
|
|
@@ -2207,21 +2327,18 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2207
2327
|
sql: this.$state.get('INSERT'),
|
|
2208
2328
|
returnId: true
|
|
2209
2329
|
});
|
|
2210
|
-
if (this.$state.get('VOID'))
|
|
2211
|
-
return null;
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
return result;
|
|
2223
|
-
}
|
|
2224
|
-
return null;
|
|
2330
|
+
if (this.$state.get('VOID') || !result)
|
|
2331
|
+
return this.resultHandler(null);
|
|
2332
|
+
const sql = [
|
|
2333
|
+
`${this.$state.get('SELECT')}`,
|
|
2334
|
+
`${this.$state.get('FROM')}`,
|
|
2335
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2336
|
+
`${this.$constants('WHERE')} ${this.$state.get('TABLE_NAME')}.\`id\` = ${id}`
|
|
2337
|
+
].join(' ');
|
|
2338
|
+
const data = yield this.queryStatement(sql);
|
|
2339
|
+
const resultData = (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
2340
|
+
this.$state.set('RESULT', resultData);
|
|
2341
|
+
return this.resultHandler(resultData);
|
|
2225
2342
|
});
|
|
2226
2343
|
}
|
|
2227
2344
|
_checkValueHasRaw(value) {
|
|
@@ -2235,23 +2352,19 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2235
2352
|
sql: this.$state.get('INSERT'),
|
|
2236
2353
|
returnId: true
|
|
2237
2354
|
});
|
|
2238
|
-
if (this.$state.get('VOID'))
|
|
2239
|
-
return null;
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
this.$state.set('RESULT', resultData);
|
|
2252
|
-
return resultData;
|
|
2253
|
-
}
|
|
2254
|
-
return null;
|
|
2355
|
+
if (this.$state.get('VOID') || !result)
|
|
2356
|
+
return this.resultHandler(null);
|
|
2357
|
+
const arrayId = [...Array(result)].map((_, i) => i + id);
|
|
2358
|
+
const sql = [
|
|
2359
|
+
`${this.$state.get('SELECT')}`,
|
|
2360
|
+
`${this.$state.get('FROM')}`,
|
|
2361
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2362
|
+
`${this.$constants('WHERE')} id`,
|
|
2363
|
+
`${this.$constants('IN')} (${arrayId})`
|
|
2364
|
+
].join(' ');
|
|
2365
|
+
const data = yield this.queryStatement(sql);
|
|
2366
|
+
const resultData = data || null;
|
|
2367
|
+
return this.resultHandler(resultData);
|
|
2255
2368
|
});
|
|
2256
2369
|
}
|
|
2257
2370
|
_insertOrSelect() {
|
|
@@ -2278,21 +2391,17 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2278
2391
|
sql: this.$state.get('INSERT'),
|
|
2279
2392
|
returnId: true
|
|
2280
2393
|
});
|
|
2281
|
-
if (this.$state.get('VOID'))
|
|
2282
|
-
return null;
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
this.$state.set('RESULT', resultData);
|
|
2293
|
-
return resultData;
|
|
2294
|
-
}
|
|
2295
|
-
return null;
|
|
2394
|
+
if (this.$state.get('VOID') || !result)
|
|
2395
|
+
return this.resultHandler(null);
|
|
2396
|
+
const sql = [
|
|
2397
|
+
`${this.$state.get('SELECT')}`,
|
|
2398
|
+
`${this.$state.get('FROM')}`,
|
|
2399
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2400
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
2401
|
+
].join(' ');
|
|
2402
|
+
const data = yield this.queryStatement(sql);
|
|
2403
|
+
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'insert' }) || null;
|
|
2404
|
+
return this.resultHandler(resultData);
|
|
2296
2405
|
}
|
|
2297
2406
|
case true: {
|
|
2298
2407
|
const data = yield this.queryStatement([
|
|
@@ -2303,14 +2412,15 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2303
2412
|
].join(' '));
|
|
2304
2413
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2305
2414
|
for (const val of data) {
|
|
2306
|
-
val
|
|
2415
|
+
val.$action = 'select';
|
|
2307
2416
|
}
|
|
2308
|
-
return data || [];
|
|
2417
|
+
return this.resultHandler(data || []);
|
|
2309
2418
|
}
|
|
2310
|
-
|
|
2419
|
+
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'select' }) || null;
|
|
2420
|
+
return this.resultHandler(resultData);
|
|
2311
2421
|
}
|
|
2312
2422
|
default: {
|
|
2313
|
-
return null;
|
|
2423
|
+
return this.resultHandler(null);
|
|
2314
2424
|
}
|
|
2315
2425
|
}
|
|
2316
2426
|
});
|
|
@@ -2339,21 +2449,17 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2339
2449
|
sql: this.$state.get('INSERT'),
|
|
2340
2450
|
returnId: true
|
|
2341
2451
|
});
|
|
2342
|
-
if (this.$state.get('VOID'))
|
|
2343
|
-
return null;
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
this.$state.set('RESULT', resultData);
|
|
2354
|
-
return resultData;
|
|
2355
|
-
}
|
|
2356
|
-
return null;
|
|
2452
|
+
if (this.$state.get('VOID') || !result)
|
|
2453
|
+
return this.resultHandler(null);
|
|
2454
|
+
const sql = [
|
|
2455
|
+
`${this.$state.get('SELECT')}`,
|
|
2456
|
+
`${this.$state.get('FROM')}`,
|
|
2457
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2458
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
2459
|
+
].join(' ');
|
|
2460
|
+
const data = yield this.queryStatement(sql);
|
|
2461
|
+
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'insert' }) || null;
|
|
2462
|
+
return this.resultHandler(resultData);
|
|
2357
2463
|
}
|
|
2358
2464
|
case true: {
|
|
2359
2465
|
const result = yield this.actionStatement({
|
|
@@ -2362,27 +2468,25 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2362
2468
|
`${this.$state.get('WHERE')}`
|
|
2363
2469
|
].join(' ')
|
|
2364
2470
|
});
|
|
2365
|
-
if (this.$state.get('VOID'))
|
|
2366
|
-
return null;
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
val.action_status = 'update';
|
|
2377
|
-
}
|
|
2378
|
-
return data || [];
|
|
2471
|
+
if (this.$state.get('VOID') || !result)
|
|
2472
|
+
return this.resultHandler(null);
|
|
2473
|
+
const data = yield this.queryStatement([
|
|
2474
|
+
`${this.$state.get('SELECT')}`,
|
|
2475
|
+
`${this.$state.get('FROM')}`,
|
|
2476
|
+
`${this.$state.get('TABLE_NAME')}`,
|
|
2477
|
+
`${this.$state.get('WHERE')}`
|
|
2478
|
+
].join(' '));
|
|
2479
|
+
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2480
|
+
for (const val of data) {
|
|
2481
|
+
val.$action = 'update';
|
|
2379
2482
|
}
|
|
2380
|
-
return
|
|
2483
|
+
return this.resultHandler(data || []);
|
|
2381
2484
|
}
|
|
2382
|
-
|
|
2485
|
+
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'update' }) || null;
|
|
2486
|
+
return this.resultHandler(resultData);
|
|
2383
2487
|
}
|
|
2384
2488
|
default: {
|
|
2385
|
-
return null;
|
|
2489
|
+
return this.resultHandler(null);
|
|
2386
2490
|
}
|
|
2387
2491
|
}
|
|
2388
2492
|
});
|
|
@@ -2396,10 +2500,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2396
2500
|
`${this.$state.get('UPDATE')}`, `${this.$state.get('WHERE')}`
|
|
2397
2501
|
].join(' ')
|
|
2398
2502
|
});
|
|
2399
|
-
if (this.$state.get('VOID'))
|
|
2400
|
-
return null;
|
|
2401
|
-
if (!result)
|
|
2402
|
-
return null;
|
|
2503
|
+
if (this.$state.get('VOID') || !result)
|
|
2504
|
+
return this.resultHandler(null);
|
|
2403
2505
|
const sql = [
|
|
2404
2506
|
`${this.$state.get('SELECT')}`,
|
|
2405
2507
|
`${this.$state.get('FROM')}`,
|
|
@@ -2408,10 +2510,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2408
2510
|
].join(' ');
|
|
2409
2511
|
const data = yield this.queryStatement(sql);
|
|
2410
2512
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1)
|
|
2411
|
-
return data || [];
|
|
2513
|
+
return this.resultHandler(data || []);
|
|
2412
2514
|
const res = (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
2413
|
-
this
|
|
2414
|
-
return res;
|
|
2515
|
+
return this.resultHandler(res);
|
|
2415
2516
|
});
|
|
2416
2517
|
}
|
|
2417
2518
|
_hiddenColumn(data) {
|
|
@@ -2481,7 +2582,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2481
2582
|
if (useDefault)
|
|
2482
2583
|
return [operator, '='];
|
|
2483
2584
|
if (operator == null)
|
|
2484
|
-
throw new Error('
|
|
2585
|
+
throw new Error('Bad arguments');
|
|
2485
2586
|
if (operator.toUpperCase() === this.$constants('LIKE')) {
|
|
2486
2587
|
operator = operator.toUpperCase();
|
|
2487
2588
|
}
|
|
@@ -2512,7 +2613,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2512
2613
|
}
|
|
2513
2614
|
if (this.$state.get('DELETE')) {
|
|
2514
2615
|
sql = [
|
|
2515
|
-
this.$state.get('DELETE')
|
|
2616
|
+
this.$state.get('DELETE'),
|
|
2617
|
+
this.$state.get('WHERE')
|
|
2516
2618
|
];
|
|
2517
2619
|
break;
|
|
2518
2620
|
}
|
|
@@ -2553,6 +2655,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2553
2655
|
logger = [...logger, data];
|
|
2554
2656
|
return;
|
|
2555
2657
|
},
|
|
2658
|
+
reset: () => {
|
|
2659
|
+
logger = [];
|
|
2660
|
+
return;
|
|
2661
|
+
},
|
|
2556
2662
|
check: (data) => logger.indexOf(data) != -1
|
|
2557
2663
|
};
|
|
2558
2664
|
})();
|
|
@@ -2560,9 +2666,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2560
2666
|
if (name == null)
|
|
2561
2667
|
return constants_1.CONSTANTS;
|
|
2562
2668
|
if (!constants_1.CONSTANTS.hasOwnProperty(name.toUpperCase()))
|
|
2563
|
-
throw new Error(`
|
|
2669
|
+
throw new Error(`Not found constants : ${name}`);
|
|
2564
2670
|
return constants_1.CONSTANTS[name.toUpperCase()];
|
|
2565
2671
|
};
|
|
2672
|
+
this.$state = new StateHandler_1.StateHandler(this.$constants('DEFAULT'));
|
|
2566
2673
|
}
|
|
2567
2674
|
}
|
|
2568
2675
|
exports.Builder = Builder;
|