tspace-mysql 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -15
- package/dist/cli/index.js +10 -6
- package/dist/cli/migrate/make.d.ts +3 -1
- package/dist/cli/migrate/make.js +9 -9
- package/dist/cli/models/make.d.ts +3 -1
- package/dist/cli/models/make.js +13 -16
- package/dist/cli/tables/make.d.ts +3 -1
- package/dist/cli/tables/make.js +20 -21
- package/dist/cli/tables/table.js +1 -1
- package/dist/lib/connections/options.d.ts +1 -1
- package/dist/lib/{utils/constant.d.ts → constants/index.d.ts} +1 -1
- package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/tspace/DB.js +7 -4
- package/dist/lib/tspace/Database.d.ts +4 -0
- package/dist/lib/tspace/Database.js +122 -58
- package/dist/lib/tspace/Interface.d.ts +1 -1
- package/dist/lib/tspace/Logger.js +4 -3
- package/dist/lib/tspace/Model.d.ts +3 -1
- package/dist/lib/tspace/Model.js +139 -136
- package/dist/lib/tspace/Schema.d.ts +3 -2
- package/dist/lib/tspace/Schema.js +0 -2
- package/dist/lib/utils/index.d.ts +1 -1
- package/dist/lib/utils/index.js +3 -3
- package/package.json +1 -1
|
@@ -139,6 +139,23 @@ var Database = /** @class */ (function (_super) {
|
|
|
139
139
|
this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(select));
|
|
140
140
|
return this;
|
|
141
141
|
};
|
|
142
|
+
Database.prototype.chunk = function (chunk) {
|
|
143
|
+
this.$db.set('CHUNK', chunk);
|
|
144
|
+
return this;
|
|
145
|
+
};
|
|
146
|
+
Database.prototype.when = function (value, cb) {
|
|
147
|
+
if (value)
|
|
148
|
+
cb(this);
|
|
149
|
+
return this;
|
|
150
|
+
};
|
|
151
|
+
Database.prototype.whereRaw = function (query) {
|
|
152
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
153
|
+
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(query));
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(query));
|
|
157
|
+
return this;
|
|
158
|
+
};
|
|
142
159
|
Database.prototype.where = function (column, operator, value) {
|
|
143
160
|
var _a;
|
|
144
161
|
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
@@ -146,39 +163,43 @@ var Database = /** @class */ (function (_super) {
|
|
|
146
163
|
value = this._valueTrueFalse(value);
|
|
147
164
|
if (operator === this.$utils().constants('LIKE'))
|
|
148
165
|
value = "%".concat(value, "%");
|
|
149
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
166
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
150
167
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
151
|
-
|
|
152
|
-
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
153
171
|
return this;
|
|
154
172
|
};
|
|
155
173
|
Database.prototype.whereId = function (id) {
|
|
156
174
|
var column = 'id';
|
|
157
175
|
var operator = '=';
|
|
158
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
176
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
159
177
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
|
|
160
|
-
|
|
161
|
-
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
|
|
162
181
|
return this;
|
|
163
182
|
};
|
|
164
183
|
Database.prototype.whereEmail = function (email) {
|
|
165
184
|
var column = 'email';
|
|
166
185
|
var operator = '=';
|
|
167
186
|
email = this.$utils().escape(email);
|
|
168
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
187
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
169
188
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(email, "'"));
|
|
170
|
-
|
|
171
|
-
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(operator, " '").concat(email, "'"));
|
|
172
192
|
return this;
|
|
173
193
|
};
|
|
174
194
|
Database.prototype.whereUser = function (id) {
|
|
175
195
|
var column = 'user_id';
|
|
176
196
|
var operator = '=';
|
|
177
197
|
id = this.$utils().escape(id);
|
|
178
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
198
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
179
199
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
|
|
182
203
|
return this;
|
|
183
204
|
};
|
|
184
205
|
Database.prototype.orWhere = function (column, operator, value) {
|
|
@@ -187,20 +208,20 @@ var Database = /** @class */ (function (_super) {
|
|
|
187
208
|
value = this.$utils().escape(value);
|
|
188
209
|
if (operator === this.$utils().constants('LIKE'))
|
|
189
210
|
value = "%".concat(value, "%");
|
|
190
|
-
if (this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
211
|
+
if (this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
191
212
|
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('OR'), " ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
192
|
-
|
|
193
|
-
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
194
216
|
return this;
|
|
195
217
|
};
|
|
196
218
|
Database.prototype.whereIn = function (column, arrayValues) {
|
|
197
|
-
var sql = this.$db.get('WHERE');
|
|
198
219
|
if (!Array.isArray(arrayValues))
|
|
199
220
|
throw new Error("[".concat(arrayValues, "] is't array"));
|
|
200
221
|
if (!arrayValues.length)
|
|
201
222
|
arrayValues = ['0'];
|
|
202
223
|
var values = "".concat(arrayValues.map(function (value) { return "'".concat(value, "'"); }).join(','));
|
|
203
|
-
if (!
|
|
224
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
204
225
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(values, ")"));
|
|
205
226
|
return this;
|
|
206
227
|
}
|
|
@@ -238,28 +259,31 @@ var Database = /** @class */ (function (_super) {
|
|
|
238
259
|
Database.prototype.whereSubQuery = function (column, subQuery) {
|
|
239
260
|
var whereSubQuery = this.$db.get('WHERE');
|
|
240
261
|
subQuery = this.$utils().escapeSubQuery(subQuery);
|
|
241
|
-
if (!whereSubQuery.includes(this.$utils().constants('WHERE')))
|
|
262
|
+
if (!whereSubQuery.includes(this.$utils().constants('WHERE'))) {
|
|
242
263
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(subQuery, ")"));
|
|
243
|
-
|
|
244
|
-
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(subQuery, ")"));
|
|
245
267
|
return this;
|
|
246
268
|
};
|
|
247
269
|
Database.prototype.whereNotInSubQuery = function (column, subQuery) {
|
|
248
270
|
var whereSubQuery = this.$db.get('WHERE');
|
|
249
271
|
subQuery = this.$utils().escapeSubQuery(subQuery);
|
|
250
|
-
if (!whereSubQuery.includes(this.$utils().constants('WHERE')))
|
|
272
|
+
if (!whereSubQuery.includes(this.$utils().constants('WHERE'))) {
|
|
251
273
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(subQuery, ")"));
|
|
252
|
-
|
|
253
|
-
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(this.$utils().constants('NOT_IN'), " (").concat(subQuery, ")"));
|
|
254
277
|
return this;
|
|
255
278
|
};
|
|
256
279
|
Database.prototype.orWhereSubQuery = function (column, subQuery) {
|
|
257
280
|
var whereSubQuery = this.$db.get('WHERE');
|
|
258
281
|
subQuery = this.$utils().escapeSubQuery(subQuery);
|
|
259
|
-
if (!whereSubQuery.includes(this.$utils().constants('WHERE')))
|
|
282
|
+
if (!whereSubQuery.includes(this.$utils().constants('WHERE'))) {
|
|
260
283
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(subQuery, ")"));
|
|
261
|
-
|
|
262
|
-
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('OR'), " ").concat(column, " ").concat(this.$utils().constants('IN'), " (").concat(subQuery, ")"));
|
|
263
287
|
return this;
|
|
264
288
|
};
|
|
265
289
|
Database.prototype.whereBetween = function (column, arrayValue) {
|
|
@@ -279,17 +303,19 @@ var Database = /** @class */ (function (_super) {
|
|
|
279
303
|
return this;
|
|
280
304
|
};
|
|
281
305
|
Database.prototype.whereNull = function (column) {
|
|
282
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
306
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
283
307
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IS_NULL')));
|
|
284
|
-
|
|
285
|
-
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(this.$utils().constants('IS_NULL')));
|
|
286
311
|
return this;
|
|
287
312
|
};
|
|
288
313
|
Database.prototype.whereNotNull = function (column) {
|
|
289
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
314
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
290
315
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(this.$utils().constants('IS_NOT_NULL')));
|
|
291
|
-
|
|
292
|
-
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(this.$utils().constants('IS_NOT_NULL')));
|
|
293
319
|
return this;
|
|
294
320
|
};
|
|
295
321
|
Database.prototype.whereSensitive = function (column, operator, value) {
|
|
@@ -297,12 +323,11 @@ var Database = /** @class */ (function (_super) {
|
|
|
297
323
|
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
298
324
|
value = this.$utils().escape(value);
|
|
299
325
|
value = this._valueTrueFalse(value);
|
|
300
|
-
if (
|
|
301
|
-
value = "%".concat(value, "%");
|
|
302
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
326
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
303
327
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " BINARY ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
304
|
-
|
|
305
|
-
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " BINARY ").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
306
331
|
return this;
|
|
307
332
|
};
|
|
308
333
|
Database.prototype.whereGroupStart = function (column, operator, value) {
|
|
@@ -312,10 +337,11 @@ var Database = /** @class */ (function (_super) {
|
|
|
312
337
|
value = this._valueTrueFalse(value);
|
|
313
338
|
if (operator === this.$utils().constants('LIKE'))
|
|
314
339
|
value = "%".concat(value, "%");
|
|
315
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
340
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
316
341
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " (").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
317
|
-
|
|
318
|
-
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " (").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
319
345
|
return this;
|
|
320
346
|
};
|
|
321
347
|
Database.prototype.orWhereGroupStart = function (column, operator, value) {
|
|
@@ -325,10 +351,11 @@ var Database = /** @class */ (function (_super) {
|
|
|
325
351
|
value = this._valueTrueFalse(value);
|
|
326
352
|
if (operator === this.$utils().constants('LIKE'))
|
|
327
353
|
value = "%".concat(value, "%");
|
|
328
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
354
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
329
355
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " (").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
330
|
-
|
|
331
|
-
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " (").concat(column, " ").concat(operator, " '").concat(value, "'"));
|
|
332
359
|
return this;
|
|
333
360
|
};
|
|
334
361
|
Database.prototype.whereGroupEnd = function (column, operator, value) {
|
|
@@ -338,10 +365,11 @@ var Database = /** @class */ (function (_super) {
|
|
|
338
365
|
value = this._valueTrueFalse(value);
|
|
339
366
|
if (operator === this.$utils().constants('LIKE'))
|
|
340
367
|
value = "%".concat(value, "%");
|
|
341
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
368
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
342
369
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(value, "')"));
|
|
343
|
-
|
|
344
|
-
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
372
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('OR'), " ").concat(column, " ").concat(operator, " '").concat(value, "')"));
|
|
345
373
|
return this;
|
|
346
374
|
};
|
|
347
375
|
Database.prototype.orWhereGroupEnd = function (column, operator, value) {
|
|
@@ -351,10 +379,11 @@ var Database = /** @class */ (function (_super) {
|
|
|
351
379
|
value = this._valueTrueFalse(value);
|
|
352
380
|
if (operator === this.$utils().constants('LIKE'))
|
|
353
381
|
value = "%".concat(value, "%");
|
|
354
|
-
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE')))
|
|
382
|
+
if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
|
|
355
383
|
this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(value, "')"));
|
|
356
|
-
|
|
357
|
-
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('OR'), " ").concat(column, " ").concat(operator, " '").concat(value, "')"));
|
|
358
387
|
return this;
|
|
359
388
|
};
|
|
360
389
|
Database.prototype.having = function (condition) {
|
|
@@ -364,19 +393,21 @@ var Database = /** @class */ (function (_super) {
|
|
|
364
393
|
Database.prototype.join = function (pk, fk) {
|
|
365
394
|
var _a;
|
|
366
395
|
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
367
|
-
if (this.$db.get('JOIN'))
|
|
396
|
+
if (this.$db.get('JOIN')) {
|
|
368
397
|
this.$db.set('JOIN', "".concat(this.$db.get('JOIN'), " ").concat(this.$utils().constants('INNER_JOIN'), " ").concat(table, " ").concat(this.$utils().constants('ON'), " ").concat(pk, " = ").concat(fk));
|
|
369
|
-
|
|
370
|
-
|
|
398
|
+
return this;
|
|
399
|
+
}
|
|
400
|
+
this.$db.set('JOIN', "".concat(this.$utils().constants('INNER_JOIN'), " ").concat(table, " ").concat(this.$utils().constants('ON'), " ").concat(pk, " = ").concat(fk));
|
|
371
401
|
return this;
|
|
372
402
|
};
|
|
373
403
|
Database.prototype.rightJoin = function (pk, fk) {
|
|
374
404
|
var _a;
|
|
375
405
|
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
376
|
-
if (this.$db.get('JOIN'))
|
|
406
|
+
if (this.$db.get('JOIN')) {
|
|
377
407
|
this.$db.set('JOIN', "".concat(this.$db.get('JOIN'), " ").concat(this.$utils().constants('RIGHT_JOIN'), " ").concat(table, " ").concat(this.$utils().constants('ON'), " ").concat(pk, " = ").concat(fk));
|
|
378
|
-
|
|
379
|
-
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
this.$db.set('JOIN', "".concat(this.$utils().constants('RIGHT_JOIN'), " ").concat(table, " ").concat(this.$utils().constants('ON'), " ").concat(pk, " = ").concat(fk));
|
|
380
411
|
return this;
|
|
381
412
|
};
|
|
382
413
|
Database.prototype.leftJoin = function (pk, fk) {
|
|
@@ -609,6 +640,8 @@ var Database = /** @class */ (function (_super) {
|
|
|
609
640
|
return __generator(this, function (_f) {
|
|
610
641
|
switch (_f.label) {
|
|
611
642
|
case 0:
|
|
643
|
+
page = +page;
|
|
644
|
+
limit = +limit;
|
|
612
645
|
currentPage = page;
|
|
613
646
|
nextPage = currentPage + 1;
|
|
614
647
|
prevPage = currentPage - 1 === 0 ? 1 : currentPage - 1;
|
|
@@ -707,7 +740,8 @@ var Database = /** @class */ (function (_super) {
|
|
|
707
740
|
Database.prototype.get = function () {
|
|
708
741
|
var _a;
|
|
709
742
|
return __awaiter(this, void 0, void 0, function () {
|
|
710
|
-
var sql, result;
|
|
743
|
+
var sql, result, data;
|
|
744
|
+
var _this = this;
|
|
711
745
|
return __generator(this, function (_b) {
|
|
712
746
|
switch (_b.label) {
|
|
713
747
|
case 0:
|
|
@@ -717,6 +751,16 @@ var Database = /** @class */ (function (_super) {
|
|
|
717
751
|
result = _b.sent();
|
|
718
752
|
if ((_a = this.$db.get('HIDDEN')) === null || _a === void 0 ? void 0 : _a.length)
|
|
719
753
|
this._hiddenColumn(result);
|
|
754
|
+
if (this.$db.get('CHUNK')) {
|
|
755
|
+
data = result.reduce(function (resultArray, item, index) {
|
|
756
|
+
var chunkIndex = Math.floor(index / _this.$db.get('CHUNK'));
|
|
757
|
+
if (!resultArray[chunkIndex])
|
|
758
|
+
resultArray[chunkIndex] = [];
|
|
759
|
+
resultArray[chunkIndex].push(item);
|
|
760
|
+
return resultArray;
|
|
761
|
+
}, []);
|
|
762
|
+
return [2 /*return*/, data || []];
|
|
763
|
+
}
|
|
720
764
|
return [2 /*return*/, result || []];
|
|
721
765
|
}
|
|
722
766
|
});
|
|
@@ -791,7 +835,7 @@ var Database = /** @class */ (function (_super) {
|
|
|
791
835
|
return __generator(this, function (_a) {
|
|
792
836
|
switch (_a.label) {
|
|
793
837
|
case 0:
|
|
794
|
-
sql = "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('EXISTS'), "(").concat(this.$utils().constants('SELECT'), " * ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE'), " LIMIT 1) as 'exists'");
|
|
838
|
+
sql = "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('EXISTS'), "(").concat(this.$utils().constants('SELECT'), " * ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('LIMIT'), " 1) as 'exists'");
|
|
795
839
|
return [4 /*yield*/, this._queryStatement(sql)];
|
|
796
840
|
case 1:
|
|
797
841
|
result = _a.sent();
|
|
@@ -888,6 +932,24 @@ var Database = /** @class */ (function (_super) {
|
|
|
888
932
|
});
|
|
889
933
|
});
|
|
890
934
|
};
|
|
935
|
+
Database.prototype.forceDelete = function () {
|
|
936
|
+
var _a;
|
|
937
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
938
|
+
var result;
|
|
939
|
+
return __generator(this, function (_b) {
|
|
940
|
+
switch (_b.label) {
|
|
941
|
+
case 0:
|
|
942
|
+
this.$db.set('DELETE', "".concat(this.$utils().constants('DELETE'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE')));
|
|
943
|
+
return [4 /*yield*/, this._actionStatement({ sql: this.$db.get('DELETE') })];
|
|
944
|
+
case 1:
|
|
945
|
+
result = _b.sent();
|
|
946
|
+
if (result)
|
|
947
|
+
return [2 /*return*/, (_a = !!result) !== null && _a !== void 0 ? _a : false];
|
|
948
|
+
return [2 /*return*/, false];
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
};
|
|
891
953
|
Database.prototype.getGroupBy = function (column) {
|
|
892
954
|
return __awaiter(this, void 0, void 0, function () {
|
|
893
955
|
var sql, results, data, sqlGroups, groups, resultData;
|
|
@@ -1398,7 +1460,9 @@ var Database = /** @class */ (function (_super) {
|
|
|
1398
1460
|
if (useDefault === void 0) { useDefault = false; }
|
|
1399
1461
|
if (useDefault)
|
|
1400
1462
|
return [operator, '='];
|
|
1401
|
-
if (operator
|
|
1463
|
+
if (operator == null)
|
|
1464
|
+
throw new Error('bad arguments');
|
|
1465
|
+
if (operator.toUpperCase() === this.$utils().constants('LIKE'))
|
|
1402
1466
|
operator = operator.toUpperCase();
|
|
1403
1467
|
return [value, operator];
|
|
1404
1468
|
};
|
|
@@ -20,10 +20,11 @@ var LoggerMethod = function (self, prop) {
|
|
|
20
20
|
'hasMany',
|
|
21
21
|
'belongsToMany',
|
|
22
22
|
];
|
|
23
|
-
var
|
|
23
|
+
var _use = prop.substring(0, 3) !== 'use';
|
|
24
24
|
var _private = prop.charAt(0) !== '_';
|
|
25
|
-
var
|
|
26
|
-
var
|
|
25
|
+
var _setter = prop.charAt(0) !== '$';
|
|
26
|
+
var _ignore = ignores.indexOf(prop) === -1;
|
|
27
|
+
var conditions = [_use, _private, _ignore, _setter].every(function (data) { return data === true; });
|
|
27
28
|
if (conditions)
|
|
28
29
|
(_a = self.$logger) === null || _a === void 0 ? void 0 : _a.set(prop);
|
|
29
30
|
return;
|
|
@@ -11,7 +11,9 @@ declare class Model extends AbstractModel {
|
|
|
11
11
|
useTimestamp(): this;
|
|
12
12
|
useTable(table: string): this;
|
|
13
13
|
disabledSoftDelete(): this;
|
|
14
|
-
registry(func:
|
|
14
|
+
registry(func: {
|
|
15
|
+
[x: string]: Function;
|
|
16
|
+
}): this;
|
|
15
17
|
withQuery(name: string, cb: Function): this;
|
|
16
18
|
with(...nameRelations: Array<any>): this;
|
|
17
19
|
withExists(...nameRelations: Array<string>): this;
|