myorm_pg 6.1.4 → 6.2.1

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 (115) hide show
  1. package/lib/core/design/Type.d.ts.map +1 -1
  2. package/lib/core/design/Type.js +1 -0
  3. package/lib/core/design/Type.js.map +1 -1
  4. package/lib/implementations/PGDBContext.d.ts +5 -1
  5. package/lib/implementations/PGDBContext.d.ts.map +1 -1
  6. package/lib/implementations/PGDBContext.js +159 -118
  7. package/lib/implementations/PGDBContext.js.map +1 -1
  8. package/lib/implementations/PGDBManager.d.ts.map +1 -1
  9. package/lib/implementations/PGDBManager.js +2 -0
  10. package/lib/implementations/PGDBManager.js.map +1 -1
  11. package/lib/implementations/PGDBSet.d.ts +3 -1
  12. package/lib/implementations/PGDBSet.d.ts.map +1 -1
  13. package/lib/implementations/PGDBSet.js +280 -66
  14. package/lib/implementations/PGDBSet.js.map +1 -1
  15. package/package.json +2 -2
  16. package/lib/__tests__/classes/RawTypes.d.ts +0 -3
  17. package/lib/__tests__/classes/RawTypes.d.ts.map +0 -1
  18. package/lib/__tests__/classes/RawTypes.js +0 -16
  19. package/lib/__tests__/classes/RawTypes.js.map +0 -1
  20. package/lib/__tests__/classes/RelationEntity.d.ts +0 -12
  21. package/lib/__tests__/classes/RelationEntity.d.ts.map +0 -1
  22. package/lib/__tests__/classes/RelationEntity.js +0 -65
  23. package/lib/__tests__/classes/RelationEntity.js.map +0 -1
  24. package/lib/__tests__/classes/TestContext.d.ts +0 -9
  25. package/lib/__tests__/classes/TestContext.d.ts.map +0 -1
  26. package/lib/__tests__/classes/TestContext.js +0 -14
  27. package/lib/__tests__/classes/TestContext.js.map +0 -1
  28. package/lib/__tests__/classes/TestEntity.d.ts +0 -18
  29. package/lib/__tests__/classes/TestEntity.d.ts.map +0 -1
  30. package/lib/__tests__/classes/TestEntity.js +0 -99
  31. package/lib/__tests__/classes/TestEntity.js.map +0 -1
  32. package/lib/__tests__/functions/TestFunctions.d.ts +0 -11
  33. package/lib/__tests__/functions/TestFunctions.d.ts.map +0 -1
  34. package/lib/__tests__/functions/TestFunctions.js +0 -137
  35. package/lib/__tests__/functions/TestFunctions.js.map +0 -1
  36. package/lib/src/Index.d.ts +0 -41
  37. package/lib/src/Index.d.ts.map +0 -1
  38. package/lib/src/Index.js +0 -64
  39. package/lib/src/Index.js.map +0 -1
  40. package/lib/src/core/decorators/SchemasDecorators.d.ts +0 -45
  41. package/lib/src/core/decorators/SchemasDecorators.d.ts.map +0 -1
  42. package/lib/src/core/decorators/SchemasDecorators.js +0 -145
  43. package/lib/src/core/decorators/SchemasDecorators.js.map +0 -1
  44. package/lib/src/core/design/Type.d.ts +0 -39
  45. package/lib/src/core/design/Type.d.ts.map +0 -1
  46. package/lib/src/core/design/Type.js +0 -144
  47. package/lib/src/core/design/Type.js.map +0 -1
  48. package/lib/src/core/enums/DBTypes.d.ts +0 -19
  49. package/lib/src/core/enums/DBTypes.d.ts.map +0 -1
  50. package/lib/src/core/enums/DBTypes.js +0 -23
  51. package/lib/src/core/enums/DBTypes.js.map +0 -1
  52. package/lib/src/core/enums/RelationType.d.ts +0 -7
  53. package/lib/src/core/enums/RelationType.d.ts.map +0 -1
  54. package/lib/src/core/enums/RelationType.js +0 -11
  55. package/lib/src/core/enums/RelationType.js.map +0 -1
  56. package/lib/src/core/exceptions/ConnectionFailException.d.ts +0 -5
  57. package/lib/src/core/exceptions/ConnectionFailException.d.ts.map +0 -1
  58. package/lib/src/core/exceptions/ConnectionFailException.js +0 -13
  59. package/lib/src/core/exceptions/ConnectionFailException.js.map +0 -1
  60. package/lib/src/core/exceptions/ConstraintFailException.d.ts +0 -5
  61. package/lib/src/core/exceptions/ConstraintFailException.d.ts.map +0 -1
  62. package/lib/src/core/exceptions/ConstraintFailException.js +0 -13
  63. package/lib/src/core/exceptions/ConstraintFailException.js.map +0 -1
  64. package/lib/src/core/exceptions/Exception.d.ts +0 -5
  65. package/lib/src/core/exceptions/Exception.d.ts.map +0 -1
  66. package/lib/src/core/exceptions/Exception.js +0 -10
  67. package/lib/src/core/exceptions/Exception.js.map +0 -1
  68. package/lib/src/core/exceptions/InvalidOperationException.d.ts +0 -6
  69. package/lib/src/core/exceptions/InvalidOperationException.d.ts.map +0 -1
  70. package/lib/src/core/exceptions/InvalidOperationException.js +0 -14
  71. package/lib/src/core/exceptions/InvalidOperationException.js.map +0 -1
  72. package/lib/src/core/exceptions/NotImplementedException.d.ts +0 -5
  73. package/lib/src/core/exceptions/NotImplementedException.d.ts.map +0 -1
  74. package/lib/src/core/exceptions/NotImplementedException.js +0 -13
  75. package/lib/src/core/exceptions/NotImplementedException.js.map +0 -1
  76. package/lib/src/core/exceptions/QueryFailException.d.ts +0 -6
  77. package/lib/src/core/exceptions/QueryFailException.d.ts.map +0 -1
  78. package/lib/src/core/exceptions/QueryFailException.js +0 -14
  79. package/lib/src/core/exceptions/QueryFailException.js.map +0 -1
  80. package/lib/src/core/exceptions/TypeNotMappedException.d.ts +0 -5
  81. package/lib/src/core/exceptions/TypeNotMappedException.d.ts.map +0 -1
  82. package/lib/src/core/exceptions/TypeNotMappedException.js +0 -13
  83. package/lib/src/core/exceptions/TypeNotMappedException.js.map +0 -1
  84. package/lib/src/core/exceptions/TypeNotSuportedException.d.ts +0 -5
  85. package/lib/src/core/exceptions/TypeNotSuportedException.d.ts.map +0 -1
  86. package/lib/src/core/exceptions/TypeNotSuportedException.js +0 -13
  87. package/lib/src/core/exceptions/TypeNotSuportedException.js.map +0 -1
  88. package/lib/src/core/handlers/DBOperationLogHandler.d.ts +0 -17
  89. package/lib/src/core/handlers/DBOperationLogHandler.d.ts.map +0 -1
  90. package/lib/src/core/handlers/DBOperationLogHandler.js +0 -18
  91. package/lib/src/core/handlers/DBOperationLogHandler.js.map +0 -1
  92. package/lib/src/implementations/PGDBConnection.d.ts +0 -19
  93. package/lib/src/implementations/PGDBConnection.d.ts.map +0 -1
  94. package/lib/src/implementations/PGDBConnection.js +0 -105
  95. package/lib/src/implementations/PGDBConnection.js.map +0 -1
  96. package/lib/src/implementations/PGDBContext.d.ts +0 -54
  97. package/lib/src/implementations/PGDBContext.d.ts.map +0 -1
  98. package/lib/src/implementations/PGDBContext.js +0 -302
  99. package/lib/src/implementations/PGDBContext.js.map +0 -1
  100. package/lib/src/implementations/PGDBManager.d.ts +0 -37
  101. package/lib/src/implementations/PGDBManager.d.ts.map +0 -1
  102. package/lib/src/implementations/PGDBManager.js +0 -296
  103. package/lib/src/implementations/PGDBManager.js.map +0 -1
  104. package/lib/src/implementations/PGDBSet.d.ts +0 -60
  105. package/lib/src/implementations/PGDBSet.d.ts.map +0 -1
  106. package/lib/src/implementations/PGDBSet.js +0 -1385
  107. package/lib/src/implementations/PGDBSet.js.map +0 -1
  108. package/lib/src/implementations/PGFluentField.d.ts +0 -18
  109. package/lib/src/implementations/PGFluentField.d.ts.map +0 -1
  110. package/lib/src/implementations/PGFluentField.js +0 -155
  111. package/lib/src/implementations/PGFluentField.js.map +0 -1
  112. package/lib/src/implementations/PGSetHelper.d.ts +0 -19
  113. package/lib/src/implementations/PGSetHelper.d.ts.map +0 -1
  114. package/lib/src/implementations/PGSetHelper.js +0 -48
  115. package/lib/src/implementations/PGSetHelper.js.map +0 -1
@@ -1,1385 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const myorm_core_1 = require("myorm_core");
16
- const Type_1 = __importDefault(require("../core/design/Type"));
17
- const DBTypes_1 = require("../core/enums/DBTypes");
18
- const SchemasDecorators_1 = __importDefault(require("../core/decorators/SchemasDecorators"));
19
- const NotImplementedException_1 = __importDefault(require("../core/exceptions/NotImplementedException"));
20
- const TypeNotSuportedException_1 = __importDefault(require("../core/exceptions/TypeNotSuportedException"));
21
- const InvalidOperationException_1 = __importDefault(require("../core/exceptions/InvalidOperationException"));
22
- const RelationType_1 = require("../core/enums/RelationType");
23
- const ConstraintFailException_1 = __importDefault(require("../core/exceptions/ConstraintFailException"));
24
- const PGFluentField_1 = __importDefault(require("./PGFluentField"));
25
- const PGSetHelper_1 = __importDefault(require("./PGSetHelper"));
26
- class PGDBSet extends myorm_core_1.AbstractSet {
27
- constructor(cTor, context) {
28
- super();
29
- this._statements = [];
30
- this._ordering = [];
31
- this._includes = [];
32
- this._type = cTor;
33
- this._table = Type_1.default.GetTableName(cTor);
34
- this._maps = Type_1.default.GetColumnNameAndType(cTor);
35
- this._manager = context["_manager"];
36
- this._context = context;
37
- this._set = new PGSetValue();
38
- }
39
- AddObjectAndRelationsAsync(obj, relations) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return this.AddObjectAsync(obj, false, relations);
42
- });
43
- }
44
- AddAsync(obj) {
45
- return this.AddObjectAsync(obj);
46
- }
47
- AddObjectAsync(obj, cascade = true, relations = [], visiteds = []) {
48
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
49
- var _a, _b, _c;
50
- visiteds = visiteds !== null && visiteds !== void 0 ? visiteds : [];
51
- if (!obj)
52
- throw new InvalidOperationException_1.default(`Cannot insert a null reference object of ${this._type.name}`);
53
- if (!this.IsCorrectType(obj))
54
- throw new InvalidOperationException_1.default(`The object passed as argument is not a ${this._type.name} instance`);
55
- let sql = `insert into "${this._table}"(`;
56
- let values = `values (`;
57
- let returnKey = '';
58
- let key;
59
- let subTypes = [];
60
- for (let map of this._maps) {
61
- if (SchemasDecorators_1.default.IsPrimaryKey(this._type, map.Field)) {
62
- returnKey = `returning ${map.Column}`;
63
- key =
64
- {
65
- Column: map.Column,
66
- Property: map.Field
67
- };
68
- continue;
69
- }
70
- let currPropValue = Reflect.get(obj, map.Field);
71
- if (currPropValue == undefined || currPropValue == null) {
72
- sql += `"${map.Column}",`;
73
- values += `null,`;
74
- continue;
75
- }
76
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, map.Field);
77
- let designType = Type_1.default.GetDesingType(this._type, map.Field);
78
- if ((designType && this._context.IsMapped(designType)) || (relation && this._context.IsMapped(relation.TypeBuilder()))) {
79
- subTypes.push({
80
- Column: map.Column,
81
- Field: map.Field,
82
- Type: map.Type
83
- });
84
- continue;
85
- }
86
- let colType = Type_1.default.CastType(map.Type);
87
- sql += `"${map.Column}",`;
88
- values += `${this.CreateValueStatement(colType, Reflect.get(obj, map.Field))},`;
89
- }
90
- if (key == undefined)
91
- throw new InvalidOperationException_1.default(`The type ${this._type.name} must have a primary key field`);
92
- if (visiteds.filter(s => s && s.constructor == obj.constructor && Reflect.get(s, key.Property) == Reflect.get(obj, key.Property)).length > 0)
93
- return obj;
94
- visiteds.push(obj);
95
- if (Type_1.default.HasValue(Reflect.get(obj, key.Property)))
96
- throw new InvalidOperationException_1.default(`Can not add a ${this._type.name} with ${key.Property} provided`);
97
- sql = sql.substring(0, sql.length - 1) + ") ";
98
- values = values.substring(0, values.length - 1) + ")";
99
- let insert = `${sql} ${values} ${returnKey};`;
100
- let retun = yield this._manager.ExecuteAsync(insert);
101
- if (key != undefined && retun.rows.length > 0) {
102
- obj[key.Property] = retun.rows[0][key.Column];
103
- }
104
- let subTypesUpdates = [];
105
- let updatableFields = [];
106
- let objectsToUpdate = [];
107
- let objectsToAdd = [];
108
- let buildSubupdates = [];
109
- for (let sub of subTypes) {
110
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, sub.Field);
111
- let subType = Type_1.default.GetDesingType(this._type, sub.Field);
112
- if (!subType && !relation)
113
- throw new InvalidOperationException_1.default(`Can not determine the relation of the property ${this._type}.${sub.Field}`);
114
- if (!subType && relation) {
115
- subType = relation.TypeBuilder();
116
- }
117
- let isArray = subType == Array;
118
- if (isArray) {
119
- if (!relation)
120
- continue;
121
- subType = relation === null || relation === void 0 ? void 0 : relation.TypeBuilder();
122
- }
123
- let subObj = Reflect.get(obj, sub.Field);
124
- if (subObj == undefined)
125
- continue;
126
- let subPK = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
127
- if (subPK == undefined)
128
- throw new InvalidOperationException_1.default(`The type ${subType.name} must have a primary key column`);
129
- let colletion = this._context.Collection(subType);
130
- if (key != undefined) {
131
- for (let subKey of Type_1.default.GetProperties(subType)) {
132
- let subRelation = SchemasDecorators_1.default.GetRelationAttribute(subType, subKey);
133
- if (subRelation && subRelation.TypeBuilder() == this._type) {
134
- if (subRelation.Field != undefined && subRelation.Field != sub.Field)
135
- continue;
136
- updatableFields.push(subKey);
137
- if (subRelation.Relation == RelationType_1.RelationType.ONE_TO_MANY || subRelation.Relation == RelationType_1.RelationType.MANY_TO_MANY) {
138
- if (isArray) {
139
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
140
- continue;
141
- for (let i of subObj) {
142
- if (i == undefined || visiteds.indexOf(i) > -1)
143
- continue;
144
- let metadata = Type_1.default.ExtractMetadata(i).filter(s => s.Field == subKey && s.Loaded);
145
- let value = [];
146
- if (metadata.length > 0) {
147
- value = ((_a = Reflect.get(i, subKey)) !== null && _a !== void 0 ? _a : []).filter(s => s[subPK] != obj[subPK]);
148
- }
149
- else {
150
- let item = yield colletion["Where"]({ Field: subPK, Value: Reflect.get(i, subPK) })["LoadRelationOn"](subKey)["FirstOrDefaultAsync"]();
151
- value = item == undefined ? [] : item[subKey];
152
- value = value !== null && value !== void 0 ? value : [];
153
- }
154
- value.push(obj);
155
- Reflect.set(i, subKey, value);
156
- }
157
- }
158
- else {
159
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
160
- continue;
161
- let metadata = Type_1.default.ExtractMetadata(subObj).filter(s => s.Field == subKey && s.Loaded);
162
- let value = [];
163
- if (metadata.length > 0) {
164
- value = ((_b = Reflect.get(subObj, subKey)) !== null && _b !== void 0 ? _b : []).filter(s => s[subPK] != obj[subPK]);
165
- }
166
- else {
167
- let item = yield colletion["Where"]({ Field: subPK, Value: Reflect.get(subObj, subPK) })["LoadRelationOn"](subKey)["FirstOrDefaultAsync"]();
168
- value = item == undefined ? [] : item[subKey];
169
- value = value !== null && value !== void 0 ? value : [];
170
- }
171
- value.push(obj);
172
- Reflect.set(subObj, subKey, value);
173
- }
174
- }
175
- else {
176
- if (subRelation.Relation == RelationType_1.RelationType.MANY_TO_ONE && isArray) {
177
- for (let i of subObj) {
178
- if (i == undefined || visiteds.indexOf(i) > -1)
179
- continue;
180
- Reflect.set(i, subKey, obj);
181
- }
182
- }
183
- else {
184
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
185
- continue;
186
- Reflect.set(subObj, subKey, obj);
187
- }
188
- }
189
- }
190
- }
191
- }
192
- if (isArray) {
193
- if (subObj == undefined)
194
- continue;
195
- for (let i of subObj) {
196
- if (i == undefined)
197
- continue;
198
- if (!Type_1.default.HasValue(Reflect.get(i, subPK))) {
199
- if (cascade || relations.filter(s => s == sub.Field).length > 0) {
200
- let cs = objectsToAdd.filter(s => s.Type == subType);
201
- if (cs.length == 0)
202
- objectsToAdd.push({ Objs: [i], Type: subType, SubPK: subPK });
203
- else
204
- cs[0].Objs.push(i);
205
- }
206
- }
207
- else {
208
- let cs = objectsToUpdate.filter(s => s.Type == subType);
209
- if (cs.length == 0)
210
- objectsToUpdate.push({ Objs: [{ Obj: i, UpdatableFields: updatableFields }], Type: subType, SubPK: subPK });
211
- else {
212
- let ccs = cs.filter(s => s.Objs.filter(j => j.Obj == i).length > 0);
213
- if (ccs.length == 0) {
214
- cs[0].Objs.push({ Obj: i, UpdatableFields: updatableFields });
215
- }
216
- else {
217
- ccs[0].Objs[0].UpdatableFields.push(...updatableFields);
218
- }
219
- }
220
- }
221
- }
222
- }
223
- else {
224
- if (subObj == undefined)
225
- continue;
226
- if (!Type_1.default.HasValue(Reflect.get(subObj, subPK))) {
227
- if (cascade || relations.filter(s => s == sub.Field).length > 0) {
228
- let cs = objectsToAdd.filter(s => s.Type == subType);
229
- if (cs.length == 0)
230
- objectsToAdd.push({ Objs: [subObj], Type: subType, SubPK: subPK });
231
- else
232
- cs[0].Objs.push(subObj);
233
- }
234
- }
235
- else {
236
- let cs = objectsToUpdate.filter(s => s.Type == subType);
237
- if (cs.length == 0)
238
- objectsToUpdate.push({ Objs: [{ Obj: subObj, UpdatableFields: updatableFields }], Type: subType, SubPK: subPK });
239
- else {
240
- let ccs = cs.filter(s => s.Objs.filter(j => j.Obj == subObj).length > 0);
241
- if (ccs.length == 0) {
242
- cs[0].Objs.push({ Obj: subObj, UpdatableFields: updatableFields });
243
- }
244
- else {
245
- ccs[0].Objs[0].UpdatableFields.push(...updatableFields);
246
- }
247
- }
248
- }
249
- }
250
- buildSubupdates.push(() => {
251
- let spk = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
252
- let columnType = Type_1.default.CastType(Type_1.default.GetDesingTimeTypeName(subType, spk));
253
- if ((relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.MANY_TO_MANY || (relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.ONE_TO_MANY || isArray)
254
- columnType = Type_1.default.AsArray(columnType);
255
- if (subObj == undefined)
256
- return;
257
- let updateValues = [Reflect.get(subObj, spk)];
258
- if (isArray) {
259
- updateValues = [];
260
- for (let i of subObj) {
261
- if (i == undefined)
262
- continue;
263
- updateValues.push(Reflect.get(i, spk));
264
- }
265
- }
266
- Type_1.default.InjectMetadata(obj, {
267
- Field: sub.Field,
268
- Type: columnType,
269
- Value: updateValues,
270
- Loaded: true
271
- });
272
- subTypesUpdates.push(`"${sub.Column}" = ${this.CreateValueStatement(columnType, isArray ? updateValues : updateValues[0])}`);
273
- });
274
- }
275
- objectsToAdd.forEach(o => {
276
- o.Objs = o.Objs.filter((i, ix, s) => {
277
- return ix == s.findIndex(v => v == i);
278
- });
279
- });
280
- for (let cs of objectsToAdd) {
281
- let colletion = this._context.Collection(cs.Type);
282
- for (let i of cs.Objs)
283
- yield colletion["AddObjectAsync"](i, true, [], visiteds);
284
- }
285
- for (let cs of objectsToUpdate) {
286
- let colletion = this._context.Collection(cs.Type);
287
- for (let i of cs.Objs)
288
- yield colletion["UpdateObjectAsync"](i.Obj, false, (_c = i.UpdatableFields) !== null && _c !== void 0 ? _c : [], [], visiteds);
289
- }
290
- for (let b of buildSubupdates)
291
- b();
292
- if (subTypesUpdates.length > 0) {
293
- let subUpdate = `update "${Type_1.default.GetTableName(this._type)}" set `;
294
- for (let p of subTypesUpdates) {
295
- subUpdate += `${p},`;
296
- }
297
- subUpdate = `${subUpdate.substring(0, subUpdate.length - 1)} where `;
298
- subUpdate += this.EvaluateStatement({
299
- StatementType: StatementType.WHERE,
300
- Statement: {
301
- Field: key.Property,
302
- Kind: myorm_core_1.Operation.EQUALS,
303
- Value: Reflect.get(obj, key.Property)
304
- }
305
- });
306
- yield this._manager.ExecuteNonQueryAsync(subUpdate);
307
- }
308
- return obj;
309
- }));
310
- }
311
- UpdateSelectionAsync() {
312
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
313
- if (!this._set || this._set.Get().length == 0)
314
- throw new InvalidOperationException_1.default('Can not realize a update with no one set operation before');
315
- let setters = this._set.Get();
316
- let update = `update "${this._table}" set`;
317
- let values = "";
318
- let whereSrt = PGSetHelper_1.default.ExtractWhereData(this);
319
- if (!whereSrt) {
320
- if (this._whereAsString != undefined && this._statements.length > 0) {
321
- throw new InvalidOperationException_1.default("Is not possible combine free and structured queries");
322
- }
323
- if (this._whereAsString != undefined) {
324
- whereSrt = ` ${this._whereAsString} `;
325
- }
326
- whereSrt = this.EvaluateWhere();
327
- }
328
- let PK = SchemasDecorators_1.default.ExtractPrimaryKey(this._type);
329
- if (!PK)
330
- throw new InvalidOperationException_1.default(`The type ${this._type.name} must have a primary key field`);
331
- let pkColumn = Type_1.default.GetColumnNameAndType(this._type).filter(s => s.Field == PK)[0];
332
- for (let map of this._maps) {
333
- let set = setters.filter(s => s.Key == map.Field);
334
- if (set.length == 0)
335
- continue;
336
- if (SchemasDecorators_1.default.IsPrimaryKey(this._type, map.Field))
337
- continue;
338
- if (set[0].Value == undefined || set[0].Value == null) {
339
- values += `"${map.Column}" = null`;
340
- continue;
341
- }
342
- let designType = Type_1.default.GetDesingType(this._type, map.Field);
343
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, map.Field);
344
- let subType = Type_1.default.GetDesingType(this._type, map.Field);
345
- if (!subType && !relation)
346
- throw new InvalidOperationException_1.default(`Can not determine the relation of the property ${this._type}.${map.Field}`);
347
- let isArray = subType == Array;
348
- if (!subType && relation)
349
- subType = relation.TypeBuilder();
350
- if (isArray) {
351
- if (!relation)
352
- continue;
353
- subType = relation === null || relation === void 0 ? void 0 : relation.TypeBuilder();
354
- }
355
- let subPK = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
356
- if ((designType && this._context.IsMapped(designType)) || (relation && this._context.IsMapped(relation.TypeBuilder()))) {
357
- if (subPK == undefined)
358
- throw new InvalidOperationException_1.default(`The type ${subType.name} must have a primary key column`);
359
- let colletion = this._context.Collection(subType);
360
- if (isArray) {
361
- for (let i of set[0].Value) {
362
- if (i == undefined)
363
- continue;
364
- if (!Type_1.default.HasValue(Reflect.get(i, subPK)))
365
- yield colletion["AddAsync"](i);
366
- if (relation) {
367
- let subRelation;
368
- for (let c of Type_1.default.GetColumnNameAndType(subType)) {
369
- let r = SchemasDecorators_1.default.GetRelationAttribute(subType, c.Field);
370
- if (r && r.Field == set[0].Key && r.TypeBuilder() == this._type) {
371
- subRelation = r;
372
- break;
373
- }
374
- }
375
- if (subRelation && (subRelation.Relation == RelationType_1.RelationType.ONE_TO_MANY || (subRelation === null || subRelation === void 0 ? void 0 : subRelation.Relation) == RelationType_1.RelationType.MANY_TO_MANY)) {
376
- let subDesingType = Type_1.default.GetDesingType(subType, relation.Field);
377
- if (subDesingType == Array) {
378
- let subColumnName = Type_1.default.GetColumnNameAndType(subType).filter(s => s.Field == (relation === null || relation === void 0 ? void 0 : relation.Field))[0];
379
- let subTableName = Type_1.default.GetTableName(subType);
380
- let subPkColumn = Type_1.default.GetColumnNameAndType(subType).filter(s => s.Field == subPK)[0];
381
- let queryAllpks = `(select array_agg(${pkColumn.Column}) from ${this._table} ${whereSrt})`;
382
- let subUpdate = `update ${subTableName} set ${subColumnName.Column} = ${subColumnName.Column} || ${queryAllpks} where "${subPkColumn.Column}" = ${this.CreateValueStatement(Type_1.default.CastType(subPkColumn.Type), Reflect.get(i, subPK))}`;
383
- yield this._manager.ExecuteNonQueryAsync(subUpdate);
384
- }
385
- }
386
- }
387
- }
388
- }
389
- else {
390
- if (set[0].Value == undefined)
391
- continue;
392
- if (!Type_1.default.HasValue(Reflect.get(set[0].Value, subPK)))
393
- yield colletion["AddAsync"](set[0].Value);
394
- if (relation) {
395
- let subRelation;
396
- for (let c of Type_1.default.GetColumnNameAndType(subType)) {
397
- let r = SchemasDecorators_1.default.GetRelationAttribute(subType, c.Field);
398
- if (r && r.Field == set[0].Key && r.TypeBuilder() == this._type) {
399
- subRelation = r;
400
- break;
401
- }
402
- }
403
- if (subRelation && (subRelation.Relation == RelationType_1.RelationType.ONE_TO_MANY || (subRelation === null || subRelation === void 0 ? void 0 : subRelation.Relation) == RelationType_1.RelationType.MANY_TO_MANY)) {
404
- let subDesingType = Type_1.default.GetDesingType(subType, relation.Field);
405
- if (subDesingType == Array) {
406
- let subColumnName = Type_1.default.GetColumnNameAndType(subType).filter(s => s.Field == (relation === null || relation === void 0 ? void 0 : relation.Field))[0];
407
- let subTableName = Type_1.default.GetTableName(subType);
408
- let subPkColumn = Type_1.default.GetColumnNameAndType(subType).filter(s => s.Field == subPK)[0];
409
- let queryAllpks = `(select array_agg(${pkColumn.Column}) from ${this._table} ${whereSrt})`;
410
- let subUpdate = `update ${subTableName} set ${subColumnName.Column} = ${subColumnName.Column} || ${queryAllpks} where "${subPkColumn.Column}" = ${this.CreateValueStatement(Type_1.default.CastType(subPkColumn.Type), Reflect.get(set[0].Value, subPK))}`;
411
- yield this._manager.ExecuteNonQueryAsync(subUpdate);
412
- }
413
- }
414
- }
415
- }
416
- let columnType = Type_1.default.CastType(Type_1.default.GetDesingTimeTypeName(subType, subPK));
417
- if ((relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.MANY_TO_MANY || (relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.ONE_TO_MANY)
418
- columnType = Type_1.default.AsArray(columnType);
419
- let updateValues = [Reflect.get(set[0].Value, subPK)];
420
- if (isArray) {
421
- updateValues = [];
422
- for (let i of set[0].Value) {
423
- if (i == undefined)
424
- continue;
425
- updateValues.push(Reflect.get(i, subPK));
426
- }
427
- }
428
- values += `"${map.Column}" = ${this.CreateValueStatement(columnType, isArray ? updateValues : updateValues[0])},`;
429
- }
430
- else {
431
- let colType = Type_1.default.CastType(map.Type);
432
- if (SchemasDecorators_1.default.IsPrimaryKey(this._type, map.Field))
433
- continue;
434
- values += `"${map.Column}" = ${this.CreateValueStatement(colType, set[0].Value)},`;
435
- }
436
- }
437
- update = `${update} ${values.substring(0, values.length - 1)}`;
438
- update += " " + whereSrt;
439
- yield this._manager.ExecuteNonQueryAsync(update);
440
- }));
441
- }
442
- Set(key, value) {
443
- this._set.Add(key, value);
444
- return this;
445
- }
446
- UpdateAsync(obj) {
447
- return __awaiter(this, void 0, void 0, function* () {
448
- return yield this.UpdateObjectAsync(obj, true);
449
- });
450
- }
451
- UpdateObjectAndRelationsAsync(obj, relations) {
452
- return __awaiter(this, void 0, void 0, function* () {
453
- Type_1.default.DeleteMetadata(obj);
454
- return this.UpdateObjectAsync(obj, false, relations ? relations.map(s => s.toString()) : []);
455
- });
456
- }
457
- UpdateObjectAsync(obj, cascade, relationsAllowed, fieldsAllowed, visiteds = []) {
458
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
459
- var _a, _b, _c, _d;
460
- relationsAllowed = relationsAllowed !== null && relationsAllowed !== void 0 ? relationsAllowed : [];
461
- visiteds = visiteds !== null && visiteds !== void 0 ? visiteds : [];
462
- if (visiteds.indexOf(obj) > -1)
463
- return obj;
464
- if (!this.IsCorrectType(obj))
465
- throw new InvalidOperationException_1.default(`The object passed as argument is not a ${this._type.name} instance`);
466
- if (!obj)
467
- throw new InvalidOperationException_1.default(`Cannot update a null reference object of ${this._type.name}`);
468
- let keys = Type_1.default.GetProperties(this._type).filter(p => SchemasDecorators_1.default.IsPrimaryKey(this._type, p));
469
- let wheres = [];
470
- if (keys && keys.length > 0) {
471
- keys.forEach((w, i) => {
472
- let keyValue = Reflect.get(obj, w);
473
- if (!keyValue)
474
- throw new ConstraintFailException_1.default(`The field ${this._type.name}.${w} is a primary key but has no value`);
475
- wheres.push({
476
- Statement: {
477
- Field: w,
478
- Kind: myorm_core_1.Operation.EQUALS,
479
- Value: Reflect.get(obj, w)
480
- },
481
- StatementType: i == 0 ? StatementType.WHERE : StatementType.AND
482
- });
483
- });
484
- }
485
- let update = `update "${this._table}" set`;
486
- let values = "";
487
- let key;
488
- let subTypes = [];
489
- for (let map of this._maps) {
490
- let designType = Type_1.default.GetDesingType(this._type, map.Field);
491
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, map.Field);
492
- if ((designType && this._context.IsMapped(designType)) || (relation && this._context.IsMapped(relation.TypeBuilder()))) {
493
- subTypes.push({
494
- Column: map.Column,
495
- Field: map.Field,
496
- Type: map.Type
497
- });
498
- continue;
499
- }
500
- let colType = Type_1.default.CastType(map.Type);
501
- if (SchemasDecorators_1.default.IsPrimaryKey(this._type, map.Field)) {
502
- key =
503
- {
504
- Column: map.Column,
505
- Property: map.Field
506
- };
507
- continue;
508
- }
509
- if (fieldsAllowed && fieldsAllowed.filter(s => s == map.Column).length == 0)
510
- continue;
511
- values += `"${map.Column}" = ${this.CreateValueStatement(colType, Reflect.get(obj, map.Field))},`;
512
- }
513
- if (key == undefined)
514
- throw new InvalidOperationException_1.default(`The type ${this._type.name} must have a primary key column`);
515
- if (visiteds.filter(s => s && s.constructor == obj.constructor && Reflect.get(s, key.Property) == Reflect.get(obj, key.Property)).length > 0)
516
- return obj;
517
- visiteds.push(obj);
518
- update = `${update} ${values.substring(0, values.length - 1)}`;
519
- for (let where of wheres) {
520
- update += ` ${where.StatementType} ${this.EvaluateStatement(where)} `;
521
- }
522
- if (values.trim().length > 1)
523
- yield this._manager.ExecuteNonQueryAsync(update);
524
- let subTypesUpdates = [];
525
- let objectsToUpdate = [];
526
- let objectsToAdd = [];
527
- let buildSubupdates = [];
528
- let updatableFields = [];
529
- for (let sub of subTypes) {
530
- let subObj = Reflect.get(obj, sub.Field);
531
- let metadata = Type_1.default.ExtractMetadata(obj);
532
- let meta = metadata.filter(s => s.Field == sub.Field && s.Loaded);
533
- let objetsToRemoveThisReferece = { HasRelation: false, IsArray: false, SubIsArray: false, SubField: "", Relation: undefined, SubRelation: undefined };
534
- if (((meta.length > 0 && meta[0].Loaded) || relationsAllowed.filter(s => s == sub.Field).length > 0) && subObj == undefined) {
535
- subTypesUpdates.push(`"${sub.Column}" = null`);
536
- }
537
- if (meta.length == 0 && relationsAllowed.filter(s => s == sub.Field).length == 0)
538
- continue;
539
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, sub.Field);
540
- let subType = Type_1.default.GetDesingType(this._type, sub.Field);
541
- if (!subType && !relation)
542
- throw new InvalidOperationException_1.default(`Can not determine the relation of the property ${this._type}.${sub.Field}`);
543
- if (!subType && relation) {
544
- subType = relation.TypeBuilder();
545
- }
546
- let isArray = subType == Array;
547
- if (isArray) {
548
- if (!relation)
549
- continue;
550
- subType = relation === null || relation === void 0 ? void 0 : relation.TypeBuilder();
551
- }
552
- if (relationsAllowed.filter(s => s == sub.Field).length == 0 && this.GetChanges(meta, subObj, subType).length == 0)
553
- continue;
554
- if (meta.length > 0)
555
- relationsAllowed.push(meta[0].Field);
556
- let subPK = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
557
- if (subPK == undefined)
558
- throw new InvalidOperationException_1.default(`The type ${subType.name} must have a primary key column`);
559
- if (key == undefined)
560
- throw new InvalidOperationException_1.default(`The type ${this._type.name} must have a primary key column`);
561
- let hasSubrelation = false;
562
- if (key != undefined) {
563
- let colletion = this._context.Collection(subType);
564
- for (let subKey of Type_1.default.GetProperties(subType)) {
565
- let subRelation = SchemasDecorators_1.default.GetRelationAttribute(subType, subKey);
566
- if (subRelation && subRelation.TypeBuilder() == this._type) {
567
- if (subRelation.Field != undefined && subRelation.Field != sub.Field)
568
- continue;
569
- updatableFields.push(subKey);
570
- objetsToRemoveThisReferece.HasRelation = true;
571
- objetsToRemoveThisReferece.Relation = relation;
572
- objetsToRemoveThisReferece.SubRelation = subRelation;
573
- objetsToRemoveThisReferece.SubField = subKey;
574
- hasSubrelation = true;
575
- if (subRelation.Relation == RelationType_1.RelationType.ONE_TO_MANY || subRelation.Relation == RelationType_1.RelationType.MANY_TO_MANY) {
576
- let subFKTypeIsArray = Type_1.default.GetDesingType(subType, subKey) == Array;
577
- objetsToRemoveThisReferece.IsArray = isArray;
578
- objetsToRemoveThisReferece.SubIsArray = subFKTypeIsArray;
579
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
580
- continue;
581
- if (isArray) {
582
- if (subObj == undefined)
583
- continue;
584
- for (let i of subObj) {
585
- if (i == undefined || visiteds.indexOf(i) > -1)
586
- continue;
587
- if (subFKTypeIsArray) {
588
- let value = [];
589
- let subMeta = Type_1.default.ExtractMetadata(i);
590
- if (subMeta.length > 0 && subMeta.filter(s => s.Field == subKey && s.Loaded).length > 0) {
591
- value = ((_a = Reflect.get(i, subKey)) !== null && _a !== void 0 ? _a : []).filter(s => s[subPK] != obj[subPK]);
592
- }
593
- else {
594
- let item = yield colletion["Where"]({ Field: subPK, Value: Reflect.get(i, subPK) })["LoadRelationOn"](subKey)["FirstOrDefaultAsync"]();
595
- value = item == undefined ? [] : item[subKey];
596
- value = value !== null && value !== void 0 ? value : [];
597
- }
598
- value = value.filter(s => Reflect.get(s, key.Property) != Reflect.get(obj, key.Property));
599
- value.push(obj);
600
- Reflect.set(i, subKey, value);
601
- }
602
- else {
603
- Reflect.set(i, subKey, obj);
604
- }
605
- }
606
- }
607
- else {
608
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
609
- continue;
610
- if (subFKTypeIsArray) {
611
- let value = [];
612
- let subMeta = Type_1.default.ExtractMetadata(subObj);
613
- if (subMeta.length > 0 && subMeta.filter(s => s.Field == subKey && s.Loaded).length > 0) {
614
- value = ((_b = Reflect.get(subObj, subKey)) !== null && _b !== void 0 ? _b : []).filter(s => s[subPK] != obj[subPK]);
615
- }
616
- else {
617
- let item = yield colletion["Where"]({ Field: subPK, Value: Reflect.get(subObj, subPK) })["LoadRelationOn"](subKey)["FirstOrDefaultAsync"]();
618
- value = item == undefined ? [] : item[subKey];
619
- value = value !== null && value !== void 0 ? value : [];
620
- }
621
- value = value.filter(s => Reflect.get(s, key.Property) != Reflect.get(obj, key.Property));
622
- value.push(obj);
623
- Reflect.set(subObj, subKey, value);
624
- }
625
- else {
626
- Reflect.set(subObj, subKey, obj);
627
- }
628
- }
629
- }
630
- else {
631
- if (subObj == undefined || visiteds.indexOf(subObj) > -1)
632
- continue;
633
- if (subRelation.Relation == RelationType_1.RelationType.MANY_TO_ONE) {
634
- for (let i of subObj) {
635
- if (i == undefined || visiteds.indexOf(i) > -1)
636
- continue;
637
- Reflect.set(i, subKey, obj);
638
- }
639
- }
640
- else {
641
- Reflect.set(subObj, subKey, obj);
642
- }
643
- }
644
- }
645
- }
646
- }
647
- let colletion = this._context.Collection(subType);
648
- if (!hasSubrelation || (cascade || relationsAllowed.filter(s => s == sub.Field).length > 0))
649
- if (meta.length > 0 && objetsToRemoveThisReferece.HasRelation) {
650
- let v = meta[0].Value;
651
- let changes = this.GetChanges(meta, subObj, subType);
652
- if (v instanceof Array)
653
- meta[0].Value = meta[0].Value.filter((s) => changes.indexOf(s) == -1);
654
- else if (v == changes[0])
655
- meta[0].Loaded = false;
656
- for (let c of changes) {
657
- let item = yield colletion["Where"]({ Field: subPK, Value: c })["LoadRelationOn"](objetsToRemoveThisReferece.SubField)["FirstOrDefaultAsync"]();
658
- if (item) {
659
- if (objetsToRemoveThisReferece.SubIsArray) {
660
- item[objetsToRemoveThisReferece.SubField] =
661
- item[objetsToRemoveThisReferece.SubField].filter(s => s && Reflect.get(s, key.Property) != Reflect.get(obj, key.Property));
662
- }
663
- else if (((_c = objetsToRemoveThisReferece.SubRelation) === null || _c === void 0 ? void 0 : _c.Relation) != RelationType_1.RelationType.ONE_TO_MANY) {
664
- item[objetsToRemoveThisReferece.SubField] = undefined;
665
- }
666
- yield colletion["UpdateObjectAsync"](item, false, [], [], visiteds);
667
- }
668
- }
669
- }
670
- if (isArray) {
671
- if (subObj == undefined)
672
- continue;
673
- for (let i of subObj) {
674
- if (i == undefined)
675
- continue;
676
- if (!Type_1.default.HasValue(Reflect.get(i, subPK))) {
677
- let cs = objectsToAdd.filter(s => s.Type == subType);
678
- if (cs.length == 0)
679
- objectsToAdd.push({ Objs: [i], Type: subType, SubPK: subPK });
680
- else
681
- cs[0].Objs.push(i);
682
- }
683
- else if (!hasSubrelation || (cascade || relationsAllowed.filter(s => s == sub.Field).length > 0)) {
684
- let cs = objectsToUpdate.filter(s => s.Type == subType);
685
- if (cs.length == 0)
686
- objectsToUpdate.push({ Objs: [{ Obj: i, UpdatableFields: updatableFields }], Type: subType, SubPK: subPK });
687
- else {
688
- let ccs = cs.filter(s => s.Objs.filter(j => j.Obj == i).length > 0);
689
- if (ccs.length == 0) {
690
- cs[0].Objs.push({ Obj: i, UpdatableFields: updatableFields });
691
- }
692
- else {
693
- ccs[0].Objs[0].UpdatableFields.push(...updatableFields);
694
- }
695
- }
696
- }
697
- }
698
- }
699
- else {
700
- if (subObj == undefined)
701
- continue;
702
- if (!Type_1.default.HasValue(Reflect.get(subObj, subPK))) {
703
- let cs = objectsToAdd.filter(s => s.Type == subType);
704
- if (cs.length == 0)
705
- objectsToAdd.push({ Objs: [subObj], Type: subType, SubPK: subPK });
706
- else
707
- cs[0].Objs.push(subObj);
708
- }
709
- else if (!hasSubrelation || (cascade || relationsAllowed.filter(s => s == sub.Field).length > 0)) {
710
- let cs = objectsToUpdate.filter(s => s.Type == subType);
711
- if (cs.length == 0)
712
- objectsToUpdate.push({ Objs: [{ Obj: subObj, UpdatableFields: updatableFields }], Type: subType, SubPK: subPK });
713
- else {
714
- let ccs = cs.filter(s => s.Objs.filter(j => j.Obj == subObj).length > 0);
715
- if (ccs.length == 0) {
716
- cs[0].Objs.push({ Obj: subObj, UpdatableFields: updatableFields });
717
- }
718
- else {
719
- ccs[0].Objs[0].UpdatableFields.push(...updatableFields);
720
- }
721
- }
722
- }
723
- }
724
- buildSubupdates.push(() => {
725
- let spk = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
726
- let columnType = Type_1.default.CastType(Type_1.default.GetDesingTimeTypeName(subType, spk));
727
- if ((relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.MANY_TO_MANY || (relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.ONE_TO_MANY || isArray)
728
- columnType = Type_1.default.AsArray(columnType);
729
- if (subObj == undefined)
730
- return;
731
- let updateValues = [Reflect.get(subObj, spk)];
732
- if (isArray) {
733
- updateValues = [];
734
- for (let i of subObj) {
735
- if (i == undefined)
736
- continue;
737
- updateValues.push(Reflect.get(i, spk));
738
- }
739
- }
740
- Type_1.default.InjectMetadata(obj, {
741
- Field: sub.Field,
742
- Type: columnType,
743
- Value: updateValues,
744
- Loaded: true
745
- });
746
- subTypesUpdates.push(`"${sub.Column}" = ${this.CreateValueStatement(columnType, isArray ? updateValues : updateValues[0])}`);
747
- });
748
- }
749
- objectsToAdd.forEach(o => {
750
- o.Objs = o.Objs.filter((i, ix, s) => {
751
- return ix == s.findIndex(v => v == i);
752
- });
753
- });
754
- for (let cs of objectsToAdd) {
755
- let colletion = this._context.Collection(cs.Type);
756
- for (let i of cs.Objs)
757
- yield colletion["AddObjectAsync"](i, true, [], visiteds);
758
- }
759
- for (let cs of objectsToUpdate) {
760
- let colletion = this._context.Collection(cs.Type);
761
- for (let i of cs.Objs)
762
- yield colletion["UpdateObjectAsync"](i.Obj, false, (_d = i.UpdatableFields) !== null && _d !== void 0 ? _d : [], [], visiteds);
763
- }
764
- for (let b of buildSubupdates)
765
- b();
766
- if (subTypesUpdates.length > 0) {
767
- let subUpdate = `update "${Type_1.default.GetTableName(this._type)}" set `;
768
- for (let p of subTypesUpdates) {
769
- subUpdate += `${p},`;
770
- }
771
- subUpdate = `${subUpdate.substring(0, subUpdate.length - 1)} where `;
772
- subUpdate += this.EvaluateStatement({
773
- StatementType: StatementType.WHERE,
774
- Statement: {
775
- Field: key.Property,
776
- Kind: myorm_core_1.Operation.EQUALS,
777
- Value: Reflect.get(obj, key.Property)
778
- }
779
- });
780
- yield this._manager.ExecuteNonQueryAsync(subUpdate);
781
- }
782
- return obj;
783
- }));
784
- }
785
- GetChanges(meta, subObj, subType) {
786
- let v = meta[0].Value;
787
- let subPK = SchemasDecorators_1.default.ExtractPrimaryKey(subType);
788
- let g = Reflect.get;
789
- if (v == undefined)
790
- return [];
791
- if (v instanceof Array && subObj instanceof Array)
792
- if (v.length == 0 || v.every(s => subObj.find(u => g(u, subPK) == s)))
793
- return [];
794
- else
795
- return v.filter(s => !subObj.find(u => g(u, subPK) == s));
796
- if (v instanceof Array && subObj == undefined)
797
- return v;
798
- if (v && subObj == undefined)
799
- return [v];
800
- if (v != g(subObj, subPK))
801
- return [v];
802
- return [];
803
- }
804
- DeleteSelectionAsync() {
805
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
806
- let whereSrt = PGSetHelper_1.default.ExtractWhereData(this);
807
- let query = `delete from "${this._table}"`;
808
- if (!whereSrt) {
809
- if (this._whereAsString != undefined && this._statements.length > 0) {
810
- throw new InvalidOperationException_1.default("Is not possible combine free and structured queries");
811
- }
812
- if (this._whereAsString != undefined) {
813
- query += ` ${this._whereAsString} `;
814
- }
815
- query += this.EvaluateWhere();
816
- }
817
- else {
818
- query += whereSrt;
819
- }
820
- yield this._manager.ExecuteNonQueryAsync(query);
821
- }));
822
- }
823
- DeleteAsync(obj) {
824
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
825
- if (!obj)
826
- throw new InvalidOperationException_1.default(`Cannot delete a null reference object of ${this._type.name}`);
827
- if (!this.IsCorrectType(obj))
828
- throw new InvalidOperationException_1.default(`The object passed as argument is not a ${this._type.name} instance`);
829
- let keys = Type_1.default.GetProperties(this._type).filter(p => SchemasDecorators_1.default.IsPrimaryKey(this._type, p));
830
- let wheres = [];
831
- if (keys && keys.length > 0) {
832
- keys.forEach((w, i) => {
833
- wheres.push({
834
- Statement: {
835
- Field: w,
836
- Kind: myorm_core_1.Operation.EQUALS,
837
- Value: Reflect.get(obj, w)
838
- },
839
- StatementType: i == 0 ? StatementType.WHERE : StatementType.AND
840
- });
841
- });
842
- }
843
- let del = `delete from "${this._table}" `;
844
- for (let where of wheres) {
845
- del += ` ${where.StatementType} ${this.EvaluateStatement(where)} `;
846
- }
847
- yield this._manager.ExecuteNonQueryAsync(del);
848
- return obj;
849
- }));
850
- }
851
- Where(statement) {
852
- var _a;
853
- this._statements.push({
854
- Statement: {
855
- Field: statement.Field.toString(),
856
- Kind: (_a = statement.Kind) !== null && _a !== void 0 ? _a : myorm_core_1.Operation.EQUALS,
857
- Value: statement.Value
858
- },
859
- StatementType: StatementType.WHERE
860
- });
861
- return this;
862
- }
863
- And(statement) {
864
- var _a;
865
- this._statements.push({
866
- Statement: {
867
- Field: statement.Field.toString(),
868
- Kind: (_a = statement.Kind) !== null && _a !== void 0 ? _a : myorm_core_1.Operation.EQUALS,
869
- Value: statement.Value
870
- },
871
- StatementType: StatementType.AND
872
- });
873
- return this;
874
- }
875
- Or(statement) {
876
- var _a;
877
- this._statements.push({
878
- Statement: {
879
- Field: statement.Field.toString(),
880
- Kind: (_a = statement.Kind) !== null && _a !== void 0 ? _a : myorm_core_1.Operation.EQUALS,
881
- Value: statement.Value
882
- },
883
- StatementType: StatementType.OR
884
- });
885
- return this;
886
- }
887
- OrderBy(key) {
888
- this._ordering.push({
889
- Field: key,
890
- Order: OrderDirection.ASC
891
- });
892
- return this;
893
- }
894
- Join(key) {
895
- this._includes.push({
896
- Field: key
897
- });
898
- return this;
899
- }
900
- OrderDescendingBy(key) {
901
- this._ordering.push({
902
- Field: key,
903
- Order: OrderDirection.DESC
904
- });
905
- return this;
906
- }
907
- Limit(limit) {
908
- this._limit = limit >= 1 ? { Limit: limit } : undefined;
909
- return this;
910
- }
911
- Offset(offset) {
912
- this._offset = offset >= 1 ? { OffSet: offset } : undefined;
913
- return this;
914
- }
915
- Take(quantity) {
916
- return this.Limit(quantity);
917
- }
918
- CountAsync() {
919
- return __awaiter(this, void 0, void 0, function* () {
920
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
921
- let query = `select count(*) from "${this._table}"`;
922
- if (this._whereAsString != undefined && this._statements.length > 0) {
923
- throw new InvalidOperationException_1.default("Is not possible combine free and structured queries");
924
- }
925
- if (this._whereAsString != undefined) {
926
- query += ` ${this._whereAsString} `;
927
- }
928
- query += this.EvaluateWhere();
929
- let ordenation = "";
930
- for (let orderby of this._ordering) {
931
- ordenation += `${this.EvaluateOrderBy(orderby)},`;
932
- }
933
- if (this._ordering.length > 0) {
934
- query += ` order by ${ordenation.substring(0, ordenation.length - 1)}`;
935
- }
936
- if (this._offset != undefined) {
937
- query += ` offset ${this._offset.OffSet}`;
938
- }
939
- if (this._limit != undefined) {
940
- query += ` limit ${this._limit.Limit}`;
941
- }
942
- var r = yield this._manager.ExecuteAsync(query);
943
- this.Reset();
944
- if (!r || r.rows.length == 0)
945
- return 0;
946
- return r.rows[0].count;
947
- }));
948
- });
949
- }
950
- ToListAsync() {
951
- return __awaiter(this, void 0, void 0, function* () {
952
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
953
- let whereSrt = PGSetHelper_1.default.ExtractWhereData(this);
954
- let sqlSrt = PGSetHelper_1.default.ExtractSQLData(this);
955
- let query = `select "${this._table}".* from "${this._table}"`;
956
- if (sqlSrt && sqlSrt.toLowerCase().trim().startsWith(`select distinct "${this._table}".*`))
957
- query = sqlSrt;
958
- if (!whereSrt) {
959
- if (this._whereAsString != undefined && this._statements.length > 0) {
960
- throw new InvalidOperationException_1.default("Is not possible combine free and structured queries");
961
- }
962
- if (this._whereAsString != undefined) {
963
- query += ` ${this._whereAsString} `;
964
- }
965
- query += this.EvaluateWhere();
966
- }
967
- else {
968
- query += whereSrt;
969
- }
970
- let ordenation = "";
971
- for (let orderby of this._ordering) {
972
- ordenation += `${this.EvaluateOrderBy(orderby)},`;
973
- }
974
- if (this._ordering.length > 0) {
975
- query += ` order by ${ordenation.substring(0, ordenation.length - 1)}`;
976
- }
977
- if (this._offset != undefined) {
978
- query += ` offset ${this._offset.OffSet}`;
979
- }
980
- if (this._limit != undefined) {
981
- query += ` limit ${this._limit.Limit}`;
982
- }
983
- var r = yield this._manager.ExecuteAsync(query);
984
- if (r.rows.length == 0) {
985
- this.Reset();
986
- return [];
987
- }
988
- let list = [];
989
- list = yield this.BuildObjects(r);
990
- this.Reset();
991
- return list;
992
- }));
993
- });
994
- }
995
- FirstOrDefaultAsync() {
996
- return __awaiter(this, void 0, void 0, function* () {
997
- return this.CreatePromisse(() => __awaiter(this, void 0, void 0, function* () {
998
- let rows = yield this.Limit(1).ToListAsync();
999
- if (rows && rows.length > 0)
1000
- return rows[0];
1001
- return undefined;
1002
- }));
1003
- });
1004
- }
1005
- WhereField(field) {
1006
- this.ResetFilters();
1007
- return new PGFluentField_1.default(this, field, false);
1008
- }
1009
- AndField(field) {
1010
- return new PGFluentField_1.default(this, field, false);
1011
- }
1012
- OrField(field) {
1013
- return new PGFluentField_1.default(this, field, true);
1014
- }
1015
- WhereAsString(where) {
1016
- this.ResetFilters();
1017
- if (where && !where.trim().toLocaleLowerCase().startsWith("where")) {
1018
- where = `where ${where}`;
1019
- }
1020
- this._whereAsString = where;
1021
- return this;
1022
- }
1023
- LoadRelationOn(field) {
1024
- return this.Join(field);
1025
- }
1026
- CreatePromisse(func) {
1027
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
1028
- try {
1029
- resolve(yield func());
1030
- }
1031
- catch (err) {
1032
- reject(err);
1033
- }
1034
- finally {
1035
- this.Reset();
1036
- }
1037
- }));
1038
- }
1039
- CleanQueryTree() {
1040
- this.Reset();
1041
- }
1042
- CreateValueStatement(colType, value) {
1043
- if (value == undefined || value == null)
1044
- return 'null';
1045
- if (colType == DBTypes_1.DBTypes.TEXT) {
1046
- return `$$${value}$$`;
1047
- }
1048
- else if (colType == DBTypes_1.DBTypes.BOOLEAN) {
1049
- return `${value.toString().toLowerCase()}`;
1050
- }
1051
- else if (Type_1.default.IsNumber(colType)) {
1052
- if (isNaN(value))
1053
- throw new InvalidOperationException_1.default(`Can not cast the value "${value}" in a number`);
1054
- return `${value}`.replace(',', '.');
1055
- }
1056
- else if (Type_1.default.IsDate(colType)) {
1057
- let dt;
1058
- if (value.constructor == Date)
1059
- dt = value;
1060
- else
1061
- dt = new Date(value.toString());
1062
- if (!dt)
1063
- throw new InvalidOperationException_1.default(`Can not cast the value: "${value}" in a valid date`);
1064
- let dtStr = `${dt.getFullYear()}-${dt.getMonth() + 1}-${dt.getDate()}`;
1065
- if (colType == DBTypes_1.DBTypes.DATE) {
1066
- return `'${dtStr}'::date`;
1067
- }
1068
- else {
1069
- return `'${dtStr} ${dt.getHours()}:${dt.getMinutes()}'::timestamp`;
1070
- }
1071
- }
1072
- else if (Type_1.default.IsArray(colType)) {
1073
- let valuesStr = 'array[';
1074
- let elementType = Type_1.default.ExtractElementType(colType);
1075
- let hasItens = false;
1076
- for (let i of value) {
1077
- hasItens = true;
1078
- valuesStr += `${this.CreateValueStatement(elementType, i)},`;
1079
- }
1080
- if (hasItens)
1081
- valuesStr = valuesStr.substring(0, valuesStr.length - 1);
1082
- valuesStr += `]::${this._manager["CastToPostgreSQLType"](colType)}`;
1083
- return valuesStr;
1084
- }
1085
- throw new TypeNotSuportedException_1.default(`The type ${colType} is not suported`);
1086
- }
1087
- EvaluateWhere() {
1088
- let query = "";
1089
- for (let i = 0; i < this._statements.length; i++) {
1090
- let where = this._statements[i];
1091
- if (i == 0 && where.StatementType != StatementType.WHERE)
1092
- throw new InvalidOperationException_1.default(`The query three must start with a WHERE statement`);
1093
- if (i > 0 && where.StatementType == StatementType.WHERE)
1094
- where.StatementType = StatementType.AND;
1095
- query += ` ${where.StatementType} ${this.EvaluateStatement(where)} `;
1096
- }
1097
- return query;
1098
- }
1099
- EvaluateStatement(pgStatement) {
1100
- let column = Type_1.default.GetColumnName(this._type, pgStatement.Statement.Field.toString());
1101
- let typeName = Type_1.default.GetDesingTimeTypeName(this._type, pgStatement.Statement.Field.toString());
1102
- let operation = this.GetOperators(pgStatement.Statement.Kind);
1103
- let type = Type_1.default.GetDesingType(this._type, pgStatement.Statement.Field.toString());
1104
- let isArray = type == Array;
1105
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, pgStatement.Statement.Field.toString());
1106
- if (!type) {
1107
- if (!relation) {
1108
- throw new InvalidOperationException_1.default(`Can not determine the correct type conversion for propety ${pgStatement.Statement.Field.toString()}`);
1109
- }
1110
- type = relation.TypeBuilder();
1111
- }
1112
- if (pgStatement.Statement.Value == undefined)
1113
- return `"${this._table}".${column} is null`;
1114
- if (this._context.IsMapped(type) || (relation && this._context.IsMapped(relation.TypeBuilder()))) {
1115
- if (!relation)
1116
- throw new InvalidOperationException_1.default(`Can not determine the correct type conversion for propety ${pgStatement.Statement.Field.toString()}`);
1117
- if (isArray) {
1118
- if (pgStatement.Statement.Value.lenght == 0)
1119
- return `coalesce(array_length("${this._table}".${column}, 1), 0) = 0`;
1120
- if (pgStatement.Statement.Value.filter(s => s == undefined || s == null).length > 0)
1121
- throw new InvalidOperationException_1.default(`Can not compare relations with null or undefined objets`);
1122
- let c = pgStatement.Statement.Value[0];
1123
- let k = SchemasDecorators_1.default.ExtractPrimaryKey(c.constructor);
1124
- if (!k)
1125
- throw new ConstraintFailException_1.default(`The type ${c.constructor.name} must have a key field`);
1126
- let elementType = Type_1.default.GetDesingTimeTypeName(c.constructor, k);
1127
- let internalType = Type_1.default.CastType(elementType);
1128
- let keyType = Type_1.default.AsArray(internalType);
1129
- let newValues = [];
1130
- for (let e of pgStatement.Statement.Value) {
1131
- newValues = [e[k]];
1132
- }
1133
- typeName = keyType;
1134
- pgStatement.Statement.Value = newValues;
1135
- }
1136
- else {
1137
- let k = SchemasDecorators_1.default.ExtractPrimaryKey(pgStatement.Statement.Value.constructor);
1138
- if (!k)
1139
- throw new ConstraintFailException_1.default(`The type ${pgStatement.Statement.Value.constructor.name} must have a key field`);
1140
- let elementType = Type_1.default.GetDesingTimeTypeName(pgStatement.Statement.Value.constructor, k);
1141
- let internalType = Type_1.default.CastType(elementType);
1142
- typeName = internalType;
1143
- pgStatement.Statement.Value = pgStatement.Statement.Value[k];
1144
- }
1145
- }
1146
- if (isArray) {
1147
- if (!typeName)
1148
- throw new InvalidOperationException_1.default(`Can not determine the correct type conversion for propety ${pgStatement.Statement.Field.toString()}`);
1149
- if (pgStatement.Statement.Kind == myorm_core_1.Operation.EQUALS) {
1150
- return `"${this._table}".${column} = ${this.CreateValueStatement(typeName, pgStatement.Statement.Value)}`;
1151
- }
1152
- if (pgStatement.Statement.Kind == myorm_core_1.Operation.NOTEQUALS) {
1153
- return `"${this._table}".${column} != ${this.CreateValueStatement(typeName, pgStatement.Statement.Value)}`;
1154
- }
1155
- if (pgStatement.Statement.Kind == myorm_core_1.Operation.SMALLER || pgStatement.Statement.Kind == myorm_core_1.Operation.SMALLEROREQUALS) {
1156
- return `"${this._table}".${column} <@ ${this.CreateValueStatement(typeName, pgStatement.Statement.Value)}`;
1157
- }
1158
- if ([myorm_core_1.Operation.STARTWITH, myorm_core_1.Operation.CONSTAINS, myorm_core_1.Operation.ENDWITH, myorm_core_1.Operation.GREATHER, myorm_core_1.Operation.GREATHEROREQUALS].includes(pgStatement.Statement.Kind)) {
1159
- return `"${this._table}".${column} @> ${this.CreateValueStatement(typeName, pgStatement.Statement.Value)}`;
1160
- }
1161
- }
1162
- if (Type_1.default.IsNumber(Type_1.default.CastType(typeName.toString())) || Type_1.default.IsDate(Type_1.default.CastType(typeName.toString()))) {
1163
- operation[1] = "";
1164
- operation[2] = "";
1165
- if (Type_1.default.IsDate(Type_1.default.CastType(typeName.toString()))) {
1166
- let dt = pgStatement.Statement.Value;
1167
- if (!dt)
1168
- throw new InvalidOperationException_1.default(`Can not cast the value: "${pgStatement.Statement.Value}" in a valid date`);
1169
- let dtStr = `${dt.getFullYear()}-${dt.getMonth() + 1}-${dt.getDate()}`;
1170
- if (Type_1.default.CastType(typeName.toString()) == DBTypes_1.DBTypes.DATE) {
1171
- pgStatement.Statement.Value = `'${dtStr}'::date`;
1172
- }
1173
- else {
1174
- pgStatement.Statement.Value = `'${dtStr} ${dt.getHours()}:${dt.getMinutes()}'::timestamp`;
1175
- }
1176
- }
1177
- if ([myorm_core_1.Operation.CONSTAINS, myorm_core_1.Operation.ENDWITH, myorm_core_1.Operation.STARTWITH].filter(s => s == pgStatement.Statement.Kind).length > 0) {
1178
- throw new InvalidOperationException_1.default(`Can execute ${pgStatement.Statement.Kind.toString().toLocaleLowerCase()} only with text and array fields`);
1179
- }
1180
- }
1181
- else {
1182
- operation[1] = `$$${operation[1]}`;
1183
- operation[2] = `${operation[2]}$$`;
1184
- }
1185
- return `"${this._table}".${column} ${operation[0]} ${operation[1]}${pgStatement.Statement.Value}${operation[2]}`;
1186
- }
1187
- EvaluateOrderBy(ordering) {
1188
- let column = Type_1.default.GetColumnName(this._type, ordering.Field.toString());
1189
- return ` "${this._table}".${column} ${ordering.Order}`;
1190
- }
1191
- GetOperators(operation) {
1192
- switch (operation) {
1193
- case myorm_core_1.Operation.EQUALS: return ["=", "", ""];
1194
- case myorm_core_1.Operation.CONSTAINS: return ["ilike", "%", "%"];
1195
- case myorm_core_1.Operation.STARTWITH:
1196
- return ["ilike", "", "%"];
1197
- ;
1198
- case myorm_core_1.Operation.ENDWITH:
1199
- return ["ilike", "%", ""];
1200
- ;
1201
- case myorm_core_1.Operation.GREATHER:
1202
- return [">", "", ""];
1203
- ;
1204
- case myorm_core_1.Operation.GREATHEROREQUALS:
1205
- return [">=", "", ""];
1206
- ;
1207
- case myorm_core_1.Operation.SMALLER:
1208
- return ["<", "", ""];
1209
- ;
1210
- case myorm_core_1.Operation.SMALLEROREQUALS:
1211
- return ["<=", "", ""];
1212
- ;
1213
- case myorm_core_1.Operation.NOTEQUALS:
1214
- return ["!=", "", ""];
1215
- ;
1216
- default: throw new NotImplementedException_1.default(`The operation ${operation} is not supported`);
1217
- }
1218
- }
1219
- Reset() {
1220
- this._ordering = [];
1221
- this._includes = [];
1222
- this._limit = undefined;
1223
- this._set = new PGSetValue();
1224
- this.ResetFilters();
1225
- }
1226
- ResetFilters() {
1227
- this._statements = [];
1228
- this._whereAsString = undefined;
1229
- PGSetHelper_1.default.CleanORMData(this);
1230
- }
1231
- IsCorrectType(obj) {
1232
- let sameCTor = obj && obj.constructor && obj.constructor == this._type;
1233
- if (sameCTor)
1234
- return true;
1235
- if (obj.prototype == this._type)
1236
- return true;
1237
- if (obj.prototype && obj.prototype.constructor == this._type)
1238
- return true;
1239
- let objectKeys = Object.keys(obj);
1240
- for (let map of this._maps) {
1241
- let v = obj[map.Field];
1242
- if (v == undefined) {
1243
- let exists = objectKeys.filter(s => s == map.Field).length > 0;
1244
- if (!exists) {
1245
- let allowNull = SchemasDecorators_1.default.AllowNullValue(this._type, map.Field);
1246
- if (!allowNull)
1247
- return false;
1248
- }
1249
- }
1250
- }
1251
- obj.__proto__ = this._type;
1252
- return true;
1253
- }
1254
- BuildObjects(r) {
1255
- return __awaiter(this, void 0, void 0, function* () {
1256
- let list = [];
1257
- for (let row of r.rows) {
1258
- let instance = Reflect.construct(this._type, []);
1259
- for (let map of this._maps) {
1260
- let type = Type_1.default.GetDesingType(this._type, map.Field);
1261
- let relation = SchemasDecorators_1.default.GetRelationAttribute(this._type, map.Field);
1262
- if ((!type || type === Array) && relation)
1263
- type = relation.TypeBuilder();
1264
- if (!this._context.IsMapped(type)) {
1265
- let v = Reflect.get(row, map.Column);
1266
- let vType = Type_1.default.CastType(map.Type);
1267
- if (v != undefined) {
1268
- if ([DBTypes_1.DBTypes.INTEGER, DBTypes_1.DBTypes.LONG, DBTypes_1.DBTypes.SERIAL].includes(vType))
1269
- Reflect.set(instance, map.Field, Number.parseInt(v));
1270
- else if (DBTypes_1.DBTypes.DOUBLE == vType)
1271
- Reflect.set(instance, map.Field, Number.parseFloat(v));
1272
- else if ([DBTypes_1.DBTypes.DATE, DBTypes_1.DBTypes.DATETIME].includes(vType)) {
1273
- try {
1274
- v = new Date(v);
1275
- }
1276
- catch (_a) { }
1277
- Reflect.set(instance, map.Field, v);
1278
- }
1279
- else if (DBTypes_1.DBTypes.TEXT == vType)
1280
- Reflect.set(instance, map.Field, v.toString());
1281
- else
1282
- Reflect.set(instance, map.Field, v);
1283
- }
1284
- else
1285
- Reflect.set(instance, map.Field, v);
1286
- }
1287
- else {
1288
- if (Reflect.get(row, map.Column) == undefined) {
1289
- if (this._includes.filter(s => s.Field == map.Field).length > 0) {
1290
- Type_1.default.InjectMetadata(instance, {
1291
- Field: map.Field,
1292
- Type: map.Type,
1293
- Value: Reflect.get(row, map.Column),
1294
- Loaded: true
1295
- });
1296
- }
1297
- continue;
1298
- }
1299
- let includeType = this._includes.filter(s => s.Field == map.Field);
1300
- let loaded = false;
1301
- if (includeType.length > 0) {
1302
- loaded = true;
1303
- let colletion = this._context.Collection(type);
1304
- if (colletion == undefined)
1305
- continue;
1306
- colletion["Reset"]();
1307
- let subKey = SchemasDecorators_1.default.ExtractPrimaryKey(type);
1308
- if ((relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.MANY_TO_MANY || (relation === null || relation === void 0 ? void 0 : relation.Relation) == RelationType_1.RelationType.ONE_TO_MANY) {
1309
- let values = Reflect.get(row, map.Column);
1310
- if (!values || values.length == 0) {
1311
- Reflect.set(instance, map.Field, []);
1312
- }
1313
- else {
1314
- colletion.Where({
1315
- Field: subKey,
1316
- Kind: myorm_core_1.Operation.EQUALS,
1317
- Value: values[0]
1318
- });
1319
- for (let i = 0; i < values.length; i++) {
1320
- if (i == 0)
1321
- continue;
1322
- colletion.Or({
1323
- Field: subKey,
1324
- Kind: myorm_core_1.Operation.EQUALS,
1325
- Value: values[i]
1326
- });
1327
- }
1328
- let subObjets = yield colletion.ToListAsync();
1329
- Reflect.set(instance, map.Field, subObjets);
1330
- }
1331
- }
1332
- else {
1333
- colletion.Where({
1334
- Field: subKey,
1335
- Kind: myorm_core_1.Operation.EQUALS,
1336
- Value: Reflect.get(row, map.Column)
1337
- });
1338
- let subObjet = yield colletion.FirstOrDefaultAsync();
1339
- Reflect.set(instance, map.Field, subObjet);
1340
- }
1341
- }
1342
- Type_1.default.InjectMetadata(instance, {
1343
- Field: map.Field,
1344
- Type: map.Type,
1345
- Value: Reflect.get(row, map.Column),
1346
- Loaded: loaded
1347
- });
1348
- }
1349
- }
1350
- list.push(instance);
1351
- }
1352
- return list;
1353
- });
1354
- }
1355
- }
1356
- exports.default = PGDBSet;
1357
- class PGSetValue {
1358
- constructor() {
1359
- this._sets = [];
1360
- }
1361
- Add(key, value) {
1362
- let i = this._sets.filter(s => s.Key == key);
1363
- if (i.length > 0) {
1364
- i[0].Value = value;
1365
- }
1366
- else {
1367
- this._sets.push({ Key: key, Value: value });
1368
- }
1369
- }
1370
- Get() {
1371
- return this._sets;
1372
- }
1373
- }
1374
- var OrderDirection;
1375
- (function (OrderDirection) {
1376
- OrderDirection["ASC"] = "asc";
1377
- OrderDirection["DESC"] = "desc";
1378
- })(OrderDirection || (OrderDirection = {}));
1379
- var StatementType;
1380
- (function (StatementType) {
1381
- StatementType["WHERE"] = "where";
1382
- StatementType["OR"] = "or";
1383
- StatementType["AND"] = "and";
1384
- })(StatementType || (StatementType = {}));
1385
- //# sourceMappingURL=PGDBSet.js.map