tspace-mysql 1.5.0 → 1.5.2
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 +1856 -701
- package/build/cli/dump/db.js +3 -2
- package/build/cli/generate/make.js +17 -15
- package/build/cli/generate/modelDecorator.d.ts +1 -1
- package/build/cli/generate/modelDecorator.js +2 -3
- package/build/cli/index.js +45 -27
- package/build/cli/migrate/make.d.ts +1 -1
- package/build/cli/migrate/make.js +2 -2
- package/build/cli/migrations/make-db.d.ts +4 -0
- package/build/cli/migrations/make-db.js +58 -0
- package/build/cli/migrations/make.d.ts +2 -0
- package/build/cli/migrations/make.js +201 -0
- package/build/lib/Interface.d.ts +24 -5
- package/build/lib/connection/index.d.ts +5 -1
- package/build/lib/connection/index.js +65 -8
- package/build/lib/connection/options.js +2 -2
- package/build/lib/constants/index.js +13 -3
- package/build/lib/{tspace → core}/Abstracts/AbstractBuilder.d.ts +1 -1
- package/build/lib/{tspace → core}/Abstracts/AbstractModel.d.ts +15 -13
- package/build/lib/{tspace → core}/Blueprint.d.ts +14 -3
- package/build/lib/{tspace → core}/Blueprint.js +30 -4
- package/build/lib/{tspace → core}/Builder.d.ts +140 -44
- package/build/lib/{tspace → core}/Builder.js +772 -459
- package/build/lib/{tspace → core}/DB.d.ts +20 -4
- package/build/lib/{tspace → core}/DB.js +73 -39
- package/build/lib/{tspace → core}/Decorator.js +2 -2
- package/build/lib/{tspace → core/Handlers}/Logger.d.ts +3 -3
- package/build/lib/{tspace → core/Handlers}/Logger.js +4 -4
- package/build/lib/{tspace → core}/Handlers/Proxy.js +2 -2
- package/build/lib/{tspace → core}/Handlers/Relation.d.ts +2 -4
- package/build/lib/{tspace → core}/Handlers/Relation.js +69 -48
- package/build/lib/{tspace → core}/Handlers/State.d.ts +1 -1
- package/build/lib/{tspace → core}/Handlers/State.js +3 -3
- package/build/lib/{tspace → core}/Model.d.ts +358 -133
- package/build/lib/{tspace → core}/Model.js +1316 -558
- package/build/lib/core/Schema.d.ts +137 -0
- package/build/lib/{tspace → core}/Schema.js +147 -52
- package/build/lib/core/Type.d.ts +6 -0
- package/build/lib/core/Type.js +2 -0
- package/build/lib/{tspace → core}/index.d.ts +2 -1
- package/build/lib/{tspace → core}/index.js +3 -2
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.js +2 -2
- package/build/lib/utils/index.d.ts +1 -0
- package/build/lib/utils/index.js +17 -7
- package/package.json +6 -4
- package/build/lib/tspace/Schema.d.ts +0 -70
- /package/build/lib/{tspace → core}/Abstracts/AbstractBuilder.js +0 -0
- /package/build/lib/{tspace → core}/Abstracts/AbstractDB.d.ts +0 -0
- /package/build/lib/{tspace → core}/Abstracts/AbstractDB.js +0 -0
- /package/build/lib/{tspace → core}/Abstracts/AbstractModel.js +0 -0
- /package/build/lib/{tspace → core}/Decorator.d.ts +0 -0
- /package/build/lib/{tspace → core}/Handlers/Proxy.d.ts +0 -0
|
@@ -22,8 +22,8 @@ class RelationHandler {
|
|
|
22
22
|
this.$logger = this.MODEL["$logger"];
|
|
23
23
|
}
|
|
24
24
|
load(parents, relation) {
|
|
25
|
-
var _a;
|
|
26
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
27
27
|
const relationIsBelongsToMany = relation.relation === this.$constants('RELATIONSHIP').belongsToMany;
|
|
28
28
|
if (relationIsBelongsToMany) {
|
|
29
29
|
return yield this._belongsToMany(parents, relation);
|
|
@@ -40,8 +40,6 @@ class RelationHandler {
|
|
|
40
40
|
})
|
|
41
41
|
.filter(d => d != null);
|
|
42
42
|
const parentIds = Array.from(new Set(localKeyId)) || [];
|
|
43
|
-
if (!parentIds.length && this._getState('RELATIONS_EXISTS'))
|
|
44
|
-
return [];
|
|
45
43
|
const query = relation.query;
|
|
46
44
|
this._assertError(query == null, `Unknown callback query in [Relation : ${relation.name}]`);
|
|
47
45
|
if (relation.count) {
|
|
@@ -49,7 +47,7 @@ class RelationHandler {
|
|
|
49
47
|
.whereIn(foreignKey, parentIds)
|
|
50
48
|
.select(foreignKey)
|
|
51
49
|
.selectRaw(`${this.$constants('COUNT')}(${foreignKey}) ${this.$constants('AS')} \`aggregate\``)
|
|
52
|
-
.debug(this.
|
|
50
|
+
.debug(this.MODEL['$state'].get('DEBUG'))
|
|
53
51
|
.when(relation.trashed, (query) => query.onlyTrashed())
|
|
54
52
|
.when(relation.all, (query) => query.disableSoftDelete())
|
|
55
53
|
.bind(this.MODEL['$pool'].get())
|
|
@@ -59,7 +57,7 @@ class RelationHandler {
|
|
|
59
57
|
}
|
|
60
58
|
const results = yield query
|
|
61
59
|
.whereIn(foreignKey, parentIds)
|
|
62
|
-
.debug(this.
|
|
60
|
+
.debug(this.MODEL['$state'].get('DEBUG'))
|
|
63
61
|
.when(relation.trashed, (query) => query.onlyTrashed())
|
|
64
62
|
.when(relation.all, (query) => query.disableSoftDelete())
|
|
65
63
|
.bind(this.MODEL['$pool'].get())
|
|
@@ -69,7 +67,7 @@ class RelationHandler {
|
|
|
69
67
|
}
|
|
70
68
|
loadExists() {
|
|
71
69
|
var _a, _b, _c;
|
|
72
|
-
const relations = this.
|
|
70
|
+
const relations = this.MODEL['$state'].get('RELATIONS');
|
|
73
71
|
for (const index in relations) {
|
|
74
72
|
const relation = relations[index];
|
|
75
73
|
if (!((_a = Object.keys(relation)) === null || _a === void 0 ? void 0 : _a.length))
|
|
@@ -80,7 +78,7 @@ class RelationHandler {
|
|
|
80
78
|
const query = relation.query;
|
|
81
79
|
this._assertError(query == null, `Unknown callback query in [Relation : '${relation.name}']`);
|
|
82
80
|
let clone = new Model_1.Model().clone(query);
|
|
83
|
-
const cloneRelations = clone['
|
|
81
|
+
const cloneRelations = clone['$state'].get('RELATIONS');
|
|
84
82
|
if (cloneRelations.length) {
|
|
85
83
|
for (const r of cloneRelations) {
|
|
86
84
|
if (!r.exists)
|
|
@@ -112,7 +110,7 @@ class RelationHandler {
|
|
|
112
110
|
const sql = clone
|
|
113
111
|
.bind(this.MODEL['$pool'].get())
|
|
114
112
|
.selectRaw("1")
|
|
115
|
-
.whereReference(`\`${this.MODEL
|
|
113
|
+
.whereReference(`\`${this.MODEL.getTableName()}\`.\`${localKey}\``, `\`${query.getTableName()}\`.\`${foreignKey}\``)
|
|
116
114
|
.toString();
|
|
117
115
|
this.MODEL['whereExists'](sql);
|
|
118
116
|
}
|
|
@@ -122,10 +120,11 @@ class RelationHandler {
|
|
|
122
120
|
apply(nameRelations, type) {
|
|
123
121
|
const relations = nameRelations.map((name) => {
|
|
124
122
|
var _a, _b, _c;
|
|
125
|
-
const relation = (_a = this.
|
|
123
|
+
const relation = (_a = this.MODEL['$state'].get('RELATION')) === null || _a === void 0 ? void 0 : _a.find((data) => data.name === name);
|
|
126
124
|
this._assertError(relation == null, `The relation '${name}' is not registered in the model '${(_b = this.MODEL.constructor) === null || _b === void 0 ? void 0 : _b.name}'.`);
|
|
127
125
|
const relationHasExists = (_c = Object.values(this.$constants('RELATIONSHIP'))) === null || _c === void 0 ? void 0 : _c.includes(relation.relation);
|
|
128
126
|
this._assertError(!relationHasExists, `Unknown relationship in [${this.$constants('RELATIONSHIP')}] !`);
|
|
127
|
+
this._assertError(relation.model == null, `The model is not found'.`);
|
|
129
128
|
if (relation.query == null)
|
|
130
129
|
relation.query = new relation.model();
|
|
131
130
|
return relation;
|
|
@@ -135,19 +134,19 @@ class RelationHandler {
|
|
|
135
134
|
break;
|
|
136
135
|
relation[type] = true;
|
|
137
136
|
}
|
|
138
|
-
return this.
|
|
137
|
+
return this.MODEL['$state'].get('RELATIONS').length
|
|
139
138
|
? [...relations.map((w) => {
|
|
140
|
-
const exists = this.
|
|
139
|
+
const exists = this.MODEL['$state'].get('RELATIONS').find((r) => r.name === w.name);
|
|
141
140
|
if (exists)
|
|
142
141
|
return null;
|
|
143
142
|
return w;
|
|
144
143
|
}).filter((d) => d != null),
|
|
145
|
-
...this.
|
|
144
|
+
...this.MODEL['$state'].get('RELATIONS')]
|
|
146
145
|
: relations;
|
|
147
146
|
}
|
|
148
147
|
callback(nameRelation, cb) {
|
|
149
148
|
var _a, _b;
|
|
150
|
-
const relation = this.
|
|
149
|
+
const relation = this.MODEL['$state'].get('RELATIONS').find((data) => data.name === nameRelation);
|
|
151
150
|
this._assertError(relation == null, `This Relation "${nameRelation}" not be register in Model "${(_a = this.MODEL.constructor) === null || _a === void 0 ? void 0 : _a.name}"`);
|
|
152
151
|
const relationHasExists = (_b = Object.values(this.$constants('RELATIONSHIP'))) === null || _b === void 0 ? void 0 : _b.includes(relation.relation);
|
|
153
152
|
this._assertError(!relationHasExists, `unknown relationship in [${this.$constants('RELATIONSHIP')}] !`);
|
|
@@ -165,7 +164,7 @@ class RelationHandler {
|
|
|
165
164
|
freezeTable,
|
|
166
165
|
query: null
|
|
167
166
|
};
|
|
168
|
-
return this.
|
|
167
|
+
return this.MODEL['$state'].set('RELATION', [...this.MODEL['$state'].get('RELATION'), relation]);
|
|
169
168
|
}
|
|
170
169
|
hasMany({ name, as, model, localKey, foreignKey, freezeTable }) {
|
|
171
170
|
const relation = {
|
|
@@ -178,7 +177,7 @@ class RelationHandler {
|
|
|
178
177
|
freezeTable,
|
|
179
178
|
query: null
|
|
180
179
|
};
|
|
181
|
-
return this.
|
|
180
|
+
return this.MODEL['$state'].set('RELATION', [...this.MODEL['$state'].get('RELATION'), relation]);
|
|
182
181
|
}
|
|
183
182
|
belongsTo({ name, as, model, localKey, foreignKey, freezeTable }) {
|
|
184
183
|
const relation = {
|
|
@@ -191,7 +190,11 @@ class RelationHandler {
|
|
|
191
190
|
freezeTable,
|
|
192
191
|
query: null
|
|
193
192
|
};
|
|
194
|
-
return this.
|
|
193
|
+
return this.MODEL['$state']
|
|
194
|
+
.set('RELATION', [
|
|
195
|
+
...this.MODEL['$state'].get('RELATION'),
|
|
196
|
+
relation
|
|
197
|
+
]);
|
|
195
198
|
}
|
|
196
199
|
belongsToMany({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }) {
|
|
197
200
|
const relation = {
|
|
@@ -207,7 +210,11 @@ class RelationHandler {
|
|
|
207
210
|
query: null,
|
|
208
211
|
modelPivot
|
|
209
212
|
};
|
|
210
|
-
return this.
|
|
213
|
+
return this.MODEL['$state']
|
|
214
|
+
.set('RELATION', [
|
|
215
|
+
...this.MODEL['$state'].get('RELATION'),
|
|
216
|
+
relation
|
|
217
|
+
]);
|
|
211
218
|
}
|
|
212
219
|
hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable, }, callback) {
|
|
213
220
|
const nameRelation = name == null
|
|
@@ -305,7 +312,7 @@ class RelationHandler {
|
|
|
305
312
|
const query = relation.query;
|
|
306
313
|
this._assertError(query == null, `Unknown callback query in [Relation : '${relation.name}']`);
|
|
307
314
|
const clone = new Model_1.Model().clone(query);
|
|
308
|
-
const cloneRelations = clone['
|
|
315
|
+
const cloneRelations = clone['$state'].get('RELATIONS');
|
|
309
316
|
if (cloneRelations.length) {
|
|
310
317
|
for (const r of cloneRelations) {
|
|
311
318
|
if (!r.exists)
|
|
@@ -353,9 +360,9 @@ class RelationHandler {
|
|
|
353
360
|
}
|
|
354
361
|
_relationBuilder(nameRelation, relation) {
|
|
355
362
|
var _a;
|
|
356
|
-
this.
|
|
363
|
+
this.MODEL['$state'].set('RELATION', [...this.MODEL['$state'].get('RELATION'), relation]);
|
|
357
364
|
this.MODEL['with'](nameRelation);
|
|
358
|
-
const r = this.
|
|
365
|
+
const r = this.MODEL['$state'].get('RELATIONS').find((data) => data.name === nameRelation);
|
|
359
366
|
this._assertError(relation == null, `The relation '${nameRelation}' is not registered in the model '${(_a = this.MODEL.constructor) === null || _a === void 0 ? void 0 : _a.name}'.`);
|
|
360
367
|
return r;
|
|
361
368
|
}
|
|
@@ -365,8 +372,10 @@ class RelationHandler {
|
|
|
365
372
|
}
|
|
366
373
|
_relationMapData(dataParents, dataChilds, r) {
|
|
367
374
|
var _a;
|
|
368
|
-
|
|
375
|
+
let { name, as, query, relation, localKey, foreignKey } = this._valueInRelation(r);
|
|
369
376
|
const keyRelation = as !== null && as !== void 0 ? as : name;
|
|
377
|
+
localKey = query == null ? localKey : query.covertFixColumnToColumnSchema(localKey);
|
|
378
|
+
foreignKey = query == null ? foreignKey : query.covertFixColumnToColumnSchema(foreignKey);
|
|
370
379
|
for (const dataParent of dataParents) {
|
|
371
380
|
const relationIsHasOneOrBelongsTo = [
|
|
372
381
|
this.$constants('RELATIONSHIP').hasOne,
|
|
@@ -400,8 +409,8 @@ class RelationHandler {
|
|
|
400
409
|
return dataParents;
|
|
401
410
|
}
|
|
402
411
|
_belongsToMany(parents, relation) {
|
|
403
|
-
var _a, _b;
|
|
404
412
|
return __awaiter(this, void 0, void 0, function* () {
|
|
413
|
+
var _a, _b;
|
|
405
414
|
const { name, foreignKey, localKey, pivot, oldVersion, modelPivot } = this._valueInRelation(relation);
|
|
406
415
|
const localKeyId = parents.map((parent) => {
|
|
407
416
|
const data = parent[foreignKey];
|
|
@@ -410,9 +419,7 @@ class RelationHandler {
|
|
|
410
419
|
this._assertError(data == null, `This relationship lacks a primary or foreign key in the '${relation === null || relation === void 0 ? void 0 : relation.name}' relation. Please review the query to identify whether the key '${localKey}' or '${foreignKey}' is missing.`);
|
|
411
420
|
}).filter((d) => d != null);
|
|
412
421
|
const mainResultIds = Array.from(new Set(localKeyId));
|
|
413
|
-
|
|
414
|
-
return [];
|
|
415
|
-
const modelRelation = new relation.model();
|
|
422
|
+
const modelRelation = relation.query == null ? new relation.model() : relation.query;
|
|
416
423
|
const relationColumn = this.MODEL['_classToTableName'](modelRelation.constructor.name, { singular: true });
|
|
417
424
|
const mainlocalKey = 'id';
|
|
418
425
|
const relationForeignKey = this._valuePattern(`${relationColumn}Id`);
|
|
@@ -436,7 +443,7 @@ class RelationHandler {
|
|
|
436
443
|
.when(relation.all, (query) => query.disableSoftDelete())
|
|
437
444
|
.groupBy(localKeyPivotTable)
|
|
438
445
|
.bind(this.MODEL['$pool'].get())
|
|
439
|
-
.debug(this.
|
|
446
|
+
.debug(this.MODEL['$state'].get('DEBUG'))
|
|
440
447
|
.get();
|
|
441
448
|
for (const parent of parents) {
|
|
442
449
|
if (parent[name] == null)
|
|
@@ -447,17 +454,18 @@ class RelationHandler {
|
|
|
447
454
|
parent[name] = (_b = pivotResult.aggregate) !== null && _b !== void 0 ? _b : 0;
|
|
448
455
|
}
|
|
449
456
|
}
|
|
450
|
-
if (this.
|
|
457
|
+
if (this.MODEL['$state'].get('HIDDEN').length)
|
|
451
458
|
this.MODEL['_hiddenColumnModel'](parents);
|
|
452
459
|
return parents;
|
|
453
460
|
}
|
|
454
461
|
const pivotResults = yield queryPivot
|
|
455
462
|
.whereIn(localKeyPivotTable, mainResultIds)
|
|
463
|
+
.when(relation.query != null, (query) => query.select(localKeyPivotTable, localKey))
|
|
456
464
|
.when(relation.exists, (query) => query.whereExists(sqlPivotExists))
|
|
457
465
|
.when(relation.trashed, (query) => query.onlyTrashed())
|
|
458
466
|
.when(relation.all, (query) => query.disableSoftDelete())
|
|
459
467
|
.bind(this.MODEL['$pool'].get())
|
|
460
|
-
.debug(this.
|
|
468
|
+
.debug(this.MODEL['$state'].get('DEBUG'))
|
|
461
469
|
.get();
|
|
462
470
|
const relationIds = Array.from(new Set(pivotResults
|
|
463
471
|
.map((pivotResult) => pivotResult[relationForeignKey])
|
|
@@ -483,7 +491,7 @@ class RelationHandler {
|
|
|
483
491
|
parent[name].push(pivotResult);
|
|
484
492
|
}
|
|
485
493
|
}
|
|
486
|
-
if (this.
|
|
494
|
+
if (this.MODEL['$state'].get('HIDDEN').length)
|
|
487
495
|
this.MODEL['_hiddenColumnModel'](parents);
|
|
488
496
|
return parents;
|
|
489
497
|
}
|
|
@@ -503,34 +511,35 @@ class RelationHandler {
|
|
|
503
511
|
parent[name].push(data);
|
|
504
512
|
}
|
|
505
513
|
}
|
|
506
|
-
if (this.
|
|
514
|
+
if (this.MODEL['$state'].get('HIDDEN').length)
|
|
507
515
|
this.MODEL['_hiddenColumnModel'](parents);
|
|
508
516
|
return parents;
|
|
509
517
|
});
|
|
510
518
|
}
|
|
511
519
|
_valueInRelation(relationModel) {
|
|
512
|
-
var _a, _b
|
|
520
|
+
var _a, _b;
|
|
513
521
|
this._assertError((relationModel === null || relationModel === void 0 ? void 0 : relationModel.query) instanceof Promise, 'The Promise method does not support nested relations.');
|
|
514
522
|
this._assertError(!((relationModel === null || relationModel === void 0 ? void 0 : relationModel.query) instanceof Model_1.Model), 'The callback function only supports instances of the Model class.');
|
|
515
523
|
const relation = relationModel.relation;
|
|
516
|
-
const model =
|
|
524
|
+
const model = relationModel.model;
|
|
517
525
|
const modelPivot = relationModel.modelPivot;
|
|
518
526
|
const oldVersion = relationModel.oldVersion;
|
|
527
|
+
const query = relationModel === null || relationModel === void 0 ? void 0 : relationModel.query;
|
|
519
528
|
const table = relationModel.freezeTable
|
|
520
529
|
? relationModel.freezeTable
|
|
521
|
-
: (
|
|
530
|
+
: (_a = relationModel.query) === null || _a === void 0 ? void 0 : _a.getTableName();
|
|
522
531
|
let pivot = null;
|
|
523
532
|
const name = relationModel.name;
|
|
524
533
|
const as = relationModel.as;
|
|
525
534
|
this._assertError(!model || model == null, 'Model not found.');
|
|
526
535
|
let localKey = this._valuePattern(relationModel.localKey
|
|
527
536
|
? relationModel.localKey
|
|
528
|
-
: this.
|
|
537
|
+
: this.MODEL['$state'].get('PRIMARY_KEY'));
|
|
529
538
|
let foreignKey = relationModel.foreignKey
|
|
530
539
|
? relationModel.foreignKey
|
|
531
540
|
: this._valuePattern([
|
|
532
541
|
`${pluralize_1.default.singular(this.MODEL['getTableName']())}`,
|
|
533
|
-
`${this.
|
|
542
|
+
`${this.MODEL['$state'].get('PRIMARY_KEY')}`
|
|
534
543
|
].join('_'));
|
|
535
544
|
const checkRelationIsBelongsTo = [
|
|
536
545
|
relationModel.localKey == null,
|
|
@@ -538,10 +547,10 @@ class RelationHandler {
|
|
|
538
547
|
relation === this.$constants('RELATIONSHIP').belongsTo
|
|
539
548
|
].every(r => r);
|
|
540
549
|
if (checkRelationIsBelongsTo) {
|
|
541
|
-
foreignKey = localKey;
|
|
550
|
+
foreignKey = this._valuePattern(localKey);
|
|
542
551
|
localKey = this._valuePattern([
|
|
543
552
|
`${pluralize_1.default.singular(table !== null && table !== void 0 ? table : '')}`,
|
|
544
|
-
`${this.
|
|
553
|
+
`${this.MODEL['$state'].get('PRIMARY_KEY')}`
|
|
545
554
|
].join('_'));
|
|
546
555
|
}
|
|
547
556
|
const checkRelationIsBelongsToMany = [
|
|
@@ -552,15 +561,17 @@ class RelationHandler {
|
|
|
552
561
|
if (checkRelationIsBelongsToMany) {
|
|
553
562
|
localKey = this._valuePattern([
|
|
554
563
|
`${pluralize_1.default.singular(table !== null && table !== void 0 ? table : '')}`,
|
|
555
|
-
`${this.
|
|
564
|
+
`${this.MODEL['$state'].get('PRIMARY_KEY')}`
|
|
556
565
|
].join('_'));
|
|
557
566
|
foreignKey = 'id';
|
|
558
567
|
const pivotModel = relationModel.query;
|
|
559
|
-
pivot = (
|
|
568
|
+
pivot = (_b = relationModel.pivot) !== null && _b !== void 0 ? _b : this._valuePattern([
|
|
560
569
|
pluralize_1.default.singular(this.MODEL['getTableName']()),
|
|
561
570
|
pluralize_1.default.singular(pivotModel.getTableName())
|
|
562
571
|
].sort().join('_'));
|
|
563
572
|
}
|
|
573
|
+
foreignKey = this.MODEL.covertColumnSchemaToFixColumn(foreignKey);
|
|
574
|
+
localKey = this.MODEL.covertColumnSchemaToFixColumn(localKey);
|
|
564
575
|
return {
|
|
565
576
|
name,
|
|
566
577
|
as,
|
|
@@ -569,18 +580,34 @@ class RelationHandler {
|
|
|
569
580
|
localKey,
|
|
570
581
|
foreignKey,
|
|
571
582
|
model,
|
|
583
|
+
query,
|
|
572
584
|
pivot,
|
|
573
585
|
oldVersion,
|
|
574
586
|
modelPivot
|
|
575
587
|
};
|
|
576
588
|
}
|
|
577
589
|
_valuePattern(value) {
|
|
578
|
-
|
|
590
|
+
const schema = this.MODEL['$state'].get('SCHEMA_TABLE');
|
|
591
|
+
switch (this.MODEL['$state'].get('PATTERN')) {
|
|
579
592
|
case this.$constants('PATTERN').snake_case: {
|
|
580
|
-
|
|
593
|
+
if (schema == null) {
|
|
594
|
+
return value.replace(/([A-Z])/g, (str) => `_${str.toLowerCase()}`);
|
|
595
|
+
}
|
|
596
|
+
const find = schema[value];
|
|
597
|
+
if (find == null || find.column == null) {
|
|
598
|
+
return value.replace(/([A-Z])/g, (str) => `_${str.toLowerCase()}`);
|
|
599
|
+
}
|
|
600
|
+
return find.column;
|
|
581
601
|
}
|
|
582
602
|
case this.$constants('PATTERN').camelCase: {
|
|
583
|
-
|
|
603
|
+
if (schema == null) {
|
|
604
|
+
return value.replace(/(.(\_|-|\s)+.)/g, (str) => `${str[0]}${str[str.length - 1].toUpperCase()}`);
|
|
605
|
+
}
|
|
606
|
+
const find = schema[value];
|
|
607
|
+
if (find == null || find.column == null) {
|
|
608
|
+
return value.replace(/(.(\_|-|\s)+.)/g, (str) => `${str[0]}${str[str.length - 1].toUpperCase()}`);
|
|
609
|
+
}
|
|
610
|
+
return find.column;
|
|
584
611
|
}
|
|
585
612
|
default: return value;
|
|
586
613
|
}
|
|
@@ -593,12 +620,6 @@ class RelationHandler {
|
|
|
593
620
|
throw new Error(message);
|
|
594
621
|
return;
|
|
595
622
|
}
|
|
596
|
-
_getState(key) {
|
|
597
|
-
return this.MODEL['_getState'](key.toLocaleUpperCase());
|
|
598
|
-
}
|
|
599
|
-
_setState(key, value) {
|
|
600
|
-
return this.MODEL['_setState'](key, value);
|
|
601
|
-
}
|
|
602
623
|
}
|
|
603
624
|
exports.RelationHandler = RelationHandler;
|
|
604
625
|
exports.default = RelationHandler;
|
|
@@ -21,18 +21,18 @@ class StateHandler {
|
|
|
21
21
|
if (key == null)
|
|
22
22
|
return this.STATE.currentState;
|
|
23
23
|
this._assertError(!this.STATE.currentState.has(key) && key !== 'DEBUG', `Can't get this [ ${key} ]`);
|
|
24
|
-
return this.STATE.currentState.get(key);
|
|
24
|
+
return this.STATE.currentState.get(key.toUpperCase());
|
|
25
25
|
}
|
|
26
26
|
set(key, value) {
|
|
27
27
|
this._assertError(!this.STATE.currentState.has(key), `Can't set this [ ${key} ]`);
|
|
28
|
-
this.STATE.currentState.set(key, value);
|
|
28
|
+
this.STATE.currentState.set(key.toUpperCase(), value);
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
clone(data) {
|
|
32
32
|
this.STATE.currentState = new Map(Object.entries(Object.assign({}, data)));
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
reset() {
|
|
36
36
|
this.STATE.currentState.set('INSERT', '');
|
|
37
37
|
this.STATE.currentState.set('UPDATE', '');
|
|
38
38
|
this.STATE.currentState.set('DELETE', '');
|