tspace-mysql 1.7.2 → 1.7.3
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/build/lib/core/Builder.d.ts +3 -1
- package/build/lib/core/Builder.js +30 -32
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Handlers/Relation.js +1 -0
- package/build/lib/core/Handlers/Relation.js.map +1 -1
- package/build/lib/core/Handlers/State.d.ts +2 -0
- package/build/lib/core/Handlers/State.js +4 -2
- package/build/lib/core/Handlers/State.js.map +1 -1
- package/build/lib/core/Model.d.ts +9 -7
- package/build/lib/core/Model.js +20 -16
- package/build/lib/core/Model.js.map +1 -1
- package/build/lib/core/Repository.d.ts +1 -1
- package/build/lib/core/Repository.js +4 -2
- package/build/lib/core/Repository.js.map +1 -1
- package/build/lib/utils/index.d.ts +1 -0
- package/build/lib/utils/index.js +6 -2
- package/build/lib/utils/index.js.map +1 -1
- package/build/tests/03-Model-default.test.js +5 -5
- package/build/tests/03-Model-default.test.js.map +1 -1
- package/build/tests/04-Model-pattern.test.js +4 -4
- package/build/tests/04-Model-pattern.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -1296,7 +1296,9 @@ declare class Builder extends AbstractBuilder {
|
|
|
1296
1296
|
* It's a versatile method that can be used in various scenarios, depending on whether you're working with a new or existing record.
|
|
1297
1297
|
* @returns {Promise<any>} promise
|
|
1298
1298
|
*/
|
|
1299
|
-
save(
|
|
1299
|
+
save({ waitMs }?: {
|
|
1300
|
+
waitMs?: number | undefined;
|
|
1301
|
+
}): Promise<Record<string, any> | any[] | null | undefined>;
|
|
1300
1302
|
/**
|
|
1301
1303
|
*
|
|
1302
1304
|
* The 'makeSelectStatement' method is used to make select statement.
|
|
@@ -2884,7 +2884,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2884
2884
|
*/
|
|
2885
2885
|
delete() {
|
|
2886
2886
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2887
|
-
var _a;
|
|
2888
2887
|
if (!this.$state.get('WHERE').length) {
|
|
2889
2888
|
throw new Error("can't delete without where condition");
|
|
2890
2889
|
}
|
|
@@ -2896,7 +2895,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2896
2895
|
].join(' '));
|
|
2897
2896
|
const result = yield this._actionStatement({ sql: this._queryBuilder().delete() });
|
|
2898
2897
|
if (result)
|
|
2899
|
-
return Boolean(this._resultHandler(
|
|
2898
|
+
return Boolean(this._resultHandler(!!result || false));
|
|
2900
2899
|
return Boolean(this._resultHandler(false));
|
|
2901
2900
|
});
|
|
2902
2901
|
}
|
|
@@ -2908,7 +2907,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2908
2907
|
*/
|
|
2909
2908
|
deleteMany() {
|
|
2910
2909
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2911
|
-
var _a;
|
|
2912
2910
|
if (!this.$state.get('WHERE').length) {
|
|
2913
2911
|
throw new Error("can't delete without where condition");
|
|
2914
2912
|
}
|
|
@@ -2919,7 +2917,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2919
2917
|
].join(' '));
|
|
2920
2918
|
const result = yield this._actionStatement({ sql: this._queryBuilder().delete() });
|
|
2921
2919
|
if (result)
|
|
2922
|
-
return Boolean(this._resultHandler(
|
|
2920
|
+
return Boolean(this._resultHandler(!!result || false));
|
|
2923
2921
|
return Boolean(this._resultHandler(false));
|
|
2924
2922
|
});
|
|
2925
2923
|
}
|
|
@@ -2934,7 +2932,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2934
2932
|
*/
|
|
2935
2933
|
forceDelete() {
|
|
2936
2934
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2937
|
-
var _a, _b;
|
|
2938
2935
|
this.$state.set('DELETE', [
|
|
2939
2936
|
`${this.$constants('DELETE')}`,
|
|
2940
2937
|
`${this.$state.get('FROM')}`,
|
|
@@ -2942,8 +2939,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2942
2939
|
].join(' '));
|
|
2943
2940
|
const result = yield this._actionStatement({ sql: this._queryBuilder().delete() });
|
|
2944
2941
|
if (result)
|
|
2945
|
-
return Boolean(this._resultHandler(
|
|
2946
|
-
return Boolean(this._resultHandler(
|
|
2942
|
+
return Boolean(this._resultHandler(!!result || false));
|
|
2943
|
+
return Boolean(this._resultHandler(!!result || false));
|
|
2947
2944
|
});
|
|
2948
2945
|
}
|
|
2949
2946
|
/**
|
|
@@ -3014,7 +3011,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3014
3011
|
* @returns {Promise<any>} promise
|
|
3015
3012
|
*/
|
|
3016
3013
|
save() {
|
|
3017
|
-
return __awaiter(this,
|
|
3014
|
+
return __awaiter(this, arguments, void 0, function* ({ waitMs = 0 } = {}) {
|
|
3015
|
+
this.$state.set('AFTER_SAVE', waitMs);
|
|
3018
3016
|
switch (this.$state.get('SAVE')) {
|
|
3019
3017
|
case 'INSERT_MULTIPLE': return yield this._insertMultiple();
|
|
3020
3018
|
case 'INSERT': return yield this._insert();
|
|
@@ -3577,12 +3575,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3577
3575
|
});
|
|
3578
3576
|
if (this.$state.get('VOID') || !result)
|
|
3579
3577
|
return this._resultHandler(undefined);
|
|
3580
|
-
|
|
3578
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3579
|
+
const data = yield new Builder()
|
|
3581
3580
|
.copyBuilder(this, { select: true })
|
|
3582
3581
|
.where('id', id)
|
|
3583
|
-
.
|
|
3584
|
-
|
|
3585
|
-
return this._resultHandler((data === null || data === void 0 ? void 0 : data.shift()) || null);
|
|
3582
|
+
.first();
|
|
3583
|
+
return this._resultHandler(data);
|
|
3586
3584
|
}
|
|
3587
3585
|
default: return this._resultHandler(null);
|
|
3588
3586
|
}
|
|
@@ -3596,13 +3594,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3596
3594
|
});
|
|
3597
3595
|
if (this.$state.get('VOID') || !result)
|
|
3598
3596
|
return this._resultHandler(undefined);
|
|
3599
|
-
|
|
3597
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3598
|
+
const results = yield new Builder()
|
|
3600
3599
|
.copyBuilder(this, { select: true })
|
|
3601
3600
|
.where('id', id)
|
|
3602
|
-
.
|
|
3603
|
-
|
|
3604
|
-
const resultData = (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
3605
|
-
return this._resultHandler(resultData);
|
|
3601
|
+
.first();
|
|
3602
|
+
return this._resultHandler(results);
|
|
3606
3603
|
});
|
|
3607
3604
|
}
|
|
3608
3605
|
_checkValueHasRaw(value) {
|
|
@@ -3638,12 +3635,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3638
3635
|
if (this.$state.get('VOID') || !result)
|
|
3639
3636
|
return this._resultHandler(undefined);
|
|
3640
3637
|
const arrayId = [...Array(result)].map((_, i) => i + id);
|
|
3641
|
-
|
|
3642
|
-
|
|
3638
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3639
|
+
const resultData = yield new Builder()
|
|
3640
|
+
.copyBuilder(this, { select: true, limit: true })
|
|
3643
3641
|
.whereIn('id', arrayId)
|
|
3644
|
-
.
|
|
3645
|
-
const data = yield this._queryStatement(sql);
|
|
3646
|
-
const resultData = data || null;
|
|
3642
|
+
.get();
|
|
3647
3643
|
return this._resultHandler(resultData);
|
|
3648
3644
|
});
|
|
3649
3645
|
}
|
|
@@ -3673,12 +3669,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3673
3669
|
});
|
|
3674
3670
|
if (this.$state.get('VOID') || !result)
|
|
3675
3671
|
return this._resultHandler(undefined);
|
|
3676
|
-
|
|
3672
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3673
|
+
const data = yield new Builder()
|
|
3677
3674
|
.copyBuilder(this, { select: true })
|
|
3678
3675
|
.where('id', id)
|
|
3679
|
-
.
|
|
3680
|
-
const
|
|
3681
|
-
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'insert' }) || null;
|
|
3676
|
+
.first();
|
|
3677
|
+
const resultData = data == null ? null : Object.assign(Object.assign({}, data), { $action: 'insert' });
|
|
3682
3678
|
return this._resultHandler(resultData);
|
|
3683
3679
|
}
|
|
3684
3680
|
case true: {
|
|
@@ -3692,7 +3688,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3692
3688
|
}
|
|
3693
3689
|
return this._resultHandler(data || []);
|
|
3694
3690
|
}
|
|
3695
|
-
const resultData = Object.assign(Object.assign({}, data
|
|
3691
|
+
const resultData = Object.assign(Object.assign({}, data[0]), { $action: 'select' });
|
|
3696
3692
|
return this._resultHandler(resultData);
|
|
3697
3693
|
}
|
|
3698
3694
|
default: {
|
|
@@ -3727,12 +3723,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3727
3723
|
});
|
|
3728
3724
|
if (this.$state.get('VOID') || !result)
|
|
3729
3725
|
return this._resultHandler(undefined);
|
|
3730
|
-
|
|
3726
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3727
|
+
const data = yield new Builder()
|
|
3731
3728
|
.copyBuilder(this, { select: true })
|
|
3732
3729
|
.where('id', id)
|
|
3733
|
-
.
|
|
3734
|
-
const
|
|
3735
|
-
const resultData = Object.assign(Object.assign({}, data === null || data === void 0 ? void 0 : data.shift()), { $action: 'insert' }) || null;
|
|
3730
|
+
.first();
|
|
3731
|
+
const resultData = data == null ? null : Object.assign(Object.assign({}, data), { $action: 'insert' });
|
|
3736
3732
|
return this._resultHandler(resultData);
|
|
3737
3733
|
}
|
|
3738
3734
|
case true: {
|
|
@@ -3741,6 +3737,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3741
3737
|
});
|
|
3742
3738
|
if (this.$state.get('VOID') || !result)
|
|
3743
3739
|
return this._resultHandler(null);
|
|
3740
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3744
3741
|
const data = yield this._queryStatement(new Builder().copyBuilder(this, { select: true, where: true }).toString());
|
|
3745
3742
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
3746
3743
|
for (const val of data) {
|
|
@@ -3748,7 +3745,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3748
3745
|
}
|
|
3749
3746
|
return this._resultHandler(data || []);
|
|
3750
3747
|
}
|
|
3751
|
-
const resultData = Object.assign(Object.assign({}, data
|
|
3748
|
+
const resultData = Object.assign(Object.assign({}, data[0]), { $action: 'update' });
|
|
3752
3749
|
return this._resultHandler(resultData);
|
|
3753
3750
|
}
|
|
3754
3751
|
default: {
|
|
@@ -3766,6 +3763,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3766
3763
|
});
|
|
3767
3764
|
if (this.$state.get('VOID') || !result)
|
|
3768
3765
|
return this._resultHandler(undefined);
|
|
3766
|
+
yield this.$utils.wait(this.$state.get('AFTER_SAVE'));
|
|
3769
3767
|
const sql = this._queryBuilder().select();
|
|
3770
3768
|
const data = yield this._queryStatement(sql);
|
|
3771
3769
|
if ((data === null || data === void 0 ? void 0 : data.length) > 1)
|