tspace-mysql 1.9.4-beta.4 → 1.9.4-beta.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 +57 -16
- package/dist/lib/config/index.d.ts +2 -2
- package/dist/lib/config/index.js +2 -2
- package/dist/lib/config/index.js.map +1 -1
- package/dist/lib/constants/index.d.ts +0 -1
- package/dist/lib/constants/index.js +0 -1
- package/dist/lib/constants/index.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractDB.d.ts +3 -3
- 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.js +1 -1
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +4 -4
- package/dist/lib/core/Builder.js +51 -49
- 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 +2 -1
- package/dist/lib/core/Contracts/Audit.js +17 -1
- package/dist/lib/core/Contracts/Audit.js.map +1 -1
- package/dist/lib/core/DB.d.ts +16 -8
- package/dist/lib/core/DB.js +24 -17
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +23 -14
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.d.ts +2 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +3 -0
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +26 -17
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +147 -128
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +3 -2
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +3 -0
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +24 -15
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +176 -164
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.d.ts +2 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +3 -9
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +26 -17
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +147 -128
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.d.ts +2 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +3 -0
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +27 -18
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +235 -216
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +2 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +3 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +28 -19
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +178 -176
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -1
- package/dist/lib/core/Model.d.ts +12 -20
- package/dist/lib/core/Model.js +98 -62
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/core/Pool.js +3 -7
- 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 +29 -2
- package/dist/lib/core/Queue/worker-lock.js +5 -7
- package/dist/lib/core/Queue/worker-lock.js.map +1 -1
- package/dist/lib/core/Queue/worker.d.ts +22 -18
- package/dist/lib/core/Queue/worker.js +188 -101
- 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.js +1 -0
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +4 -3
- package/dist/lib/core/Schema.js +122 -87
- 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 +2 -0
- package/dist/lib/core/StateManager.js +5 -4
- package/dist/lib/core/StateManager.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +13 -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 +21 -68
- package/dist/lib/types/repository/index.d.ts +8 -8
- package/package.json +1 -1
package/dist/lib/core/Builder.js
CHANGED
|
@@ -431,7 +431,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
431
431
|
sleep(second) {
|
|
432
432
|
this.CTEs('sleep', (query) => {
|
|
433
433
|
return query
|
|
434
|
-
.selectRaw(`${this.
|
|
434
|
+
.selectRaw(`${this.getQueryBuilder().sleep(second)} ${this.$constants("AS")} delay`)
|
|
435
435
|
.from(null);
|
|
436
436
|
});
|
|
437
437
|
this.from(this.$state.get("TABLE_NAME"), {
|
|
@@ -1676,7 +1676,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
1676
1676
|
random() {
|
|
1677
1677
|
this.$state.set("ORDER_BY", [
|
|
1678
1678
|
...this.$state.get("ORDER_BY"),
|
|
1679
|
-
`${this
|
|
1679
|
+
`${this.getQueryBuilder().random()}`,
|
|
1680
1680
|
]);
|
|
1681
1681
|
return this;
|
|
1682
1682
|
}
|
|
@@ -2251,7 +2251,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2251
2251
|
* @returns {string} return sql query
|
|
2252
2252
|
*/
|
|
2253
2253
|
toString() {
|
|
2254
|
-
const sql = this.
|
|
2254
|
+
const sql = this.getQueryBuilder().any();
|
|
2255
2255
|
return this._resultHandler(sql);
|
|
2256
2256
|
}
|
|
2257
2257
|
/**
|
|
@@ -2311,7 +2311,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2311
2311
|
* @returns {Promise<Array>}
|
|
2312
2312
|
*/
|
|
2313
2313
|
async showSchema(table = String(this.$state.get("TABLE_NAME")), options = {}) {
|
|
2314
|
-
const qb = this.
|
|
2314
|
+
const qb = this.getQueryBuilder();
|
|
2315
2315
|
const sql = qb.getSchema({
|
|
2316
2316
|
database: this.$database,
|
|
2317
2317
|
table: this.$utils.escape(table),
|
|
@@ -2341,7 +2341,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2341
2341
|
if (table == null) {
|
|
2342
2342
|
throw new Error('Unknown table name');
|
|
2343
2343
|
}
|
|
2344
|
-
const sql = this.
|
|
2344
|
+
const sql = this.getQueryBuilder().getSchema({
|
|
2345
2345
|
database: this.$database,
|
|
2346
2346
|
table,
|
|
2347
2347
|
});
|
|
@@ -2361,7 +2361,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2361
2361
|
*
|
|
2362
2362
|
*/
|
|
2363
2363
|
async getFKs(table) {
|
|
2364
|
-
const fks = await this.rawQuery(this.
|
|
2364
|
+
const fks = await this.rawQuery(this.getQueryBuilder().getFKs({
|
|
2365
2365
|
database: this.$database,
|
|
2366
2366
|
table: table ?? String(this.$state.get("TABLE_NAME")),
|
|
2367
2367
|
}));
|
|
@@ -2378,7 +2378,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2378
2378
|
*
|
|
2379
2379
|
*/
|
|
2380
2380
|
async hasFK({ constraint, table }) {
|
|
2381
|
-
const result = await this.rawQuery(this.
|
|
2381
|
+
const result = await this.rawQuery(this.getQueryBuilder().hasFK({
|
|
2382
2382
|
database: this.$database,
|
|
2383
2383
|
table: table ?? String(this.$state.get("TABLE_NAME")),
|
|
2384
2384
|
constraint
|
|
@@ -2401,7 +2401,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2401
2401
|
*
|
|
2402
2402
|
*/
|
|
2403
2403
|
async getChildFKs(table) {
|
|
2404
|
-
const childFks = await this.rawQuery(this.
|
|
2404
|
+
const childFks = await this.rawQuery(this.getQueryBuilder().getChildFKs({
|
|
2405
2405
|
database: this.$database,
|
|
2406
2406
|
table: table ?? String(this.$state.get("TABLE_NAME")),
|
|
2407
2407
|
}));
|
|
@@ -2435,7 +2435,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2435
2435
|
if (exists) {
|
|
2436
2436
|
throw new Error('The specified foreign key constraint already exists.');
|
|
2437
2437
|
}
|
|
2438
|
-
await this.rawQuery(this.
|
|
2438
|
+
await this.rawQuery(this.getQueryBuilder()
|
|
2439
2439
|
.addFK({
|
|
2440
2440
|
table: table ?? this.getTableName(),
|
|
2441
2441
|
tableRef,
|
|
@@ -2460,7 +2460,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2460
2460
|
if (!exists) {
|
|
2461
2461
|
throw new Error('The specified foreign key constraint was not found.');
|
|
2462
2462
|
}
|
|
2463
|
-
await this.rawQuery(this.
|
|
2463
|
+
await this.rawQuery(this.getQueryBuilder()
|
|
2464
2464
|
.dropFK({
|
|
2465
2465
|
table: table ?? this.getTableName(),
|
|
2466
2466
|
constraint
|
|
@@ -2483,7 +2483,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2483
2483
|
*
|
|
2484
2484
|
*/
|
|
2485
2485
|
async getIndexes(table) {
|
|
2486
|
-
const indexes = await this.rawQuery(this.
|
|
2486
|
+
const indexes = await this.rawQuery(this.getQueryBuilder().getIndexes({
|
|
2487
2487
|
database: this.$database,
|
|
2488
2488
|
table: table ?? this.getTableName()
|
|
2489
2489
|
}));
|
|
@@ -2500,7 +2500,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2500
2500
|
*
|
|
2501
2501
|
*/
|
|
2502
2502
|
async hasIndex({ name, table }) {
|
|
2503
|
-
const result = await this.rawQuery(this.
|
|
2503
|
+
const result = await this.rawQuery(this.getQueryBuilder().hasIndex({
|
|
2504
2504
|
database: this.$database,
|
|
2505
2505
|
table: table ?? this.getTableName(),
|
|
2506
2506
|
name
|
|
@@ -2530,7 +2530,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2530
2530
|
if (exists) {
|
|
2531
2531
|
throw new Error('The specified index already exists.');
|
|
2532
2532
|
}
|
|
2533
|
-
await this.rawQuery(this.
|
|
2533
|
+
await this.rawQuery(this.getQueryBuilder().addIndex({
|
|
2534
2534
|
table: table ?? this.getTableName(),
|
|
2535
2535
|
name,
|
|
2536
2536
|
columns
|
|
@@ -2559,7 +2559,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2559
2559
|
if (!exists) {
|
|
2560
2560
|
throw new Error('The specified index was not found');
|
|
2561
2561
|
}
|
|
2562
|
-
await this.rawQuery(this.
|
|
2562
|
+
await this.rawQuery(this.getQueryBuilder().dropIndex({
|
|
2563
2563
|
table: table ?? this.getTableName(),
|
|
2564
2564
|
name,
|
|
2565
2565
|
}));
|
|
@@ -2580,7 +2580,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2580
2580
|
* @returns {Promise<boolean>} Returns `true` if the unique constraint exists, otherwise `false`.
|
|
2581
2581
|
*/
|
|
2582
2582
|
async hasUnique({ name, table }) {
|
|
2583
|
-
const result = await this.rawQuery(this.
|
|
2583
|
+
const result = await this.rawQuery(this.getQueryBuilder().hasUnique({
|
|
2584
2584
|
database: this.$database,
|
|
2585
2585
|
table: table ?? this.getTableName(),
|
|
2586
2586
|
name
|
|
@@ -2610,7 +2610,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2610
2610
|
if (exists) {
|
|
2611
2611
|
throw new Error('The specified unique constraint already exists.');
|
|
2612
2612
|
}
|
|
2613
|
-
await this.rawQuery(this.
|
|
2613
|
+
await this.rawQuery(this.getQueryBuilder().addUnique({
|
|
2614
2614
|
table: table ?? this.getTableName(),
|
|
2615
2615
|
name,
|
|
2616
2616
|
columns
|
|
@@ -2639,7 +2639,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2639
2639
|
if (!exists) {
|
|
2640
2640
|
throw new Error('The specified unique constraint was not found.');
|
|
2641
2641
|
}
|
|
2642
|
-
await this.rawQuery(this.
|
|
2642
|
+
await this.rawQuery(this.getQueryBuilder().dropUnique({
|
|
2643
2643
|
table: table ?? this.getTableName(),
|
|
2644
2644
|
name,
|
|
2645
2645
|
}));
|
|
@@ -2660,7 +2660,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2660
2660
|
* otherwise `false`.
|
|
2661
2661
|
*/
|
|
2662
2662
|
async hasPrimaryKey({ table } = {}) {
|
|
2663
|
-
const result = await this.rawQuery(this.
|
|
2663
|
+
const result = await this.rawQuery(this.getQueryBuilder().hasPrimaryKey({
|
|
2664
2664
|
database: this.$database,
|
|
2665
2665
|
table: table ?? this.getTableName()
|
|
2666
2666
|
}));
|
|
@@ -2688,7 +2688,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2688
2688
|
if (exists) {
|
|
2689
2689
|
throw new Error('The specified primary constraint already exists.');
|
|
2690
2690
|
}
|
|
2691
|
-
await this.rawQuery(this.
|
|
2691
|
+
await this.rawQuery(this.getQueryBuilder().addPrimaryKey({
|
|
2692
2692
|
table: table ?? String(this.getTableName()),
|
|
2693
2693
|
columns
|
|
2694
2694
|
}));
|
|
@@ -2714,7 +2714,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2714
2714
|
if (!exists) {
|
|
2715
2715
|
throw new Error('The specified primary constraint was not found.');
|
|
2716
2716
|
}
|
|
2717
|
-
await this.rawQuery(this.
|
|
2717
|
+
await this.rawQuery(this.getQueryBuilder().dropPrimaryKey({
|
|
2718
2718
|
table: table ?? String(this.getTableName())
|
|
2719
2719
|
}));
|
|
2720
2720
|
return;
|
|
@@ -2846,6 +2846,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2846
2846
|
bind(connection) {
|
|
2847
2847
|
this.$state.set('BIND', true);
|
|
2848
2848
|
this.$pool.set(connection);
|
|
2849
|
+
this.$database = connection.database();
|
|
2850
|
+
this.$driver = connection.driver();
|
|
2849
2851
|
return this;
|
|
2850
2852
|
}
|
|
2851
2853
|
/**
|
|
@@ -3111,7 +3113,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3111
3113
|
if (this.$state.get("EXCEPTS")?.length)
|
|
3112
3114
|
this.select(...(await this.exceptColumns()));
|
|
3113
3115
|
this.limit(1);
|
|
3114
|
-
let sql = this.
|
|
3116
|
+
let sql = this.getQueryBuilder().select();
|
|
3115
3117
|
if (cb) {
|
|
3116
3118
|
const callbackSql = cb(sql);
|
|
3117
3119
|
if (callbackSql == null || callbackSql === "")
|
|
@@ -3148,7 +3150,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3148
3150
|
if (this.$state.get("EXCEPTS")?.length)
|
|
3149
3151
|
this.select(...(await this.exceptColumns()));
|
|
3150
3152
|
this.limit(1);
|
|
3151
|
-
let sql = this.
|
|
3153
|
+
let sql = this.getQueryBuilder().select();
|
|
3152
3154
|
const result = await this._queryStatement(sql);
|
|
3153
3155
|
const data = result?.shift() || null;
|
|
3154
3156
|
if (data == null) {
|
|
@@ -3185,7 +3187,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3185
3187
|
if (this.$state.get("EXCEPTS")?.length) {
|
|
3186
3188
|
this.select(...(await this.exceptColumns()));
|
|
3187
3189
|
}
|
|
3188
|
-
let sql = this.
|
|
3190
|
+
let sql = this.getQueryBuilder().select();
|
|
3189
3191
|
if (cb) {
|
|
3190
3192
|
const callbackSql = cb(sql);
|
|
3191
3193
|
if (callbackSql == null || callbackSql === "") {
|
|
@@ -3222,7 +3224,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3222
3224
|
sql = this.toSQL();
|
|
3223
3225
|
}
|
|
3224
3226
|
const LARGE_SCAN_ROWS = 10_000;
|
|
3225
|
-
const qb = this.
|
|
3227
|
+
const qb = this.getQueryBuilder();
|
|
3226
3228
|
const plan = await this.rawQuery(qb.explain(sql)).catch(() => []);
|
|
3227
3229
|
const issues = [];
|
|
3228
3230
|
const recommendations = [];
|
|
@@ -3436,7 +3438,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3436
3438
|
*/
|
|
3437
3439
|
async toArray(column = "id") {
|
|
3438
3440
|
this.selectRaw(`${this.bindColumn(column)}`);
|
|
3439
|
-
const sql = this.
|
|
3441
|
+
const sql = this.getQueryBuilder().select();
|
|
3440
3442
|
const result = await this._queryStatement(sql);
|
|
3441
3443
|
const toArray = result.map((data) => data[column]);
|
|
3442
3444
|
return this._resultHandler(toArray);
|
|
@@ -3477,7 +3479,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3477
3479
|
? `${this.$constants("DISTINCT")} ${this.bindColumn(column)}`
|
|
3478
3480
|
: `${this.bindColumn(column)}`;
|
|
3479
3481
|
this.selectRaw(`${this.$constants("COUNT")}(${column}) ${this.$constants(`${this.$constants("AS")}`)} \`aggregate\``);
|
|
3480
|
-
const sql = this.
|
|
3482
|
+
const sql = this.getQueryBuilder().select();
|
|
3481
3483
|
const result = await this._queryStatement(sql);
|
|
3482
3484
|
return Number(this._resultHandler(result.reduce((prev, cur) => prev + Number(cur?.aggregate ?? 0), 0) || 0));
|
|
3483
3485
|
}
|
|
@@ -3494,7 +3496,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3494
3496
|
? `${this.$constants("DISTINCT")} ${this.bindColumn(column)}`
|
|
3495
3497
|
: `${this.bindColumn(column)}`;
|
|
3496
3498
|
this.selectRaw(`${this.$constants("AVG")}(${column}) ${this.$constants("AS")} \`aggregate\``);
|
|
3497
|
-
const sql = this.
|
|
3499
|
+
const sql = this.getQueryBuilder().select();
|
|
3498
3500
|
const result = await this._queryStatement(sql);
|
|
3499
3501
|
return Number(this._resultHandler((result.reduce((prev, cur) => prev + Number(cur?.aggregate ?? 0), 0) ||
|
|
3500
3502
|
0) / result.length));
|
|
@@ -3512,7 +3514,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3512
3514
|
? `${this.$constants("DISTINCT")} ${this.bindColumn(column)}`
|
|
3513
3515
|
: `${this.bindColumn(column)}`;
|
|
3514
3516
|
this.selectRaw(`${this.$constants("SUM")}(${column}) ${this.$constants("AS")} \`aggregate\``);
|
|
3515
|
-
const sql = this.
|
|
3517
|
+
const sql = this.getQueryBuilder().select();
|
|
3516
3518
|
const result = await this._queryStatement(sql);
|
|
3517
3519
|
return Number(this._resultHandler(result.reduce((prev, cur) => prev + Number(cur?.aggregate ?? 0), 0) || 0));
|
|
3518
3520
|
}
|
|
@@ -3529,7 +3531,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3529
3531
|
? `${this.$constants("DISTINCT")} ${this.bindColumn(column)}`
|
|
3530
3532
|
: `${this.bindColumn(column)}`;
|
|
3531
3533
|
this.selectRaw(`${this.$constants("MAX")}(${column}) ${this.$constants("AS")} \`aggregate\``);
|
|
3532
|
-
const sql = this.
|
|
3534
|
+
const sql = this.getQueryBuilder().select();
|
|
3533
3535
|
const result = await this._queryStatement(sql);
|
|
3534
3536
|
return Number(this._resultHandler(result.sort((a, b) => b?.aggregate - a?.aggregate)[0]?.aggregate || 0));
|
|
3535
3537
|
}
|
|
@@ -3546,7 +3548,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3546
3548
|
? `${this.$constants("DISTINCT")} ${this.bindColumn(column)}`
|
|
3547
3549
|
: `${this.bindColumn(column)}`;
|
|
3548
3550
|
this.selectRaw(`${this.$constants("MIN")}(${column}) ${this.$constants("AS")} \`aggregate\``);
|
|
3549
|
-
const sql = this.
|
|
3551
|
+
const sql = this.getQueryBuilder().select();
|
|
3550
3552
|
const result = await this._queryStatement(sql);
|
|
3551
3553
|
return Number(this._resultHandler(result.sort((a, b) => a?.aggregate - b?.aggregate)[0]?.aggregate || 0));
|
|
3552
3554
|
}
|
|
@@ -3562,7 +3564,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3562
3564
|
}
|
|
3563
3565
|
this.limit(1);
|
|
3564
3566
|
this.$state.set("DELETE", true);
|
|
3565
|
-
const result = await this._actionStatement(this.
|
|
3567
|
+
const result = await this._actionStatement(this.getQueryBuilder().remove());
|
|
3566
3568
|
return Boolean(this._resultHandler(result?.$meta?.affected ?? false));
|
|
3567
3569
|
}
|
|
3568
3570
|
/**
|
|
@@ -3576,7 +3578,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3576
3578
|
throw new Error("can't delete without where condition");
|
|
3577
3579
|
}
|
|
3578
3580
|
this.$state.set("DELETE", true);
|
|
3579
|
-
const result = await this._actionStatement(this.
|
|
3581
|
+
const result = await this._actionStatement(this.getQueryBuilder().remove());
|
|
3580
3582
|
return Boolean(this._resultHandler(result?.$meta?.affected ?? false));
|
|
3581
3583
|
}
|
|
3582
3584
|
/**
|
|
@@ -3590,7 +3592,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3590
3592
|
*/
|
|
3591
3593
|
async forceDelete() {
|
|
3592
3594
|
this.$state.set("DELETE", true);
|
|
3593
|
-
const result = await this._actionStatement(this.
|
|
3595
|
+
const result = await this._actionStatement(this.getQueryBuilder().remove());
|
|
3594
3596
|
return Boolean(this._resultHandler(result?.$meta?.affected ?? false));
|
|
3595
3597
|
}
|
|
3596
3598
|
/**
|
|
@@ -3793,7 +3795,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3793
3795
|
* @async
|
|
3794
3796
|
*/
|
|
3795
3797
|
async getTables() {
|
|
3796
|
-
const results = await this._queryStatement(this.
|
|
3798
|
+
const results = await this._queryStatement(this.getQueryBuilder().getTables(this.database()));
|
|
3797
3799
|
return results
|
|
3798
3800
|
.map((table) => String(Object.values(table)[0]))
|
|
3799
3801
|
.filter((d) => d != null || d !== "");
|
|
@@ -3807,7 +3809,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3807
3809
|
* @async
|
|
3808
3810
|
*/
|
|
3809
3811
|
async hasTable(table) {
|
|
3810
|
-
const result = await this._queryStatement(this.
|
|
3812
|
+
const result = await this._queryStatement(this.getQueryBuilder().hasTable({ database: this.database(), table }));
|
|
3811
3813
|
return Boolean(result[0]?.IS_EXISTS ?? false);
|
|
3812
3814
|
}
|
|
3813
3815
|
/**
|
|
@@ -3818,7 +3820,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3818
3820
|
* @returns {Promise<Array>}
|
|
3819
3821
|
*/
|
|
3820
3822
|
async showColumns(table = String(this.$state.get("TABLE_NAME")), options = {}) {
|
|
3821
|
-
const sql = this.
|
|
3823
|
+
const sql = this.getQueryBuilder().getColumns({
|
|
3822
3824
|
table,
|
|
3823
3825
|
database: this.$database,
|
|
3824
3826
|
});
|
|
@@ -3934,7 +3936,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3934
3936
|
].join('\n'));
|
|
3935
3937
|
return false;
|
|
3936
3938
|
}
|
|
3937
|
-
const sql = this.
|
|
3939
|
+
const sql = this.getQueryBuilder().truncate(this.getTableName());
|
|
3938
3940
|
if (!force) {
|
|
3939
3941
|
console.log([
|
|
3940
3942
|
`\x1b[33m`,
|
|
@@ -3986,10 +3988,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3986
3988
|
}
|
|
3987
3989
|
const sql = [
|
|
3988
3990
|
db
|
|
3989
|
-
? this.
|
|
3991
|
+
? this.getQueryBuilder().dropDatabase(table)
|
|
3990
3992
|
: view
|
|
3991
|
-
? this.
|
|
3992
|
-
: this.
|
|
3993
|
+
? this.getQueryBuilder().dropView(table)
|
|
3994
|
+
: this.getQueryBuilder().dropTable(table),
|
|
3993
3995
|
].join(" ");
|
|
3994
3996
|
if (!force) {
|
|
3995
3997
|
console.log([
|
|
@@ -4080,7 +4082,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4080
4082
|
newInstance.$state.set("HAVING", null);
|
|
4081
4083
|
return newInstance;
|
|
4082
4084
|
}
|
|
4083
|
-
|
|
4085
|
+
getQueryBuilder() {
|
|
4084
4086
|
return this._buildQueryStatement();
|
|
4085
4087
|
}
|
|
4086
4088
|
_buildQueryStatement() {
|
|
@@ -4144,7 +4146,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4144
4146
|
.exists();
|
|
4145
4147
|
switch (check) {
|
|
4146
4148
|
case false: {
|
|
4147
|
-
const result = await this._actionStatement(this.
|
|
4149
|
+
const result = await this._actionStatement(this.getQueryBuilder().insert());
|
|
4148
4150
|
if (this.$state.get("VOID") || !result) {
|
|
4149
4151
|
return this._resultHandler(undefined);
|
|
4150
4152
|
}
|
|
@@ -4162,7 +4164,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4162
4164
|
}
|
|
4163
4165
|
}
|
|
4164
4166
|
async _insert() {
|
|
4165
|
-
const result = await this._actionStatement(this.
|
|
4167
|
+
const result = await this._actionStatement(this.getQueryBuilder().insert());
|
|
4166
4168
|
if (this.$state.get("VOID") || !result)
|
|
4167
4169
|
return this._resultHandler(undefined);
|
|
4168
4170
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
@@ -4175,7 +4177,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4175
4177
|
return this._resultHandler(results);
|
|
4176
4178
|
}
|
|
4177
4179
|
async _insertMultiple() {
|
|
4178
|
-
const result = await this._actionStatement(this.
|
|
4180
|
+
const result = await this._actionStatement(this.getQueryBuilder().insert());
|
|
4179
4181
|
if (this.$state.get("VOID") || !result)
|
|
4180
4182
|
return this._resultHandler(undefined);
|
|
4181
4183
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
@@ -4202,7 +4204,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4202
4204
|
.exists();
|
|
4203
4205
|
switch (check) {
|
|
4204
4206
|
case false: {
|
|
4205
|
-
const result = await this._actionStatement(this.
|
|
4207
|
+
const result = await this._actionStatement(this.getQueryBuilder().insert());
|
|
4206
4208
|
if (this.$state.get("VOID") || !result)
|
|
4207
4209
|
return this._resultHandler(undefined);
|
|
4208
4210
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
@@ -4249,7 +4251,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4249
4251
|
.exists();
|
|
4250
4252
|
switch (check) {
|
|
4251
4253
|
case false: {
|
|
4252
|
-
const result = await this._actionStatement(this.
|
|
4254
|
+
const result = await this._actionStatement(this.getQueryBuilder().insert());
|
|
4253
4255
|
if (this.$state.get("VOID") || !result)
|
|
4254
4256
|
return this._resultHandler(undefined);
|
|
4255
4257
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
@@ -4263,7 +4265,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4263
4265
|
return this._resultHandler(resultData);
|
|
4264
4266
|
}
|
|
4265
4267
|
case true: {
|
|
4266
|
-
const result = await this._actionStatement(this.
|
|
4268
|
+
const result = await this._actionStatement(this.getQueryBuilder().update());
|
|
4267
4269
|
if (this.$state.get("VOID") || !result)
|
|
4268
4270
|
return this._resultHandler(null);
|
|
4269
4271
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
@@ -4288,11 +4290,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4288
4290
|
async _update(ignoreWhere = false) {
|
|
4289
4291
|
if (!this.$state.get("WHERE").length && !ignoreWhere)
|
|
4290
4292
|
throw new Error("can't update without where condition");
|
|
4291
|
-
const result = await this._actionStatement(this.
|
|
4293
|
+
const result = await this._actionStatement(this.getQueryBuilder().update());
|
|
4292
4294
|
if (this.$state.get("VOID") || !result)
|
|
4293
4295
|
return this._resultHandler(undefined);
|
|
4294
4296
|
await this.$utils.wait(this.$state.get("AFTER_SAVE"));
|
|
4295
|
-
const sql = this.
|
|
4297
|
+
const sql = this.getQueryBuilder().select();
|
|
4296
4298
|
const data = await this._queryStatement(sql);
|
|
4297
4299
|
if (data?.length > 1)
|
|
4298
4300
|
return this._resultHandler(data || []);
|