@iamkirbki/database-handler-core 4.4.3 → 4.4.5

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.
Files changed (28) hide show
  1. package/dist/abstract/Controller.js +18 -39
  2. package/dist/abstract/Model.d.ts.map +1 -1
  3. package/dist/abstract/Model.js +100 -98
  4. package/dist/abstract/SchemaTableBuilder.js +4 -1
  5. package/dist/abstract/model/ModelRelation.d.ts +4 -4
  6. package/dist/abstract/model/ModelRelation.d.ts.map +1 -1
  7. package/dist/abstract/model/ModelRelation.js +47 -49
  8. package/dist/base/Query.js +56 -79
  9. package/dist/base/Record.js +75 -90
  10. package/dist/base/Table.d.ts.map +1 -1
  11. package/dist/base/Table.js +130 -153
  12. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +7 -18
  13. package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +5 -1
  14. package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +7 -18
  15. package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +8 -19
  16. package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +26 -39
  17. package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +9 -20
  18. package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +8 -19
  19. package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +9 -20
  20. package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +87 -101
  21. package/dist/runtime/Repository.d.ts +1 -1
  22. package/dist/runtime/Repository.d.ts.map +1 -1
  23. package/dist/runtime/Repository.js +98 -102
  24. package/dist/types/model.d.ts +3 -0
  25. package/dist/types/model.d.ts.map +1 -1
  26. package/dist/types/table.d.ts +1 -0
  27. package/dist/types/table.d.ts.map +1 -1
  28. package/package.json +1 -1
@@ -1,47 +1,26 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export default class Controller {
11
- static index() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const instance = new this();
14
- return yield instance.index();
15
- });
2
+ static async index() {
3
+ const instance = new this();
4
+ return await instance.index();
16
5
  }
17
- static show(value) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const instance = new this();
20
- return yield instance.show(value);
21
- });
6
+ static async show(value) {
7
+ const instance = new this();
8
+ return await instance.show(value);
22
9
  }
23
- static edit(value) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const instance = new this();
26
- return yield instance.edit(value);
27
- });
10
+ static async edit(value) {
11
+ const instance = new this();
12
+ return await instance.edit(value);
28
13
  }
29
- static update(id, newValues) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const instance = new this();
32
- return yield instance.update(id, newValues);
33
- });
14
+ static async update(id, newValues) {
15
+ const instance = new this();
16
+ return await instance.update(id, newValues);
34
17
  }
35
- static create(data) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const instance = new this();
38
- return yield instance.create(data);
39
- });
18
+ static async create(data) {
19
+ const instance = new this();
20
+ return await instance.create(data);
40
21
  }
41
- static delete(id) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const instance = new this();
44
- return yield instance.delete(id);
45
- });
22
+ static async delete(id) {
23
+ const instance = new this();
24
+ return await instance.delete(id);
46
25
  }
47
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/abstract/Model.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAA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value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import Repository from '../runtime/Repository.js';
11
2
  import ModelRelations from '../abstract/model/ModelRelation.js';
12
3
  import { QueryEvaluationPhase, } from '../types/index.js';
@@ -133,78 +124,86 @@ export default class Model extends ModelRelations {
133
124
  this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }];
134
125
  return this;
135
126
  }
136
- static findOrFail(primaryKeyValue) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- const instance = new this();
139
- return (yield instance.findOrFail(primaryKeyValue));
140
- });
127
+ static async findOrFail(primaryKeyValue) {
128
+ const instance = new this();
129
+ return (await instance.findOrFail(primaryKeyValue));
141
130
  }
142
- findOrFail(primaryKeyValue) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- var _a;
145
- if (primaryKeyValue) {
146
- this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }];
147
- }
148
- const query = this.queryLayers;
149
- const record = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(query, this));
150
- if (!record) {
151
- throw new Error(`Record with primary key ${primaryKeyValue} not found.`);
152
- }
153
- this.attributes = record;
154
- this.originalAttributes = Object.assign({}, this.attributes);
155
- this.exists = true;
156
- return this;
157
- });
131
+ async findOrFail(primaryKeyValue) {
132
+ var _a;
133
+ if (primaryKeyValue) {
134
+ this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }];
135
+ }
136
+ this.queryLayers.base.from = this.Configuration.table;
137
+ const query = this.queryLayers;
138
+ const record = await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(query, this));
139
+ if (!record) {
140
+ throw new Error(`Record with primary key ${primaryKeyValue} not found.`);
141
+ }
142
+ this.attributes = record;
143
+ this.originalAttributes = { ...this.attributes };
144
+ this.exists = true;
145
+ return this;
158
146
  }
159
- static first(primaryKeyValue) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- const instance = new this();
162
- return instance.first(primaryKeyValue);
163
- });
147
+ static async first(primaryKeyValue) {
148
+ const instance = new this();
149
+ return instance.first(primaryKeyValue);
164
150
  }
165
- first(primaryKeyValue) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- var _a;
168
- if (primaryKeyValue !== undefined) {
169
- this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }, ...this.normalizeConditions(this.queryLayers.base.where || [])];
170
- }
171
- const attributes = (yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table, where: this.normalizeConditions(this.queryLayers.base.where || []) }) }), this)));
172
- if (attributes) {
173
- this.attributes = attributes;
174
- this.originalAttributes = Object.assign({}, attributes);
175
- this.exists = true;
151
+ async first(primaryKeyValue) {
152
+ var _a;
153
+ if (primaryKeyValue !== undefined) {
154
+ this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }, ...this.normalizeConditions(this.queryLayers.base.where || [])];
155
+ }
156
+ const attributes = (await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first({
157
+ ...this.queryLayers,
158
+ base: {
159
+ ...this.queryLayers.base,
160
+ from: this.Configuration.table,
161
+ where: this.normalizeConditions(this.queryLayers.base.where || []),
176
162
  }
177
- return this;
178
- });
163
+ }, this)));
164
+ if (attributes) {
165
+ this.attributes = attributes;
166
+ this.originalAttributes = { ...attributes };
167
+ this.exists = true;
168
+ }
169
+ return this;
179
170
  }
180
- get() {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- const records = yield this.repository.get(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }), this);
183
- return records.map((record) => {
184
- const instance = new this.constructor();
185
- instance.set(record);
186
- instance.exists = true;
187
- instance.originalAttributes = Object.assign({}, record);
188
- instance.attributes = Object.assign({}, record);
189
- return instance;
190
- });
171
+ async get() {
172
+ const records = await this.repository.get({
173
+ ...this.queryLayers,
174
+ base: {
175
+ ...this.queryLayers.base,
176
+ from: this.Configuration.table,
177
+ }
178
+ }, this);
179
+ return records.map((record) => {
180
+ const instance = new this.constructor();
181
+ instance.set(record);
182
+ instance.exists = true;
183
+ instance.originalAttributes = { ...record };
184
+ instance.attributes = { ...record };
185
+ return instance;
191
186
  });
192
187
  }
193
188
  static all() {
194
189
  const instance = new this();
195
190
  return instance.all();
196
191
  }
197
- all() {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- const records = yield this.repository.all(this, Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }));
200
- return records.map((record) => {
201
- const instance = new this.constructor();
202
- instance.set(record);
203
- instance.exists = true;
204
- instance.originalAttributes = Object.assign({}, record);
205
- instance.attributes = Object.assign({}, record);
206
- return instance;
207
- });
192
+ async all() {
193
+ const records = await this.repository.all(this, {
194
+ ...this.queryLayers,
195
+ base: {
196
+ ...this.queryLayers.base,
197
+ from: this.Configuration.table,
198
+ }
199
+ });
200
+ return records.map((record) => {
201
+ const instance = new this.constructor();
202
+ instance.set(record);
203
+ instance.exists = true;
204
+ instance.originalAttributes = { ...record };
205
+ instance.attributes = { ...record };
206
+ return instance;
208
207
  });
209
208
  }
210
209
  static set(attributes) {
@@ -215,32 +214,31 @@ export default class Model extends ModelRelations {
215
214
  if (attributes[this.primaryKeyColumn] !== undefined && !this.exists) {
216
215
  this.repository.syncModel(this);
217
216
  }
218
- this.attributes = Object.assign(Object.assign({}, this.attributes), attributes);
217
+ this.attributes = { ...this.attributes, ...attributes };
219
218
  this.dirty = true;
220
219
  return this;
221
220
  }
222
- save() {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- this.originalAttributes = Object.assign(Object.assign({}, this.originalAttributes), this.attributes);
225
- yield this.repository.save(this.originalAttributes);
226
- this.exists = true;
227
- this.dirty = false;
228
- return this;
229
- });
221
+ async save() {
222
+ this.originalAttributes = {
223
+ ...this.originalAttributes,
224
+ ...this.attributes,
225
+ };
226
+ await this.repository.save(this.originalAttributes);
227
+ this.exists = true;
228
+ this.dirty = false;
229
+ return this;
230
230
  }
231
- update(attributes) {
232
- return __awaiter(this, void 0, void 0, function* () {
233
- var _a;
234
- if (this.primaryKey === undefined) {
235
- throw new Error('Primary key value is undefined. Cannot update record without a valid primary key.');
236
- }
237
- const newRecord = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.update({ [this.primaryKeyColumn]: this.primaryKey }, attributes));
238
- if (newRecord) {
239
- this.originalAttributes = newRecord.values;
240
- this.exists = true;
241
- }
242
- return this;
243
- });
231
+ async update(attributes) {
232
+ var _a;
233
+ if (this.primaryKey === undefined) {
234
+ throw new Error('Primary key value is undefined. Cannot update record without a valid primary key.');
235
+ }
236
+ const newRecord = await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.update({ [this.primaryKeyColumn]: this.primaryKey }, attributes, this.Configuration.table));
237
+ if (newRecord) {
238
+ this.originalAttributes = newRecord.values;
239
+ this.exists = true;
240
+ }
241
+ return this;
244
242
  }
245
243
  near(params) {
246
244
  var _a;
@@ -347,12 +345,16 @@ export default class Model extends ModelRelations {
347
345
  this.queryLayers.final.blacklistTables.push(...Array.from(new Set(this.collectTables({ table, nested: nested || [] }))));
348
346
  return this;
349
347
  }
350
- toSql() {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- var _a;
353
- const sql = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.toSql(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }), this));
354
- return sql === null || sql === void 0 ? void 0 : sql.replace(/\s+/g, ' ').replace(/\n/g, '');
355
- });
348
+ async toSql() {
349
+ var _a;
350
+ const sql = await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.toSql({
351
+ ...this.queryLayers,
352
+ base: {
353
+ ...this.queryLayers.base,
354
+ from: this.Configuration.table,
355
+ }
356
+ }, this));
357
+ return sql === null || sql === void 0 ? void 0 : sql.replace(/\s+/g, ' ').replace(/\n/g, '');
356
358
  }
357
359
  collectSelectAliases(def) {
358
360
  const columnAliases = def.columns.map(col => `${def.table}.${col} AS ${def.table}_${col}`);
@@ -5,7 +5,10 @@ export default class SchemaTableBuilder {
5
5
  addColumn(data) {
6
6
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
7
7
  if (data.name) {
8
- this.columns.push(Object.assign(Object.assign({}, data), { constraints: ['NOT NULL', ...((_a = data.constraints) !== null && _a !== void 0 ? _a : [])] }));
8
+ this.columns.push({
9
+ ...data,
10
+ constraints: ['NOT NULL', ...((_a = data.constraints) !== null && _a !== void 0 ? _a : [])],
11
+ });
9
12
  }
10
13
  else {
11
14
  const lastColumn = this.columns[this.columns.length - 1];
@@ -10,10 +10,10 @@ export default abstract class ModelRelations<Type extends columnType, Self exten
10
10
  get JoinedEntities(): joinedEntity[];
11
11
  get Relations(): relation[];
12
12
  insertRecordIntoPivotTable(otherTable: string, foreignKey: string): Promise<void>;
13
- protected ManyToMany<modelType extends Model<columnType>>(model: modelType, pivotTable?: string, localKey?: string, foreignKey?: string, pivotForeignKey?: string, pivotLocalKey?: string): Promise<this>;
14
- protected hasMany<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
15
- protected hasOne<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
16
- protected belongsTo<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
13
+ protected ManyToMany<modelType extends Model<columnType>>(model: modelType, pivotTable?: string, localKey?: string, foreignKey?: string, pivotForeignKey?: string, pivotLocalKey?: string, path?: string, name?: string): Promise<this>;
14
+ protected hasMany<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string, path?: string, name?: string): this;
15
+ protected hasOne<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string, path?: string, name?: string): this;
16
+ protected belongsTo<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string, path?: string, name?: string): this;
17
17
  static with<ParameterModelType extends Model<columnType>>(this: new () => ParameterModelType, relation: string, queryScopes?: QueryWhereCondition): ParameterModelType;
18
18
  with(relation: string, queryScopes?: QueryWhereCondition): this;
19
19
  asyncWith(relation: string, queryScopes?: QueryWhereCondition): Promise<this>;
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRelation.d.ts","sourceRoot":"","sources":["../../../src/abstract/model/ModelRelation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAA6B,mBAAmB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvI,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,UAAU,MAAM,6BAA6B,CAAC;AAErD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,cAAc,CACxC,IAAI,SAAS,UAAU,EACvB,IAAI,SAAS,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IAEtC,SAAS,CAAC,cAAc,EAAE,YAAY,EAAE,CAAM;IAC9C,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAM;IAErC,QAAQ,KAAK,aAAa,IAAI,WAAW,CAAC;IAC1C,SAAS,CAAC,QAAQ,KAAK,UAAU,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5D,SAAS,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC;IAEpC,IAAW,cAAc,IAAI,YAAY,EAAE,CAE1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AC,IAAI,CAAC;IAsBhB,SAAS,CAAC,OAAO,CAAC,SAAS,SAAS,KAAK,CAAC,UAAU,CAAC,EACjD,KAAK,EAAE,SAAS,EAChB,UAAU,GAAE,MAAuE,EACnF,QAAQ,GAAE,MAAsC,EAChD,IAAI,GAAE,MAAmE,EACzE,IAAI,GAAE,MAA2B,GAClC,IAAI;IAYP,SAAS,CAAC,MAAM,CAAC,SAAS,SAAS,KAAK,CAAC,UAAU,CAAC,EAChD,KAAK,EAAE,SAAS,EAChB,UAAU,GAAE,MAA4C,EACxD,QAAQ,GAAE,MAAyE,EACnF,IAAI,GAAE,MAAmE,EACzE,IAAI,GAAE,MAA2B,GAClC,IAAI;IAYP,SAAS,CAAC,SAAS,CAAC,SAAS,SAAS,KAAK,CAAC,UAAU,CAAC,EACnD,KAAK,EAAE,SAAS,EAChB,UAAU,GAAE,MAAyE,EACrF,QAAQ,GAAE,MAAuC,EACjD,IAAI,GAAE,MAAmE,EACzE,IAAI,GAAE,MAA2B,GAClC,IAAI;WAYO,IAAI,CAAC,kBAAkB,SAAS,KAAK,CAAC,UAAU,CAAC,EAC3D,IAAI,EAAE,UAAU,kBAAkB,EAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,mBAAmB,GAClC,kBAAkB;IAKd,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAuBzD,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnF,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAYjE,OAAO,CAAC,oBAAoB;CAuB/B"}
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export default class ModelRelations {
11
2
  constructor() {
12
3
  this.joinedEntities = [];
@@ -18,58 +9,62 @@ export default class ModelRelations {
18
9
  get Relations() {
19
10
  return this.relations;
20
11
  }
21
- insertRecordIntoPivotTable(otherTable, foreignKey) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- yield this.callRelationMethod(otherTable);
24
- const relation = this.relations.pop();
25
- if (!relation) {
26
- throw new Error(`Relation for pivot table insertion not found.`);
27
- }
28
- yield this.repository.insertRecordIntoPivotTable(foreignKey, this.self, relation);
29
- });
12
+ async insertRecordIntoPivotTable(otherTable, foreignKey) {
13
+ await this.callRelationMethod(otherTable);
14
+ const relation = this.relations.pop();
15
+ if (!relation) {
16
+ throw new Error(`Relation for pivot table insertion not found.`);
17
+ }
18
+ await this.repository.insertRecordIntoPivotTable(foreignKey, this.self, relation);
30
19
  }
31
- ManyToMany(model_1) {
32
- return __awaiter(this, arguments, void 0, function* (model, pivotTable = [this.Configuration.table, model.Configuration.table].sort().join('_'), localKey = this.Configuration.primaryKey, foreignKey = model.Configuration.primaryKey, pivotForeignKey = `${this.Configuration.table}_${localKey}`, pivotLocalKey = `${model.Configuration.table}_${foreignKey}`) {
33
- const relation = yield this.repository.getManyToManyRelation({
34
- type: 'manyToMany',
35
- model: model,
36
- pivotTable: pivotTable,
37
- foreignKey: foreignKey,
38
- pivotForeignKey: pivotForeignKey,
39
- localKey: localKey,
40
- pivotLocalKey: pivotLocalKey,
41
- });
42
- if (!relation) {
43
- throw new Error(`Failed to create many-to-many relation for model ${model.Configuration.table}`);
44
- }
45
- this.relations.push(relation);
46
- return this;
20
+ async ManyToMany(model, pivotTable = [this.Configuration.table, model.Configuration.table].sort().join('_'), localKey = this.Configuration.primaryKey, foreignKey = model.Configuration.primaryKey, pivotForeignKey = `${this.Configuration.table}_${localKey}`, pivotLocalKey = `${model.Configuration.table}_${foreignKey}`, path = pivotTable, name = path.split('.')[1]) {
21
+ const relation = await this.repository.getManyToManyRelation({
22
+ type: 'manyToMany',
23
+ model: model,
24
+ pivotTable: pivotTable,
25
+ path: path,
26
+ name: name,
27
+ foreignKey: foreignKey,
28
+ pivotForeignKey: pivotForeignKey,
29
+ localKey: localKey,
30
+ pivotLocalKey: pivotLocalKey,
47
31
  });
32
+ if (!relation) {
33
+ throw new Error(`Failed to create many-to-many relation for model ${model.Configuration.table}`);
34
+ }
35
+ this.relations.push(relation);
36
+ return this;
48
37
  }
49
- hasMany(model, foreignKey = `${this.Configuration.table}_${this.Configuration.primaryKey}`, localKey = this.Configuration.primaryKey) {
38
+ hasMany(model, foreignKey = `${this.Configuration.table}_${this.Configuration.primaryKey}`, localKey = this.Configuration.primaryKey, path = `${this.Configuration.table}.${model.Configuration.table}`, name = path.split('.')[1]) {
50
39
  this.relations.push({
51
40
  type: 'hasMany',
52
41
  model: model,
53
42
  foreignKey: foreignKey,
54
43
  localKey: localKey,
44
+ path: path,
45
+ name: name
55
46
  });
56
47
  return this;
57
48
  }
58
- hasOne(model, foreignKey = `${model.Configuration.primaryKey}`, localKey = `${model.Configuration.table}_${model.Configuration.primaryKey}`) {
49
+ hasOne(model, foreignKey = `${model.Configuration.primaryKey}`, localKey = `${model.Configuration.table}_${model.Configuration.primaryKey}`, path = `${this.Configuration.table}.${model.Configuration.table}`, name = path.split('.')[1]) {
59
50
  this.relations.push({
60
51
  type: 'hasOne',
61
52
  model: model,
62
53
  foreignKey: foreignKey,
63
54
  localKey: localKey,
55
+ path: path,
56
+ name: name
64
57
  });
65
58
  return this;
66
59
  }
67
- belongsTo(model, foreignKey = `${model.Configuration.table}_${model.Configuration.primaryKey}`, localKey = model.Configuration.primaryKey) {
60
+ belongsTo(model, foreignKey = `${model.Configuration.table}_${model.Configuration.primaryKey}`, localKey = model.Configuration.primaryKey, path = `${this.Configuration.table}.${model.Configuration.table}`, name = path.split('.')[1]) {
68
61
  this.relations.push({
69
62
  type: 'belongsTo',
70
63
  model: model,
71
64
  foreignKey: foreignKey,
72
65
  localKey: localKey,
66
+ path: path,
67
+ name: name
73
68
  });
74
69
  return this;
75
70
  }
@@ -87,22 +82,22 @@ export default class ModelRelations {
87
82
  const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
88
83
  this.joinedEntities.push({
89
84
  relation: relation,
85
+ path: lastRelation.path,
90
86
  queryScopes: normalizedScopes
91
87
  });
92
88
  return this;
93
89
  }
94
- asyncWith(relation, queryScopes) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- yield this.callRelationMethod(relation);
97
- const lastRelation = this.relations[this.relations.length - 1];
98
- const tableName = lastRelation.model.Configuration.table;
99
- const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
100
- this.joinedEntities.push({
101
- relation: relation,
102
- queryScopes: normalizedScopes
103
- });
104
- return this;
90
+ async asyncWith(relation, queryScopes) {
91
+ await this.callRelationMethod(relation);
92
+ const lastRelation = this.relations[this.relations.length - 1];
93
+ const tableName = lastRelation.model.Configuration.table;
94
+ const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
95
+ this.joinedEntities.push({
96
+ relation: relation,
97
+ path: lastRelation.path,
98
+ queryScopes: normalizedScopes
105
99
  });
100
+ return this;
106
101
  }
107
102
  callRelationMethod(relation) {
108
103
  const method = Reflect.get(this, relation);
@@ -125,6 +120,9 @@ export default class ModelRelations {
125
120
  const scopesArray = isSingleParameter
126
121
  ? [queryScopes]
127
122
  : this.repository.ConvertParamsToArray(queryScopes);
128
- return scopesArray.map(scope => (Object.assign(Object.assign({}, scope), { column: `${tableName}.${scope.column}` })));
123
+ return scopesArray.map(scope => ({
124
+ ...scope,
125
+ column: `${tableName}.${scope.column}`
126
+ }));
129
127
  }
130
128
  }