tspace-mysql 1.1.2 → 1.1.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/dist/cli/index.js +23 -24
- package/dist/cli/migrate/make.js +18 -41
- package/dist/cli/models/make.js +18 -18
- package/dist/cli/models/model.js +27 -2
- package/dist/cli/tables/make.js +10 -10
- package/dist/cli/tables/table.js +22 -2
- package/dist/lib/config/env.d.ts +6 -0
- package/dist/lib/config/env.js +16 -10
- package/dist/lib/connection/index.d.ts +29 -8
- package/dist/lib/connection/index.js +111 -55
- package/dist/lib/constants/index.js +7 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/tspace/AbstractDB.js +3 -23
- package/dist/lib/tspace/AbstractDatabase.d.ts +9 -4
- package/dist/lib/tspace/AbstractDatabase.js +28 -31
- package/dist/lib/tspace/AbstractModel.d.ts +30 -16
- package/dist/lib/tspace/AbstractModel.js +3 -23
- package/dist/lib/tspace/Blueprint.d.ts +92 -21
- package/dist/lib/tspace/Blueprint.js +171 -140
- package/dist/lib/tspace/DB.d.ts +27 -4
- package/dist/lib/tspace/DB.js +66 -158
- package/dist/lib/tspace/Database.d.ts +100 -51
- package/dist/lib/tspace/Database.js +1335 -1911
- package/dist/lib/tspace/Interface.d.ts +8 -8
- package/dist/lib/tspace/Logger.js +19 -19
- package/dist/lib/tspace/Model.d.ts +168 -132
- package/dist/lib/tspace/Model.js +1467 -2081
- package/dist/lib/tspace/ProxyHandler.js +15 -26
- package/dist/lib/tspace/Schema.js +25 -117
- package/dist/lib/tspace/index.js +4 -4
- package/dist/lib/utils/index.d.ts +4 -3
- package/dist/lib/utils/index.js +87 -112
- package/package.json +1 -1
|
@@ -1,215 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
65
|
-
var t = {};
|
|
66
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
67
|
-
t[p] = s[p];
|
|
68
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
69
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
70
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
71
|
-
t[p[i]] = s[p[i]];
|
|
72
|
-
}
|
|
73
|
-
return t;
|
|
74
|
-
};
|
|
75
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
76
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
77
|
-
if (!m) return o;
|
|
78
|
-
var i = m.call(o), r, ar = [], e;
|
|
79
|
-
try {
|
|
80
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
81
|
-
}
|
|
82
|
-
catch (error) { e = { error: error }; }
|
|
83
|
-
finally {
|
|
84
|
-
try {
|
|
85
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
86
|
-
}
|
|
87
|
-
finally { if (e) throw e.error; }
|
|
88
|
-
}
|
|
89
|
-
return ar;
|
|
90
|
-
};
|
|
91
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
92
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
93
|
-
if (ar || !(i in from)) {
|
|
94
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
95
|
-
ar[i] = from[i];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
99
|
-
};
|
|
100
|
-
var __values = (this && this.__values) || function(o) {
|
|
101
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
102
|
-
if (m) return m.call(o);
|
|
103
|
-
if (o && typeof o.length === "number") return {
|
|
104
|
-
next: function () {
|
|
105
|
-
if (o && i >= o.length) o = void 0;
|
|
106
|
-
return { value: o && o[i++], done: !o };
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
110
|
-
};
|
|
111
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
112
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
113
4
|
};
|
|
114
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
115
6
|
exports.Database = void 0;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return _this;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const sql_formatter_1 = require("sql-formatter");
|
|
9
|
+
const AbstractDatabase_1 = __importDefault(require("./AbstractDatabase"));
|
|
10
|
+
const utils_1 = __importDefault(require("../utils"));
|
|
11
|
+
const constants_1 = __importDefault(require("../constants"));
|
|
12
|
+
const DB_1 = __importDefault(require("./DB"));
|
|
13
|
+
const connection_1 = require("../connection");
|
|
14
|
+
class Database extends AbstractDatabase_1.default {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this._initialConnection();
|
|
128
18
|
}
|
|
129
19
|
/**
|
|
130
20
|
*
|
|
131
21
|
* @param {string} column
|
|
132
22
|
* @return {this}
|
|
133
23
|
*/
|
|
134
|
-
|
|
24
|
+
pluck(column) {
|
|
135
25
|
this.$db.set('PLUCK', column);
|
|
136
26
|
return this;
|
|
137
|
-
}
|
|
27
|
+
}
|
|
138
28
|
/**
|
|
139
29
|
*
|
|
140
30
|
* @param {...string} columns
|
|
141
31
|
* @return {this} this
|
|
142
32
|
*/
|
|
143
|
-
|
|
144
|
-
var columns = [];
|
|
145
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
146
|
-
columns[_i] = arguments[_i];
|
|
147
|
-
}
|
|
33
|
+
except(...columns) {
|
|
148
34
|
this.$db.set('EXCEPT', columns.length ? columns : ['id']);
|
|
149
35
|
return this;
|
|
150
|
-
}
|
|
36
|
+
}
|
|
151
37
|
/**
|
|
152
38
|
*
|
|
153
39
|
* @param {...string} columns show only colums selected
|
|
154
40
|
* @return {this} this
|
|
155
41
|
*/
|
|
156
|
-
|
|
157
|
-
var columns = [];
|
|
158
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
159
|
-
columns[_i] = arguments[_i];
|
|
160
|
-
}
|
|
42
|
+
only(...columns) {
|
|
161
43
|
this.$db.set('ONLY', columns);
|
|
162
44
|
return this;
|
|
163
|
-
}
|
|
45
|
+
}
|
|
164
46
|
/**
|
|
165
47
|
*
|
|
166
48
|
* @param {string=} column [column=id]
|
|
167
49
|
* @return {this} this
|
|
168
50
|
*/
|
|
169
|
-
|
|
170
|
-
if (column === void 0) { column = 'id'; }
|
|
51
|
+
distinct(column = 'id') {
|
|
171
52
|
this.$db.set('SELECT', [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
53
|
+
`${this.$constants('SELECT')}`,
|
|
54
|
+
`${this.$constants('DISTINCT')}`,
|
|
55
|
+
`${column}`
|
|
175
56
|
].join(' '));
|
|
176
57
|
return this;
|
|
177
|
-
}
|
|
58
|
+
}
|
|
178
59
|
/**
|
|
179
60
|
*
|
|
180
|
-
* @param {string
|
|
61
|
+
* @param {Array<string>} ...columns
|
|
181
62
|
* @return {this} this
|
|
182
63
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
var select = '*';
|
|
189
|
-
if (columns === null || columns === void 0 ? void 0 : columns.length)
|
|
190
|
-
select = columns.join(',');
|
|
191
|
-
this.$db.set('SELECT', "".concat(this.$constants('SELECT'), " ").concat(select));
|
|
64
|
+
select(...columns) {
|
|
65
|
+
let select = '*';
|
|
66
|
+
if (columns?.length)
|
|
67
|
+
select = columns.join(', ');
|
|
68
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} ${select}`);
|
|
192
69
|
return this;
|
|
193
|
-
}
|
|
70
|
+
}
|
|
194
71
|
/**
|
|
195
72
|
*
|
|
196
73
|
* @param {number} chunk
|
|
197
74
|
* @return {this} this
|
|
198
75
|
*/
|
|
199
|
-
|
|
76
|
+
chunk(chunk) {
|
|
200
77
|
this.$db.set('CHUNK', chunk);
|
|
201
78
|
return this;
|
|
202
|
-
}
|
|
79
|
+
}
|
|
203
80
|
/**
|
|
204
81
|
*
|
|
205
82
|
* @param {string | number | undefined | null | Boolean} condition when condition true will be callback
|
|
206
83
|
* @return {this} this
|
|
207
84
|
*/
|
|
208
|
-
|
|
85
|
+
when(condition, callback) {
|
|
209
86
|
if (condition)
|
|
210
87
|
callback(this);
|
|
211
88
|
return this;
|
|
212
|
-
}
|
|
89
|
+
}
|
|
213
90
|
/**
|
|
214
91
|
* if has 2 arguments default operator '='
|
|
215
92
|
* @param {string} column
|
|
@@ -217,27 +94,24 @@ var Database = /** @class */ (function (_super) {
|
|
|
217
94
|
* @param {any?} value
|
|
218
95
|
* @return {this}
|
|
219
96
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
97
|
+
where(column, operator, value) {
|
|
98
|
+
[value, operator] = this._valueAndOperator(value, operator, arguments.length === 2);
|
|
223
99
|
value = this.$utils.escape(value);
|
|
224
100
|
value = this._valueTrueFalse(value);
|
|
225
|
-
if (operator.toUpperCase() === this.$constants('LIKE'))
|
|
226
|
-
value = "%".concat(value, "%");
|
|
227
101
|
if (!this._queryWhereIsExists()) {
|
|
228
102
|
this.$db.set('WHERE', [
|
|
229
|
-
|
|
230
|
-
|
|
103
|
+
`${this.$constants('WHERE')}`,
|
|
104
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
231
105
|
].join(' '));
|
|
232
106
|
return this;
|
|
233
107
|
}
|
|
234
108
|
this.$db.set('WHERE', [
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
109
|
+
`${this.$db.get('WHERE')}`,
|
|
110
|
+
`${this.$constants('AND')}`,
|
|
111
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
238
112
|
].join(' '));
|
|
239
113
|
return this;
|
|
240
|
-
}
|
|
114
|
+
}
|
|
241
115
|
/**
|
|
242
116
|
* if has 2 arguments default operator '='
|
|
243
117
|
* @param {string} column
|
|
@@ -245,332 +119,391 @@ var Database = /** @class */ (function (_super) {
|
|
|
245
119
|
* @param {any?} value
|
|
246
120
|
* @return {this}
|
|
247
121
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
122
|
+
orWhere(column, operator, value) {
|
|
123
|
+
[value, operator] = this._valueAndOperator(value, operator, arguments.length === 2);
|
|
251
124
|
value = this.$utils.escape(value);
|
|
252
|
-
if (
|
|
253
|
-
value = "%".concat(value, "%");
|
|
254
|
-
if (this._queryWhereIsExists()) {
|
|
125
|
+
if (!this._queryWhereIsExists()) {
|
|
255
126
|
this.$db.set('WHERE', [
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
"".concat(column, " ").concat(operator, " '").concat(value, "'")
|
|
127
|
+
`${this.$constants('WHERE')}`,
|
|
128
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
259
129
|
].join(' '));
|
|
260
130
|
return this;
|
|
261
131
|
}
|
|
262
132
|
this.$db.set('WHERE', [
|
|
263
|
-
|
|
264
|
-
|
|
133
|
+
`${this.$db.get('WHERE')}`,
|
|
134
|
+
`${this.$constants('OR')}`,
|
|
135
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
265
136
|
].join(' '));
|
|
266
137
|
return this;
|
|
267
|
-
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param {string} sql where column with raw sql
|
|
142
|
+
* @return {this} this
|
|
143
|
+
*/
|
|
144
|
+
whereRaw(sql) {
|
|
145
|
+
if (!this._queryWhereIsExists()) {
|
|
146
|
+
this.$db.set('WHERE', [
|
|
147
|
+
`${this.$constants('WHERE')}`,
|
|
148
|
+
`${sql}`
|
|
149
|
+
].join(' '));
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
this.$db.set('WHERE', [
|
|
153
|
+
`${this.$db.get('WHERE')}`,
|
|
154
|
+
`${this.$constants('AND')}`,
|
|
155
|
+
`${sql}`
|
|
156
|
+
].join(' '));
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
268
159
|
/**
|
|
269
160
|
*
|
|
270
161
|
* @param {string} query where column with raw sql
|
|
271
162
|
* @return {this} this
|
|
272
163
|
*/
|
|
273
|
-
|
|
164
|
+
orWhereRaw(sql) {
|
|
165
|
+
if (!this._queryWhereIsExists()) {
|
|
166
|
+
this.$db.set('WHERE', [
|
|
167
|
+
`${this.$constants('WHERE')}`,
|
|
168
|
+
`${sql}`
|
|
169
|
+
].join(' '));
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
this.$db.set('WHERE', [
|
|
173
|
+
`${this.$db.get('WHERE')}`,
|
|
174
|
+
`${this.$constants('OR')}`,
|
|
175
|
+
`${sql}`
|
|
176
|
+
].join(' '));
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
* @param {string} tableAndLocalKey
|
|
182
|
+
* @param {string?} tableAndForeignKey
|
|
183
|
+
* @return {this}
|
|
184
|
+
*/
|
|
185
|
+
whereReference(tableAndLocalKey, tableAndForeignKey) {
|
|
186
|
+
if (!this._queryWhereIsExists()) {
|
|
187
|
+
this.$db.set('WHERE', [
|
|
188
|
+
`${this.$constants('WHERE')}`,
|
|
189
|
+
`${tableAndLocalKey} = ${tableAndForeignKey}`
|
|
190
|
+
].join(' '));
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
this.$db.set('WHERE', [
|
|
194
|
+
`${this.$db.get('WHERE')}`,
|
|
195
|
+
`${this.$constants('AND')}`,
|
|
196
|
+
`${tableAndLocalKey} = ${tableAndForeignKey}`
|
|
197
|
+
].join(' '));
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
*
|
|
202
|
+
* where exists
|
|
203
|
+
* @param {string} sql
|
|
204
|
+
* @return {this}
|
|
205
|
+
*/
|
|
206
|
+
whereExists(sql) {
|
|
274
207
|
if (!this._queryWhereIsExists()) {
|
|
275
208
|
this.$db.set('WHERE', [
|
|
276
|
-
|
|
277
|
-
|
|
209
|
+
`${this.$constants('WHERE')}`,
|
|
210
|
+
`${this.$constants('EXISTS')}`,
|
|
211
|
+
`(${sql})`
|
|
278
212
|
].join(' '));
|
|
279
213
|
return this;
|
|
280
214
|
}
|
|
281
215
|
this.$db.set('WHERE', [
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
216
|
+
`${this.$db.get('WHERE')}`,
|
|
217
|
+
`${this.$constants('AND')}`,
|
|
218
|
+
`${this.$constants('EXISTS')}`,
|
|
219
|
+
`(${sql})`
|
|
285
220
|
].join(' '));
|
|
286
221
|
return this;
|
|
287
|
-
}
|
|
222
|
+
}
|
|
288
223
|
/**
|
|
289
224
|
*
|
|
290
225
|
* @param {number} id
|
|
291
226
|
* @param {string?} column custom it *if column is not id
|
|
292
227
|
* @return {this} this
|
|
293
228
|
*/
|
|
294
|
-
|
|
295
|
-
if (column === void 0) { column = 'id'; }
|
|
229
|
+
whereId(id, column = 'id') {
|
|
296
230
|
if (!this._queryWhereIsExists()) {
|
|
297
231
|
this.$db.set('WHERE', [
|
|
298
|
-
|
|
299
|
-
|
|
232
|
+
`${this.$constants('WHERE')}`,
|
|
233
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${id}'`
|
|
300
234
|
].join(' '));
|
|
301
235
|
return this;
|
|
302
236
|
}
|
|
303
237
|
this.$db.set('WHERE', [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
238
|
+
`${this.$db.get('WHERE')}`,
|
|
239
|
+
`${this.$constants('AND')}`,
|
|
240
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${id}'`
|
|
307
241
|
].join(' '));
|
|
308
242
|
return this;
|
|
309
|
-
}
|
|
243
|
+
}
|
|
310
244
|
/**
|
|
311
245
|
*
|
|
312
246
|
* @param {string} email where using email
|
|
313
247
|
* @return {this}
|
|
314
248
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
249
|
+
whereEmail(email) {
|
|
250
|
+
const column = 'email';
|
|
317
251
|
email = this.$utils.escape(email);
|
|
318
252
|
if (!this._queryWhereIsExists()) {
|
|
319
253
|
this.$db.set('WHERE', [
|
|
320
|
-
|
|
321
|
-
|
|
254
|
+
`${this.$constants('WHERE')}`,
|
|
255
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${email}'`
|
|
322
256
|
].join(' '));
|
|
323
257
|
return this;
|
|
324
258
|
}
|
|
325
259
|
this.$db.set('WHERE', [
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
260
|
+
`${this.$db.get('WHERE')}`,
|
|
261
|
+
`${this.$constants('AND')}`,
|
|
262
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${email}'`
|
|
329
263
|
].join(' '));
|
|
330
264
|
return this;
|
|
331
|
-
}
|
|
265
|
+
}
|
|
332
266
|
/**
|
|
333
267
|
*
|
|
334
268
|
* @param {number} id
|
|
335
269
|
* @param {string?} column custom it *if column is not user_id
|
|
336
270
|
* @return {this}
|
|
337
271
|
*/
|
|
338
|
-
|
|
339
|
-
if (column === void 0) { column = 'user_id'; }
|
|
272
|
+
whereUser(id, column = 'user_id') {
|
|
340
273
|
id = this.$utils.escape(id);
|
|
341
274
|
if (!this._queryWhereIsExists()) {
|
|
342
275
|
this.$db.set('WHERE', [
|
|
343
|
-
|
|
344
|
-
|
|
276
|
+
`${this.$constants('WHERE')}`,
|
|
277
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${id}'`
|
|
345
278
|
].join(' '));
|
|
346
279
|
return this;
|
|
347
280
|
}
|
|
348
281
|
this.$db.set('WHERE', [
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
282
|
+
`${this.$db.get('WHERE')}`,
|
|
283
|
+
`${this.$constants('AND')}`,
|
|
284
|
+
`${this._bindTableAndColumnInQueryWhere(column)} = '${id}'`
|
|
352
285
|
].join(' '));
|
|
353
286
|
return this;
|
|
354
|
-
}
|
|
287
|
+
}
|
|
355
288
|
/**
|
|
356
289
|
* using array value where in value in array
|
|
357
290
|
* @param {string} column
|
|
358
291
|
* @param {array} array
|
|
359
292
|
* @return {this}
|
|
360
293
|
*/
|
|
361
|
-
|
|
294
|
+
whereIn(column, array) {
|
|
362
295
|
if (!Array.isArray(array))
|
|
363
|
-
throw new Error(
|
|
296
|
+
throw new Error(`[${array}] is't array`);
|
|
364
297
|
if (!array.length)
|
|
365
298
|
array = ['0'];
|
|
366
|
-
|
|
299
|
+
const values = `${array.map((value) => `\'${value}\'`).join(',')}`;
|
|
367
300
|
if (!this._queryWhereIsExists()) {
|
|
368
301
|
this.$db.set('WHERE', [
|
|
369
|
-
|
|
370
|
-
|
|
302
|
+
`${this.$constants('WHERE')}`,
|
|
303
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${values})`
|
|
371
304
|
].join(' '));
|
|
372
305
|
return this;
|
|
373
306
|
}
|
|
374
307
|
this.$db.set('WHERE', [
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
308
|
+
`${this.$db.get('WHERE')}`,
|
|
309
|
+
`${this.$constants('AND')}`,
|
|
310
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${values})`
|
|
378
311
|
].join(' '));
|
|
379
312
|
return this;
|
|
380
|
-
}
|
|
313
|
+
}
|
|
381
314
|
/**
|
|
382
315
|
* or where in data using array values
|
|
383
316
|
* @param {string} column
|
|
384
317
|
* @param {array} array
|
|
385
318
|
* @return {this}
|
|
386
319
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
320
|
+
orWhereIn(column, array) {
|
|
321
|
+
const sql = this.$db.get('WHERE');
|
|
389
322
|
if (!Array.isArray(array))
|
|
390
|
-
throw new Error(
|
|
323
|
+
throw new Error(`[${array}] is't array`);
|
|
391
324
|
if (!array.length)
|
|
392
325
|
array = ['0'];
|
|
393
|
-
|
|
326
|
+
const values = `${array.map((value) => `\'${value}\'`).join(',')}`;
|
|
394
327
|
if (!sql.includes(this.$constants('WHERE'))) {
|
|
395
328
|
this.$db.set('WHERE', [
|
|
396
|
-
|
|
397
|
-
|
|
329
|
+
`${this.$constants('WHERE')}`,
|
|
330
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${values})`
|
|
398
331
|
].join(' '));
|
|
399
332
|
return this;
|
|
400
333
|
}
|
|
401
334
|
this.$db.set('WHERE', [
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
335
|
+
`${this.$db.get('WHERE')}`,
|
|
336
|
+
`${this.$constants('OR')}`,
|
|
337
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${values})`
|
|
405
338
|
].join(' '));
|
|
406
339
|
return this;
|
|
407
|
-
}
|
|
340
|
+
}
|
|
408
341
|
/**
|
|
409
342
|
* where not in data using array values
|
|
410
343
|
* @param {string} column
|
|
411
344
|
* @param {array} array
|
|
412
345
|
* @return {this}
|
|
413
346
|
*/
|
|
414
|
-
|
|
415
|
-
|
|
347
|
+
whereNotIn(column, array) {
|
|
348
|
+
const sql = this.$db.get('WHERE');
|
|
416
349
|
if (!Array.isArray(array))
|
|
417
|
-
throw new Error(
|
|
350
|
+
throw new Error(`[${array}] is't array`);
|
|
418
351
|
if (!array.length)
|
|
419
352
|
array = ['0'];
|
|
420
|
-
|
|
353
|
+
const values = `${array.map((value) => `\'${value}\'`).join(',')}`;
|
|
421
354
|
if (!sql.includes(this.$constants('WHERE'))) {
|
|
422
355
|
this.$db.set('WHERE', [
|
|
423
|
-
|
|
424
|
-
|
|
356
|
+
`${this.$constants('WHERE')}`,
|
|
357
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_IN')} (${values})`
|
|
425
358
|
].join(' '));
|
|
426
359
|
return this;
|
|
427
360
|
}
|
|
428
361
|
this.$db.set('WHERE', [
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
362
|
+
`${this.$db.get('WHERE')}`,
|
|
363
|
+
`${this.$constants('AND')}`,
|
|
364
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_IN')} (${values})`
|
|
432
365
|
].join(' '));
|
|
433
366
|
return this;
|
|
434
|
-
}
|
|
367
|
+
}
|
|
435
368
|
/**
|
|
436
369
|
* where sub query using sub query sql
|
|
437
370
|
* @param {string} column
|
|
438
371
|
* @param {string} subQuery
|
|
439
372
|
* @return {this}
|
|
440
373
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
374
|
+
whereSubQuery(column, subQuery) {
|
|
375
|
+
const whereSubQuery = this.$db.get('WHERE');
|
|
443
376
|
subQuery = this.$utils.escapeSubQuery(subQuery);
|
|
444
377
|
if (!whereSubQuery.includes(this.$constants('WHERE'))) {
|
|
445
378
|
this.$db.set('WHERE', [
|
|
446
|
-
|
|
447
|
-
|
|
379
|
+
`${this.$constants('WHERE')}`,
|
|
380
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${subQuery})`
|
|
448
381
|
].join(' '));
|
|
449
382
|
return this;
|
|
450
383
|
}
|
|
451
384
|
this.$db.set('WHERE', [
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
385
|
+
`${this.$db.get('WHERE')}`,
|
|
386
|
+
`${this.$constants('AND')}`,
|
|
387
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${subQuery})`
|
|
455
388
|
].join(' '));
|
|
456
389
|
return this;
|
|
457
|
-
}
|
|
390
|
+
}
|
|
458
391
|
/**
|
|
459
392
|
* where not sub query using sub query sql
|
|
460
393
|
* @param {string} column
|
|
461
394
|
* @param {string} subQuery
|
|
462
395
|
* @return {this}
|
|
463
396
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
397
|
+
whereNotSubQuery(column, subQuery) {
|
|
398
|
+
const whereSubQuery = this.$db.get('WHERE');
|
|
466
399
|
subQuery = this.$utils.escapeSubQuery(subQuery);
|
|
467
400
|
if (!whereSubQuery.includes(this.$constants('WHERE'))) {
|
|
468
401
|
this.$db.set('WHERE', [
|
|
469
|
-
|
|
470
|
-
|
|
402
|
+
`${this.$constants('WHERE')}`,
|
|
403
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${subQuery})`
|
|
471
404
|
].join(' '));
|
|
472
405
|
return this;
|
|
473
406
|
}
|
|
474
407
|
this.$db.set('WHERE', [
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
408
|
+
`${this.$db.get('WHERE')}`,
|
|
409
|
+
`${this.$constants('AND')}`,
|
|
410
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_IN')} (${subQuery})`
|
|
478
411
|
].join(' '));
|
|
479
412
|
return this;
|
|
480
|
-
}
|
|
413
|
+
}
|
|
481
414
|
/**
|
|
482
415
|
* or where not sub query using query sql
|
|
483
416
|
* @param {string} column
|
|
484
417
|
* @param {string} subQuery
|
|
485
418
|
* @return {this}
|
|
486
419
|
*/
|
|
487
|
-
|
|
488
|
-
|
|
420
|
+
orWhereSubQuery(column, subQuery) {
|
|
421
|
+
const whereSubQuery = this.$db.get('WHERE');
|
|
489
422
|
subQuery = this.$utils.escapeSubQuery(subQuery);
|
|
490
423
|
if (!whereSubQuery.includes(this.$constants('WHERE'))) {
|
|
491
424
|
this.$db.set('WHERE', [
|
|
492
|
-
|
|
493
|
-
|
|
425
|
+
`${this.$constants('WHERE')}`,
|
|
426
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${subQuery})`
|
|
494
427
|
].join(' '));
|
|
495
428
|
return this;
|
|
496
429
|
}
|
|
497
430
|
this.$db.set('WHERE', [
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
431
|
+
`${this.$db.get('WHERE')}`,
|
|
432
|
+
`${this.$constants('OR')}`,
|
|
433
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IN')} (${subQuery})`
|
|
501
434
|
].join(' '));
|
|
502
435
|
return this;
|
|
503
|
-
}
|
|
436
|
+
}
|
|
504
437
|
/**
|
|
505
438
|
* where between using [value1, value2]
|
|
506
439
|
* @param {string} column
|
|
507
440
|
* @param {array} array
|
|
508
441
|
* @return {this}
|
|
509
442
|
*/
|
|
510
|
-
|
|
443
|
+
whereBetween(column, array) {
|
|
511
444
|
if (!Array.isArray(array))
|
|
512
445
|
throw new Error("Value is't array");
|
|
513
446
|
if (!array.length)
|
|
514
447
|
array = ['0', '0'];
|
|
515
|
-
|
|
448
|
+
let [value1, value2] = array;
|
|
516
449
|
value1 = this.$utils.escape(value1);
|
|
517
450
|
value2 = this.$utils.escape(value2);
|
|
518
451
|
if (!this._queryWhereIsExists()) {
|
|
519
452
|
this.$db.set('WHERE', [
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
453
|
+
`${this.$constants('WHERE')}`,
|
|
454
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
|
|
455
|
+
`'${value1}' ${this.$constants('AND')} '${value2}'`
|
|
523
456
|
].join(' '));
|
|
524
457
|
return this;
|
|
525
458
|
}
|
|
526
459
|
this.$db.set('WHERE', [
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
460
|
+
`${this.$db.get('WHERE')}`,
|
|
461
|
+
`${this.$constants('AND')}`,
|
|
462
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
|
|
463
|
+
`'${value1}' ${this.$constants('AND')} '${value2}'`
|
|
531
464
|
].join(' '));
|
|
532
465
|
return this;
|
|
533
|
-
}
|
|
466
|
+
}
|
|
534
467
|
/**
|
|
535
468
|
* where null using NULL
|
|
536
469
|
* @param {string} column
|
|
537
470
|
* @return {this}
|
|
538
471
|
*/
|
|
539
|
-
|
|
472
|
+
whereNull(column) {
|
|
540
473
|
if (!this._queryWhereIsExists()) {
|
|
541
474
|
this.$db.set('WHERE', [
|
|
542
|
-
|
|
543
|
-
|
|
475
|
+
`${this.$constants('WHERE')}`,
|
|
476
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IS_NULL')}`
|
|
544
477
|
].join(' '));
|
|
545
478
|
return this;
|
|
546
479
|
}
|
|
547
480
|
this.$db.set('WHERE', [
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
481
|
+
`${this.$db.get('WHERE')}`,
|
|
482
|
+
`${this.$constants('AND')}`,
|
|
483
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IS_NULL')}`
|
|
551
484
|
].join(' '));
|
|
552
485
|
return this;
|
|
553
|
-
}
|
|
486
|
+
}
|
|
554
487
|
/**
|
|
555
488
|
* where not null using NULL
|
|
556
489
|
* @param {string} column
|
|
557
490
|
* @return {this}
|
|
558
491
|
*/
|
|
559
|
-
|
|
492
|
+
whereNotNull(column) {
|
|
560
493
|
if (!this._queryWhereIsExists()) {
|
|
561
494
|
this.$db.set('WHERE', [
|
|
562
|
-
|
|
563
|
-
|
|
495
|
+
`${this.$constants('WHERE')}`,
|
|
496
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IS_NOT_NULL')}`
|
|
564
497
|
].join(' '));
|
|
565
498
|
return this;
|
|
566
499
|
}
|
|
567
500
|
this.$db.set('WHERE', [
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
501
|
+
`${this.$db.get('WHERE')}`,
|
|
502
|
+
`${this.$constants('AND')}`,
|
|
503
|
+
`${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('IS_NOT_NULL')}`
|
|
571
504
|
].join(' '));
|
|
572
505
|
return this;
|
|
573
|
-
}
|
|
506
|
+
}
|
|
574
507
|
/**
|
|
575
508
|
* where sensitive (uppercase, lowercase)
|
|
576
509
|
* @param {string} column
|
|
@@ -578,525 +511,461 @@ var Database = /** @class */ (function (_super) {
|
|
|
578
511
|
* @param {any?} value
|
|
579
512
|
* @return {this}
|
|
580
513
|
*/
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
514
|
+
whereSensitive(column, operator, value) {
|
|
515
|
+
[value, operator] = this._valueAndOperator(value, operator, arguments.length === 2);
|
|
584
516
|
value = this.$utils.escape(value);
|
|
585
517
|
value = this._valueTrueFalse(value);
|
|
586
518
|
if (!this._queryWhereIsExists()) {
|
|
587
519
|
this.$db.set('WHERE', [
|
|
588
|
-
|
|
589
|
-
|
|
520
|
+
`${this.$constants('WHERE')}`,
|
|
521
|
+
`BINARY ${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
590
522
|
].join(' '));
|
|
591
523
|
return this;
|
|
592
524
|
}
|
|
593
525
|
this.$db.set('WHERE', [
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
526
|
+
`${this.$db.get('WHERE')}`,
|
|
527
|
+
`${this.$constants('AND')}`,
|
|
528
|
+
`BINARY ${this._bindTableAndColumnInQueryWhere(column)} ${operator} '${value}'`
|
|
597
529
|
].join(' '));
|
|
598
530
|
return this;
|
|
599
|
-
}
|
|
531
|
+
}
|
|
600
532
|
/**
|
|
601
|
-
* where
|
|
602
|
-
* @param {
|
|
603
|
-
* @param {string?} operator = < > != !< !>
|
|
604
|
-
* @param {any?} value
|
|
533
|
+
* where group query
|
|
534
|
+
* @param {function} callback callback query
|
|
605
535
|
* @return {this}
|
|
606
536
|
*/
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
if (operator === this.$constants('LIKE'))
|
|
613
|
-
value = "%".concat(value, "%");
|
|
614
|
-
if (!this._queryWhereIsExists()) {
|
|
615
|
-
this.$db.set('WHERE', [
|
|
616
|
-
"".concat(this.$constants('WHERE')),
|
|
617
|
-
"(".concat(column, " ").concat(operator, " '").concat(value, "'")
|
|
618
|
-
].join(' '));
|
|
619
|
-
return this;
|
|
537
|
+
whereQuery(callback) {
|
|
538
|
+
const db = new DB_1.default();
|
|
539
|
+
const repository = callback(db);
|
|
540
|
+
if (!(repository instanceof DB_1.default)) {
|
|
541
|
+
throw new Error(`unknown callback query: '[${repository}]'`);
|
|
620
542
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
"(".concat(column, " ").concat(operator, " '").concat(value, "'")
|
|
625
|
-
].join(' '));
|
|
626
|
-
return this;
|
|
627
|
-
};
|
|
628
|
-
/**
|
|
629
|
-
* or where grouping of start statements
|
|
630
|
-
* @param {string} column
|
|
631
|
-
* @param {string?} operator = < > != !< !>
|
|
632
|
-
* @param {any?} value
|
|
633
|
-
* @return {this}
|
|
634
|
-
*/
|
|
635
|
-
Database.prototype.orWhereGroupStart = function (column, operator, value) {
|
|
636
|
-
var _a;
|
|
637
|
-
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
638
|
-
value = this.$utils.escape(value);
|
|
639
|
-
value = this._valueTrueFalse(value);
|
|
640
|
-
if (operator === this.$constants('LIKE'))
|
|
641
|
-
value = "%".concat(value, "%");
|
|
642
|
-
if (!this._queryWhereIsExists()) {
|
|
643
|
-
this.$db.set('WHERE', [
|
|
644
|
-
"".concat(this.$constants('WHERE')),
|
|
645
|
-
"(".concat(column, " ").concat(operator, " '").concat(value, "'")
|
|
646
|
-
].join(' '));
|
|
647
|
-
return this;
|
|
543
|
+
const where = repository?.$db.get('WHERE') || '';
|
|
544
|
+
if (where === '') {
|
|
545
|
+
throw new Error(`unknown callback query with where condition`);
|
|
648
546
|
}
|
|
649
|
-
this
|
|
650
|
-
|
|
651
|
-
"".concat(this.$constants('AND')),
|
|
652
|
-
"(".concat(column, " ").concat(operator, " '").concat(value, "'")
|
|
653
|
-
].join(' '));
|
|
654
|
-
return this;
|
|
655
|
-
};
|
|
656
|
-
/**
|
|
657
|
-
* where grouping of end statements
|
|
658
|
-
* @param {string} column
|
|
659
|
-
* @param {string?} operator = < > != !< !>
|
|
660
|
-
* @param {any?} value
|
|
661
|
-
* @return {this}
|
|
662
|
-
*/
|
|
663
|
-
Database.prototype.whereGroupEnd = function (column, operator, value) {
|
|
664
|
-
var _a;
|
|
665
|
-
_a = __read(this._valueAndOperator(value, operator, arguments.length === 2), 2), value = _a[0], operator = _a[1];
|
|
666
|
-
value = this.$utils.escape(value);
|
|
667
|
-
value = this._valueTrueFalse(value);
|
|
668
|
-
if (operator === this.$constants('LIKE'))
|
|
669
|
-
value = "%".concat(value, "%");
|
|
670
|
-
if (!this._queryWhereIsExists()) {
|
|
547
|
+
if (this._queryWhereIsExists()) {
|
|
548
|
+
const query = where.replace('WHERE', '');
|
|
671
549
|
this.$db.set('WHERE', [
|
|
672
|
-
|
|
673
|
-
|
|
550
|
+
`${this.$db.get('WHERE')}`,
|
|
551
|
+
`${this.$constants('AND')}`,
|
|
552
|
+
`(${query})`
|
|
674
553
|
].join(' '));
|
|
675
554
|
return this;
|
|
676
555
|
}
|
|
556
|
+
const query = where.replace('WHERE', '');
|
|
677
557
|
this.$db.set('WHERE', [
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
"".concat(column, " ").concat(operator, " '").concat(value, "')")
|
|
558
|
+
`${this.$constants('WHERE')}`,
|
|
559
|
+
`(${query})`
|
|
681
560
|
].join(' '));
|
|
682
561
|
return this;
|
|
683
|
-
}
|
|
562
|
+
}
|
|
684
563
|
/**
|
|
685
|
-
*
|
|
686
|
-
* @param {
|
|
687
|
-
* @param {string
|
|
688
|
-
* @param {any?} value
|
|
564
|
+
* select by cases
|
|
565
|
+
* @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}]
|
|
566
|
+
* @param {string} as
|
|
689
567
|
* @return {this}
|
|
690
568
|
*/
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
569
|
+
case(cases, as) {
|
|
570
|
+
let query = ['CASE'];
|
|
571
|
+
for (let i = 0; i < cases.length; i++) {
|
|
572
|
+
const c = cases[i];
|
|
573
|
+
if (cases.length - 1 === i) {
|
|
574
|
+
if (c.then == null)
|
|
575
|
+
throw new Error(`can't find then condition`);
|
|
576
|
+
query = [
|
|
577
|
+
...query,
|
|
578
|
+
`${this.$constants('ELSE')} '${c.then}'`,
|
|
579
|
+
`${this.$constants('END')}`
|
|
580
|
+
];
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
if (c.when == null)
|
|
584
|
+
throw new Error(`can't find when condition`);
|
|
585
|
+
if (c.then == null)
|
|
586
|
+
throw new Error(`can't find then condition`);
|
|
587
|
+
query = [
|
|
588
|
+
...query,
|
|
589
|
+
`${this.$constants('WHEN')} ${c.when} ${this.$constants('THEN')} '${c.then}'`
|
|
590
|
+
];
|
|
704
591
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
"".concat(column, " ").concat(operator, " '").concat(value, "')")
|
|
709
|
-
].join(' '));
|
|
592
|
+
if (query.length <= 1)
|
|
593
|
+
return this;
|
|
594
|
+
this.$db.set('SELECT', `${this.$db.get('SELECT')}, ${query.join(' ')} ${this.$constants('AS')} ${as}`);
|
|
710
595
|
return this;
|
|
711
|
-
}
|
|
596
|
+
}
|
|
712
597
|
/**
|
|
713
598
|
*
|
|
714
599
|
* @param {string} condition
|
|
715
600
|
* @return {this}
|
|
716
601
|
*/
|
|
717
|
-
|
|
602
|
+
having(condition) {
|
|
718
603
|
this.$db.set('HAVING', condition);
|
|
719
604
|
return this;
|
|
720
|
-
}
|
|
605
|
+
}
|
|
721
606
|
/**
|
|
722
607
|
*
|
|
723
608
|
* @param {string} pk talbe.pk
|
|
724
609
|
* @param {string} fk talbe.fk
|
|
725
610
|
* @return {this}
|
|
726
611
|
*/
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
612
|
+
join(pk, fk) {
|
|
613
|
+
const table = fk.split('.')?.shift();
|
|
730
614
|
if (this.$db.get('JOIN')) {
|
|
731
615
|
this.$db.set('JOIN', [
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
616
|
+
`${this.$db.get('JOIN')}`,
|
|
617
|
+
`${this.$constants('INNER_JOIN')}`,
|
|
618
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
735
619
|
].join(' '));
|
|
736
620
|
return this;
|
|
737
621
|
}
|
|
738
622
|
this.$db.set('JOIN', [
|
|
739
|
-
|
|
740
|
-
|
|
623
|
+
`${this.$constants('INNER_JOIN')}`,
|
|
624
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
741
625
|
].join(' '));
|
|
742
626
|
return this;
|
|
743
|
-
}
|
|
627
|
+
}
|
|
744
628
|
/**
|
|
745
629
|
*
|
|
746
630
|
* @param {string} pk talbe.pk
|
|
747
631
|
* @param {string} fk talbe.fk
|
|
748
632
|
* @return {this}
|
|
749
633
|
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
634
|
+
rightJoin(pk, fk) {
|
|
635
|
+
const table = fk.split('.')?.shift();
|
|
753
636
|
if (this.$db.get('JOIN')) {
|
|
754
637
|
this.$db.set('JOIN', [
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
638
|
+
`${this.$db.get('JOIN')}`,
|
|
639
|
+
`${this.$constants('RIGHT_JOIN')}`,
|
|
640
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
758
641
|
].join(' '));
|
|
759
642
|
return this;
|
|
760
643
|
}
|
|
761
644
|
this.$db.set('JOIN', [
|
|
762
|
-
|
|
763
|
-
|
|
645
|
+
`${this.$constants('RIGHT_JOIN')}`,
|
|
646
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
764
647
|
].join(''));
|
|
765
648
|
return this;
|
|
766
|
-
}
|
|
649
|
+
}
|
|
767
650
|
/**
|
|
768
651
|
*
|
|
769
652
|
* @param {string} pk talbe.pk
|
|
770
653
|
* @param {string} fk talbe.fk
|
|
771
654
|
* @return {this}
|
|
772
655
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
656
|
+
leftJoin(pk, fk) {
|
|
657
|
+
const table = fk.split('.')?.shift();
|
|
776
658
|
if (this.$db.get('JOIN')) {
|
|
777
659
|
this.$db.set('JOIN', [
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
660
|
+
`${this.$db.get('JOIN')}`,
|
|
661
|
+
`${this.$constants('LEFT_JOIN')}`,
|
|
662
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
781
663
|
].join(' '));
|
|
782
664
|
return this;
|
|
783
665
|
}
|
|
784
666
|
this.$db.set('JOIN', [
|
|
785
|
-
|
|
786
|
-
|
|
667
|
+
`${this.$constants('LEFT_JOIN')}`,
|
|
668
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
787
669
|
].join(' '));
|
|
788
670
|
return this;
|
|
789
|
-
}
|
|
671
|
+
}
|
|
790
672
|
/**
|
|
791
673
|
*
|
|
792
674
|
* @param {string} pk talbe.pk
|
|
793
675
|
* @param {string} fk talbe.fk
|
|
794
676
|
* @return {this}
|
|
795
677
|
*/
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
var table = (_a = fk.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
|
|
678
|
+
crossJoin(pk, fk) {
|
|
679
|
+
const table = fk.split('.')?.shift();
|
|
799
680
|
if (this.$db.get('JOIN')) {
|
|
800
681
|
this.$db.set('JOIN', [
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
682
|
+
`${this.$db.get('JOIN')}`,
|
|
683
|
+
`${this.$constants('CROSS_JOIN')}`,
|
|
684
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
804
685
|
].join(' '));
|
|
805
686
|
return this;
|
|
806
687
|
}
|
|
807
688
|
this.$db.set('JOIN', [
|
|
808
|
-
|
|
809
|
-
|
|
689
|
+
`${this.$constants('CROSS_JOIN')}`,
|
|
690
|
+
`${table} ${this.$constants('ON')} ${pk} = ${fk}`
|
|
810
691
|
].join(' '));
|
|
811
692
|
return this;
|
|
812
|
-
}
|
|
693
|
+
}
|
|
813
694
|
/**
|
|
814
695
|
*
|
|
815
696
|
* @param {string} column
|
|
816
|
-
* @param {string
|
|
697
|
+
* @param {string?} order [order=asc] asc, desc
|
|
817
698
|
* @return {this}
|
|
818
699
|
*/
|
|
819
|
-
|
|
820
|
-
if (order === void 0) { order = this.$constants('ASC'); }
|
|
700
|
+
orderBy(column, order = this.$constants('ASC')) {
|
|
821
701
|
this.$db.set('ORDER_BY', [
|
|
822
|
-
|
|
823
|
-
|
|
702
|
+
`${this.$constants('ORDER_BY')}`,
|
|
703
|
+
`${column} ${order.toUpperCase()}`
|
|
824
704
|
].join(' '));
|
|
825
705
|
return this;
|
|
826
|
-
}
|
|
706
|
+
}
|
|
827
707
|
/**
|
|
828
708
|
*
|
|
829
|
-
* @param {string
|
|
709
|
+
* @param {string?} column [column=id]
|
|
830
710
|
* @return {this}
|
|
831
711
|
*/
|
|
832
|
-
|
|
833
|
-
if (column === void 0) { column = 'id'; }
|
|
712
|
+
latest(column = 'id') {
|
|
834
713
|
if (this.$db.get('ORDER_BY')) {
|
|
835
714
|
this.$db.set('ORDER_BY', [
|
|
836
|
-
|
|
837
|
-
|
|
715
|
+
`${this.$db.get('ORDER_BY')}`,
|
|
716
|
+
`,${column} ${this.$constants('DESC')}`
|
|
838
717
|
].join(' '));
|
|
839
718
|
return this;
|
|
840
719
|
}
|
|
841
720
|
this.$db.set('ORDER_BY', [
|
|
842
|
-
|
|
843
|
-
|
|
721
|
+
`${this.$constants('ORDER_BY')}`,
|
|
722
|
+
`${column} ${this.$constants('DESC')}`
|
|
844
723
|
].join(' '));
|
|
845
724
|
return this;
|
|
846
|
-
}
|
|
725
|
+
}
|
|
847
726
|
/**
|
|
848
727
|
*
|
|
849
|
-
* @param {string
|
|
728
|
+
* @param {string?} column [column=id]
|
|
850
729
|
* @return {this}
|
|
851
730
|
*/
|
|
852
|
-
|
|
853
|
-
if (column === void 0) { column = 'id'; }
|
|
731
|
+
oldest(column = 'id') {
|
|
854
732
|
if (this.$db.get('ORDER_BY')) {
|
|
855
733
|
this.$db.set('ORDER_BY', [
|
|
856
|
-
|
|
857
|
-
|
|
734
|
+
`${this.$db.get('ORDER_BY')}`,
|
|
735
|
+
`,${column} ${this.$constants('ASC')}`
|
|
858
736
|
].join(' '));
|
|
859
737
|
return this;
|
|
860
738
|
}
|
|
861
739
|
this.$db.set('ORDER_BY', [
|
|
862
|
-
|
|
863
|
-
|
|
740
|
+
`${this.$constants('ORDER_BY')}`,
|
|
741
|
+
`${column} ${this.$constants('ASC')}`
|
|
864
742
|
].join(' '));
|
|
865
743
|
return this;
|
|
866
|
-
}
|
|
744
|
+
}
|
|
867
745
|
/**
|
|
868
746
|
*
|
|
869
|
-
* @param {string
|
|
747
|
+
* @param {string?} column [column=id]
|
|
870
748
|
* @return {this}
|
|
871
749
|
*/
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
this.$db.set('GROUP_BY', "".concat(this.$constants('GROUP_BY'), " ").concat(column));
|
|
750
|
+
groupBy(column = 'id') {
|
|
751
|
+
this.$db.set('GROUP_BY', `${this.$constants('GROUP_BY')} ${column}`);
|
|
875
752
|
return this;
|
|
876
|
-
}
|
|
753
|
+
}
|
|
877
754
|
/**
|
|
878
755
|
*
|
|
879
756
|
* @param {number=} number [number=1]
|
|
880
757
|
* @return {this}
|
|
881
758
|
*/
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
this.$db.set('LIMIT', "".concat(this.$constants('LIMIT'), " ").concat(number));
|
|
759
|
+
limit(number = 1) {
|
|
760
|
+
this.$db.set('LIMIT', `${this.$constants('LIMIT')} ${number}`);
|
|
885
761
|
return this;
|
|
886
|
-
}
|
|
762
|
+
}
|
|
887
763
|
/**
|
|
888
764
|
*
|
|
889
765
|
* @param {number=} number [number=1]
|
|
890
766
|
* @return {this}
|
|
891
767
|
*/
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
this.$db.set('OFFSET', "".concat(this.$constants('OFFSET'), " ").concat(number));
|
|
768
|
+
offset(number = 1) {
|
|
769
|
+
this.$db.set('OFFSET', `${this.$constants('OFFSET')} ${number}`);
|
|
895
770
|
return this;
|
|
896
|
-
}
|
|
771
|
+
}
|
|
897
772
|
/**
|
|
898
773
|
*
|
|
899
774
|
* @param {...string} columns
|
|
900
775
|
* @return {this} this
|
|
901
776
|
*/
|
|
902
|
-
|
|
903
|
-
var columns = [];
|
|
904
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
905
|
-
columns[_i] = arguments[_i];
|
|
906
|
-
}
|
|
777
|
+
hidden(...columns) {
|
|
907
778
|
this.$db.set('HIDDEN', columns);
|
|
908
779
|
return this;
|
|
909
|
-
}
|
|
780
|
+
}
|
|
910
781
|
/**
|
|
911
782
|
*
|
|
912
783
|
* update data in the database
|
|
913
784
|
* @param {object} data
|
|
914
785
|
* @return {this} this
|
|
915
786
|
*/
|
|
916
|
-
|
|
917
|
-
|
|
787
|
+
update(data) {
|
|
788
|
+
const query = this._queryUpdate(data);
|
|
918
789
|
this.$db.set('UPDATE', [
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
790
|
+
`${this.$constants('UPDATE')}`,
|
|
791
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
792
|
+
`${query}`
|
|
922
793
|
].join(' '));
|
|
923
794
|
this.$db.set('SAVE', 'UPDATE');
|
|
924
795
|
return this;
|
|
925
|
-
}
|
|
796
|
+
}
|
|
926
797
|
/**
|
|
927
798
|
*
|
|
928
799
|
* insert data into the database
|
|
929
800
|
* @param {object} data
|
|
930
801
|
* @return {this} this
|
|
931
802
|
*/
|
|
932
|
-
|
|
933
|
-
|
|
803
|
+
insert(data) {
|
|
804
|
+
const query = this._queryInsert(data);
|
|
934
805
|
this.$db.set('INSERT', [
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
806
|
+
`${this.$constants('INSERT')}`,
|
|
807
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
808
|
+
`${query}`
|
|
938
809
|
].join(' '));
|
|
939
810
|
this.$db.set('SAVE', 'INSERT');
|
|
940
811
|
return this;
|
|
941
|
-
}
|
|
812
|
+
}
|
|
942
813
|
/**
|
|
943
814
|
*
|
|
944
815
|
* insert data into the database
|
|
945
816
|
* @param {object} data
|
|
946
817
|
* @return {this} this
|
|
947
818
|
*/
|
|
948
|
-
|
|
949
|
-
|
|
819
|
+
create(data) {
|
|
820
|
+
const query = this._queryInsert(data);
|
|
950
821
|
this.$db.set('INSERT', [
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
822
|
+
`${this.$constants('INSERT')}`,
|
|
823
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
824
|
+
`${query}`
|
|
954
825
|
].join(' '));
|
|
955
826
|
this.$db.set('SAVE', 'INSERT');
|
|
956
827
|
return this;
|
|
957
|
-
}
|
|
828
|
+
}
|
|
958
829
|
/**
|
|
959
830
|
*
|
|
960
831
|
* insert muliple data into the database
|
|
961
832
|
* @param {array} data create multiple data
|
|
962
833
|
* @return {this} this this
|
|
963
834
|
*/
|
|
964
|
-
|
|
965
|
-
|
|
835
|
+
createMultiple(data) {
|
|
836
|
+
const query = this._queryInsertMultiple(data);
|
|
966
837
|
this.$db.set('INSERT', [
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
838
|
+
`${this.$constants('INSERT')}`,
|
|
839
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
840
|
+
`${query}`
|
|
970
841
|
].join(' '));
|
|
971
842
|
this.$db.set('SAVE', 'INSERT_MULTIPLE');
|
|
972
843
|
return this;
|
|
973
|
-
}
|
|
844
|
+
}
|
|
974
845
|
/**
|
|
975
846
|
*
|
|
976
847
|
* insert muliple data into the database
|
|
977
848
|
* @param {array} data create multiple data
|
|
978
849
|
* @return {this} this this
|
|
979
850
|
*/
|
|
980
|
-
|
|
981
|
-
|
|
851
|
+
insertMultiple(data) {
|
|
852
|
+
const query = this._queryInsertMultiple(data);
|
|
982
853
|
this.$db.set('INSERT', [
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
854
|
+
`${this.$constants('INSERT')}`,
|
|
855
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
856
|
+
`${query}`
|
|
986
857
|
].join(' '));
|
|
987
858
|
this.$db.set('SAVE', 'INSERT_MULTIPLE');
|
|
988
859
|
return this;
|
|
989
|
-
}
|
|
860
|
+
}
|
|
990
861
|
/**
|
|
991
862
|
*
|
|
992
863
|
* @return {string} return sql query
|
|
993
864
|
*/
|
|
994
|
-
|
|
995
|
-
return this.
|
|
996
|
-
}
|
|
865
|
+
toString() {
|
|
866
|
+
return this._buildQuery();
|
|
867
|
+
}
|
|
997
868
|
/**
|
|
998
869
|
*
|
|
999
870
|
* @return {string} return sql query
|
|
1000
871
|
*/
|
|
1001
|
-
|
|
1002
|
-
return this.
|
|
1003
|
-
}
|
|
872
|
+
toSQL() {
|
|
873
|
+
return this._buildQuery();
|
|
874
|
+
}
|
|
1004
875
|
/**
|
|
1005
876
|
*
|
|
1006
877
|
* @param {boolean} debug debug sql statements
|
|
1007
878
|
* @return {this} this this
|
|
1008
879
|
*/
|
|
1009
|
-
|
|
1010
|
-
if (debug === void 0) { debug = true; }
|
|
880
|
+
debug(debug = true) {
|
|
1011
881
|
this.$db.set('DEBUG', debug);
|
|
1012
882
|
return this;
|
|
1013
|
-
}
|
|
883
|
+
}
|
|
1014
884
|
/**
|
|
1015
885
|
*
|
|
1016
886
|
* @param {boolean} debug debug sql statements
|
|
1017
887
|
* @return {this} this this
|
|
1018
888
|
*/
|
|
1019
|
-
|
|
1020
|
-
if (debug === void 0) { debug = true; }
|
|
889
|
+
dd(debug = true) {
|
|
1021
890
|
this.$db.set('DEBUG', debug);
|
|
1022
891
|
return this;
|
|
1023
|
-
}
|
|
892
|
+
}
|
|
1024
893
|
/**
|
|
1025
894
|
*
|
|
1026
895
|
* @param {object} data create not exists data
|
|
1027
896
|
* @return {this} this this
|
|
1028
897
|
*/
|
|
1029
|
-
|
|
1030
|
-
|
|
898
|
+
createNotExists(data) {
|
|
899
|
+
const query = this._queryInsert(data);
|
|
1031
900
|
this.$db.set('INSERT', [
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
901
|
+
`${this.$constants('INSERT')}`,
|
|
902
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
903
|
+
`${query}`
|
|
1035
904
|
].join(' '));
|
|
1036
905
|
this.$db.set('SAVE', 'INSERT_NOT_EXISTS');
|
|
1037
906
|
return this;
|
|
1038
|
-
}
|
|
907
|
+
}
|
|
1039
908
|
/**
|
|
1040
909
|
*
|
|
1041
910
|
* @param {object} data insert not exists data
|
|
1042
911
|
* @return {this} this this
|
|
1043
912
|
*/
|
|
1044
|
-
|
|
913
|
+
insertNotExists(data) {
|
|
1045
914
|
this.createNotExists(data);
|
|
1046
915
|
return this;
|
|
1047
|
-
}
|
|
916
|
+
}
|
|
1048
917
|
/**
|
|
1049
918
|
*
|
|
1050
919
|
* check data if exists if exists then update. if not exists insert
|
|
1051
920
|
* @param {object} data insert or update data
|
|
1052
921
|
* @return {this} this this
|
|
1053
922
|
*/
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
923
|
+
updateOrCreate(data) {
|
|
924
|
+
const queryUpdate = this._queryUpdate(data);
|
|
925
|
+
const queryInsert = this._queryInsert(data);
|
|
1057
926
|
this.$db.set('INSERT', [
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
927
|
+
`${this.$constants('INSERT')}`,
|
|
928
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
929
|
+
`${queryInsert}`
|
|
1061
930
|
].join(' '));
|
|
1062
931
|
this.$db.set('UPDATE', [
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
932
|
+
`${this.$constants('UPDATE')}`,
|
|
933
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
934
|
+
`${queryUpdate}`
|
|
1066
935
|
].join(' '));
|
|
1067
936
|
this.$db.set('SAVE', 'UPDATE_OR_INSERT');
|
|
1068
937
|
return this;
|
|
1069
|
-
}
|
|
938
|
+
}
|
|
1070
939
|
/**
|
|
1071
940
|
*
|
|
1072
941
|
* check data if exists if exists then update. if not exists insert
|
|
1073
942
|
* @param {object} data insert or update data
|
|
1074
943
|
* @return {this} this this
|
|
1075
944
|
*/
|
|
1076
|
-
|
|
945
|
+
updateOrInsert(data) {
|
|
1077
946
|
this.updateOrCreate(data);
|
|
1078
947
|
return this;
|
|
1079
|
-
}
|
|
948
|
+
}
|
|
1080
949
|
/**
|
|
1081
950
|
*
|
|
1082
951
|
* check data if exists if exists then update. if not exists insert
|
|
1083
952
|
* @param {object} data insert or update data
|
|
1084
953
|
* @return {this} this this
|
|
1085
954
|
*/
|
|
1086
|
-
|
|
955
|
+
insertOrUpdate(data) {
|
|
1087
956
|
this.updateOrCreate(data);
|
|
1088
957
|
return this;
|
|
1089
|
-
}
|
|
958
|
+
}
|
|
1090
959
|
/**
|
|
1091
960
|
*
|
|
1092
961
|
* check data if exists if exists then update. if not exists insert
|
|
1093
962
|
* @param {object} data create or update data
|
|
1094
963
|
* @return {this} this this
|
|
1095
964
|
*/
|
|
1096
|
-
|
|
965
|
+
createOrUpdate(data) {
|
|
1097
966
|
this.updateOrCreate(data);
|
|
1098
967
|
return this;
|
|
1099
|
-
}
|
|
968
|
+
}
|
|
1100
969
|
/**
|
|
1101
970
|
*
|
|
1102
971
|
* @param {Object} options options for connection database with credentials
|
|
@@ -1107,27 +976,54 @@ var Database = /** @class */ (function (_super) {
|
|
|
1107
976
|
* @param {string} option.password
|
|
1108
977
|
* @return {this} this
|
|
1109
978
|
*/
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
979
|
+
connection(options) {
|
|
980
|
+
const { host, port, database, username: user, password, ...others } = options;
|
|
981
|
+
const pool = new connection_1.PoolConnection({
|
|
982
|
+
host,
|
|
983
|
+
port,
|
|
984
|
+
database,
|
|
985
|
+
user,
|
|
986
|
+
password,
|
|
987
|
+
...others
|
|
988
|
+
});
|
|
1113
989
|
this.$pool.set(pool.connection());
|
|
1114
990
|
return this;
|
|
1115
|
-
}
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
*
|
|
994
|
+
* @param {Function} pool pool connection database
|
|
995
|
+
* @return {this} this
|
|
996
|
+
*/
|
|
997
|
+
pool(pool) {
|
|
998
|
+
if (!pool?.hasOwnProperty('query')) {
|
|
999
|
+
throw new Error('pool must have a query property');
|
|
1000
|
+
}
|
|
1001
|
+
this.$pool.set(pool);
|
|
1002
|
+
return this;
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
*
|
|
1006
|
+
* @param {object} connection pool database
|
|
1007
|
+
* @return {this} this
|
|
1008
|
+
*/
|
|
1009
|
+
bind(connection) {
|
|
1010
|
+
if (!connection?.hasOwnProperty('query')) {
|
|
1011
|
+
throw new Error('connection must have a query property');
|
|
1012
|
+
}
|
|
1013
|
+
if (typeof connection.query !== 'function') {
|
|
1014
|
+
throw new Error('connection must have a query function');
|
|
1015
|
+
}
|
|
1016
|
+
this.$pool.set(connection);
|
|
1017
|
+
return this;
|
|
1018
|
+
}
|
|
1116
1019
|
/**
|
|
1117
1020
|
* execute sql statements with raw sql query
|
|
1118
1021
|
* @param {string} sql sql execute return data
|
|
1119
1022
|
* @return {promise<any>}
|
|
1120
1023
|
*/
|
|
1121
|
-
|
|
1122
|
-
return
|
|
1123
|
-
|
|
1124
|
-
switch (_a.label) {
|
|
1125
|
-
case 0: return [4 /*yield*/, this._queryStatement(sql)];
|
|
1126
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
});
|
|
1130
|
-
};
|
|
1024
|
+
async rawQuery(sql) {
|
|
1025
|
+
return await this._queryStatement(sql);
|
|
1026
|
+
}
|
|
1131
1027
|
/**
|
|
1132
1028
|
*
|
|
1133
1029
|
* plus value then update
|
|
@@ -1135,26 +1031,15 @@ var Database = /** @class */ (function (_super) {
|
|
|
1135
1031
|
* @param {number} value
|
|
1136
1032
|
* @return {promise<any>}
|
|
1137
1033
|
*/
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
this.$db.set('UPDATE', [
|
|
1148
|
-
"".concat(this.$constants('UPDATE')),
|
|
1149
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
1150
|
-
"".concat(query)
|
|
1151
|
-
].join(' '));
|
|
1152
|
-
return [4 /*yield*/, this._update(true)];
|
|
1153
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1154
|
-
}
|
|
1155
|
-
});
|
|
1156
|
-
});
|
|
1157
|
-
};
|
|
1034
|
+
async increment(column = 'id', value = 1) {
|
|
1035
|
+
const query = `${this.$constants('SET')} ${column} = ${column} + ${value}`;
|
|
1036
|
+
this.$db.set('UPDATE', [
|
|
1037
|
+
`${this.$constants('UPDATE')}`,
|
|
1038
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1039
|
+
`${query}`
|
|
1040
|
+
].join(' '));
|
|
1041
|
+
return await this._update(true);
|
|
1042
|
+
}
|
|
1158
1043
|
/**
|
|
1159
1044
|
*
|
|
1160
1045
|
* minus value then update
|
|
@@ -1162,70 +1047,43 @@ var Database = /** @class */ (function (_super) {
|
|
|
1162
1047
|
* @param {number} value
|
|
1163
1048
|
* @return {promise<any>}
|
|
1164
1049
|
*/
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
this.$db.set('UPDATE', [
|
|
1175
|
-
"".concat(this.$constants('UPDATE')),
|
|
1176
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
1177
|
-
"".concat(query)
|
|
1178
|
-
].join(' '));
|
|
1179
|
-
return [4 /*yield*/, this._update(true)];
|
|
1180
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
});
|
|
1184
|
-
};
|
|
1050
|
+
async decrement(column = 'id', value = 1) {
|
|
1051
|
+
const query = `${this.$constants('SET')} ${column} = ${column} - ${value}`;
|
|
1052
|
+
this.$db.set('UPDATE', [
|
|
1053
|
+
`${this.$constants('UPDATE')}`,
|
|
1054
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1055
|
+
`${query}`
|
|
1056
|
+
].join(' '));
|
|
1057
|
+
return await this._update(true);
|
|
1058
|
+
}
|
|
1185
1059
|
/**
|
|
1186
1060
|
* execute data without condition
|
|
1187
1061
|
* @return {promise<any>}
|
|
1188
1062
|
*/
|
|
1189
|
-
|
|
1190
|
-
return
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
"".concat(this.$db.get('TABLE_NAME'))
|
|
1198
|
-
].join(' '))];
|
|
1199
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
});
|
|
1203
|
-
};
|
|
1063
|
+
async all() {
|
|
1064
|
+
return await this._queryStatement([
|
|
1065
|
+
`${this.$constants('SELECT')}`,
|
|
1066
|
+
`*`,
|
|
1067
|
+
`${this.$constants('FROM')}`,
|
|
1068
|
+
`${this.$db.get('TABLE_NAME')}`
|
|
1069
|
+
].join(' '));
|
|
1070
|
+
}
|
|
1204
1071
|
/**
|
|
1205
1072
|
*
|
|
1206
1073
|
* execute data with where by id
|
|
1207
1074
|
* @param {number} id
|
|
1208
1075
|
* @return {promise<any>}
|
|
1209
1076
|
*/
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
"".concat(this.$constants('WHERE'), " id = ").concat(id)
|
|
1221
|
-
].join(' '))];
|
|
1222
|
-
case 1:
|
|
1223
|
-
result = _a.sent();
|
|
1224
|
-
return [2 /*return*/, (result === null || result === void 0 ? void 0 : result.shift()) || null];
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
});
|
|
1228
|
-
};
|
|
1077
|
+
async find(id) {
|
|
1078
|
+
const result = await this._queryStatement([
|
|
1079
|
+
`${this.$constants('SELECT')}`,
|
|
1080
|
+
`*`,
|
|
1081
|
+
`${this.$constants('FROM')}`,
|
|
1082
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1083
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
1084
|
+
].join(' '));
|
|
1085
|
+
return result?.shift() || null;
|
|
1086
|
+
}
|
|
1229
1087
|
/**
|
|
1230
1088
|
*
|
|
1231
1089
|
* execute data page & limit
|
|
@@ -1234,82 +1092,69 @@ var Database = /** @class */ (function (_super) {
|
|
|
1234
1092
|
* @param {number} paginationOptions.page
|
|
1235
1093
|
* @return {promise<Pagination>}
|
|
1236
1094
|
*/
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
total: total,
|
|
1301
|
-
limit: limit,
|
|
1302
|
-
current_page: currentPage,
|
|
1303
|
-
last_page: lastPage,
|
|
1304
|
-
next_page: nextPage,
|
|
1305
|
-
prev_page: prevPage
|
|
1306
|
-
},
|
|
1307
|
-
data: result !== null && result !== void 0 ? result : []
|
|
1308
|
-
}];
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
});
|
|
1312
|
-
};
|
|
1095
|
+
async pagination(paginationOptions) {
|
|
1096
|
+
let limit = 15;
|
|
1097
|
+
let page = 1;
|
|
1098
|
+
if (paginationOptions != null) {
|
|
1099
|
+
limit = paginationOptions?.limit || limit;
|
|
1100
|
+
page = paginationOptions?.page || page;
|
|
1101
|
+
}
|
|
1102
|
+
const currentPage = page;
|
|
1103
|
+
const nextPage = currentPage + 1;
|
|
1104
|
+
const prevPage = currentPage - 1 === 0 ? 1 : currentPage - 1;
|
|
1105
|
+
const offset = (page - 1) * limit;
|
|
1106
|
+
let sql = this._buildQuery();
|
|
1107
|
+
if (!sql.includes(this.$constants('LIMIT'))) {
|
|
1108
|
+
sql = [
|
|
1109
|
+
`${sql}`,
|
|
1110
|
+
`${this.$constants('LIMIT')}`,
|
|
1111
|
+
`${limit}`,
|
|
1112
|
+
`${this.$constants('OFFSET')} ${offset}`
|
|
1113
|
+
].join(' ');
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
sql = sql.replace(this.$db.get('LIMIT'), `${limit} ${this.$constants('OFFSET')} ${offset}`);
|
|
1117
|
+
}
|
|
1118
|
+
const result = await this._queryStatement(sql);
|
|
1119
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1120
|
+
this._hiddenColumn(result);
|
|
1121
|
+
if (!result.length)
|
|
1122
|
+
return {
|
|
1123
|
+
meta: {
|
|
1124
|
+
total: 0,
|
|
1125
|
+
limit,
|
|
1126
|
+
total_page: 0,
|
|
1127
|
+
current_page: currentPage,
|
|
1128
|
+
last_page: 0,
|
|
1129
|
+
next_page: 0,
|
|
1130
|
+
prev_page: 0
|
|
1131
|
+
},
|
|
1132
|
+
data: []
|
|
1133
|
+
};
|
|
1134
|
+
this.$db.set('SELECT', [
|
|
1135
|
+
`${this.$constants('SELECT')}`,
|
|
1136
|
+
`${this.$constants('COUNT')}(*)`,
|
|
1137
|
+
`${this.$constants('AS')} total`
|
|
1138
|
+
].join(' '));
|
|
1139
|
+
sql = this._buildQuery();
|
|
1140
|
+
const count = await this._queryStatement(sql);
|
|
1141
|
+
const total = count.shift().total || 0;
|
|
1142
|
+
let lastPage = Math.ceil(total / limit) || 0;
|
|
1143
|
+
lastPage = lastPage > 1 ? lastPage : 1;
|
|
1144
|
+
const totalPage = result?.length ?? 0;
|
|
1145
|
+
return {
|
|
1146
|
+
meta: {
|
|
1147
|
+
total_page: totalPage,
|
|
1148
|
+
total,
|
|
1149
|
+
limit,
|
|
1150
|
+
current_page: currentPage,
|
|
1151
|
+
last_page: lastPage,
|
|
1152
|
+
next_page: nextPage,
|
|
1153
|
+
prev_page: prevPage
|
|
1154
|
+
},
|
|
1155
|
+
data: result ?? []
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1313
1158
|
/**
|
|
1314
1159
|
*
|
|
1315
1160
|
* execute data useing page & limit
|
|
@@ -1318,1379 +1163,971 @@ var Database = /** @class */ (function (_super) {
|
|
|
1318
1163
|
* @param {number} paginationOptions.page
|
|
1319
1164
|
* @return {promise<Pagination>}
|
|
1320
1165
|
*/
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
limit = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.limit) || limit;
|
|
1331
|
-
page = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.page) || page;
|
|
1332
|
-
}
|
|
1333
|
-
return [4 /*yield*/, this.pagination({ limit: limit, page: page })];
|
|
1334
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1335
|
-
}
|
|
1336
|
-
});
|
|
1337
|
-
});
|
|
1338
|
-
};
|
|
1166
|
+
async paginate(paginationOptions) {
|
|
1167
|
+
let limit = 15;
|
|
1168
|
+
let page = 1;
|
|
1169
|
+
if (paginationOptions != null) {
|
|
1170
|
+
limit = paginationOptions?.limit || limit;
|
|
1171
|
+
page = paginationOptions?.page || page;
|
|
1172
|
+
}
|
|
1173
|
+
return await this.pagination({ limit, page });
|
|
1174
|
+
}
|
|
1339
1175
|
/**
|
|
1340
1176
|
*
|
|
1341
1177
|
* execute data return object | null
|
|
1342
1178
|
* @return {promise<object | null>}
|
|
1343
1179
|
*/
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1180
|
+
async first() {
|
|
1181
|
+
let sql = this._buildQuery();
|
|
1182
|
+
if (!sql.includes(this.$constants('LIMIT')))
|
|
1183
|
+
sql = `${sql} ${this.$constants('LIMIT')} 1`;
|
|
1184
|
+
else
|
|
1185
|
+
sql = sql.replace(this.$db.get('LIMIT'), `${this.$constants('LIMIT')} 1`);
|
|
1186
|
+
const result = await this._queryStatement(sql);
|
|
1187
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1188
|
+
this._hiddenColumn(result);
|
|
1189
|
+
if (this.$db.get('PLUCK')) {
|
|
1190
|
+
const pluck = this.$db.get('PLUCK');
|
|
1191
|
+
const newData = result?.shift();
|
|
1192
|
+
const checkProperty = newData.hasOwnProperty(pluck);
|
|
1193
|
+
if (!checkProperty)
|
|
1194
|
+
throw new Error(`can't find property '${pluck}' of result`);
|
|
1195
|
+
return newData[pluck] || null;
|
|
1196
|
+
}
|
|
1197
|
+
return result?.shift() || null;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
*
|
|
1201
|
+
* execute data return object | throw rror
|
|
1202
|
+
* @return {promise<object | null>}
|
|
1203
|
+
*/
|
|
1204
|
+
async findOne() {
|
|
1205
|
+
return await this.first();
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
*
|
|
1209
|
+
* execute data return object | throw Error
|
|
1210
|
+
* @return {promise<object | Error>}
|
|
1211
|
+
*/
|
|
1212
|
+
async firstOrError(message, options) {
|
|
1213
|
+
let sql = this._buildQuery();
|
|
1214
|
+
if (!sql.includes(this.$constants('LIMIT')))
|
|
1215
|
+
sql = `${sql} ${this.$constants('LIMIT')} 1`;
|
|
1216
|
+
else
|
|
1217
|
+
sql = sql.replace(this.$db.get('LIMIT'), `${this.$constants('LIMIT')} 1`);
|
|
1218
|
+
const result = await this._queryStatement(sql);
|
|
1219
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1220
|
+
this._hiddenColumn(result);
|
|
1221
|
+
if (this.$db.get('PLUCK')) {
|
|
1222
|
+
const pluck = this.$db.get('PLUCK');
|
|
1223
|
+
const newData = result?.shift();
|
|
1224
|
+
const checkProperty = newData.hasOwnProperty(pluck);
|
|
1225
|
+
if (!checkProperty)
|
|
1226
|
+
throw new Error(`can't find property '${pluck}' of result`);
|
|
1227
|
+
const data = newData[pluck] || null;
|
|
1228
|
+
if (data == null) {
|
|
1229
|
+
if (options == null) {
|
|
1230
|
+
throw { message, code: 400 };
|
|
1370
1231
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1232
|
+
throw { message, ...options };
|
|
1233
|
+
}
|
|
1234
|
+
return data;
|
|
1235
|
+
}
|
|
1236
|
+
const data = result?.shift() || null;
|
|
1237
|
+
if (data == null) {
|
|
1238
|
+
if (options == null) {
|
|
1239
|
+
throw { message, code: 400 };
|
|
1240
|
+
}
|
|
1241
|
+
throw { message, ...options };
|
|
1242
|
+
}
|
|
1243
|
+
return data;
|
|
1244
|
+
}
|
|
1374
1245
|
/**
|
|
1375
1246
|
*
|
|
1376
1247
|
* execute data return object | null
|
|
1377
1248
|
* @return {promise<object | null>}
|
|
1378
1249
|
*/
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1250
|
+
async findOneOrError(message, options) {
|
|
1251
|
+
let sql = this._buildQuery();
|
|
1252
|
+
if (!sql.includes(this.$constants('LIMIT')))
|
|
1253
|
+
sql = `${sql} ${this.$constants('LIMIT')} 1`;
|
|
1254
|
+
else
|
|
1255
|
+
sql = sql.replace(this.$db.get('LIMIT'), `${this.$constants('LIMIT')} 1`);
|
|
1256
|
+
const result = await this._queryStatement(sql);
|
|
1257
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1258
|
+
this._hiddenColumn(result);
|
|
1259
|
+
if (this.$db.get('PLUCK')) {
|
|
1260
|
+
const pluck = this.$db.get('PLUCK');
|
|
1261
|
+
const newData = result?.shift();
|
|
1262
|
+
const checkProperty = newData.hasOwnProperty(pluck);
|
|
1263
|
+
if (!checkProperty)
|
|
1264
|
+
throw new Error(`can't find property '${pluck}' of result`);
|
|
1265
|
+
return newData[pluck] || null;
|
|
1266
|
+
}
|
|
1267
|
+
return result?.shift() || null;
|
|
1268
|
+
}
|
|
1389
1269
|
/**
|
|
1390
1270
|
*
|
|
1391
1271
|
* execute data return Array
|
|
1392
1272
|
* @return {promise<Array<any>>}
|
|
1393
1273
|
*/
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
pluck_1 = this.$db.get('PLUCK');
|
|
1420
|
-
newData = result.map(function (d) { return d[pluck_1]; });
|
|
1421
|
-
if (newData.every(function (d) { return d == null; })) {
|
|
1422
|
-
throw new Error("can't find property '".concat(pluck_1, "' of result"));
|
|
1423
|
-
}
|
|
1424
|
-
return [2 /*return*/, newData || []];
|
|
1425
|
-
}
|
|
1426
|
-
return [2 /*return*/, result || []];
|
|
1427
|
-
}
|
|
1428
|
-
});
|
|
1429
|
-
});
|
|
1430
|
-
};
|
|
1274
|
+
async get() {
|
|
1275
|
+
const sql = this._buildQuery();
|
|
1276
|
+
const result = await this._queryStatement(sql);
|
|
1277
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1278
|
+
this._hiddenColumn(result);
|
|
1279
|
+
if (this.$db.get('CHUNK')) {
|
|
1280
|
+
const data = result.reduce((resultArray, item, index) => {
|
|
1281
|
+
const chunkIndex = Math.floor(index / this.$db.get('CHUNK'));
|
|
1282
|
+
if (!resultArray[chunkIndex])
|
|
1283
|
+
resultArray[chunkIndex] = [];
|
|
1284
|
+
resultArray[chunkIndex].push(item);
|
|
1285
|
+
return resultArray;
|
|
1286
|
+
}, []);
|
|
1287
|
+
return data || [];
|
|
1288
|
+
}
|
|
1289
|
+
if (this.$db.get('PLUCK')) {
|
|
1290
|
+
const pluck = this.$db.get('PLUCK');
|
|
1291
|
+
const newData = result.map((d) => d[pluck]);
|
|
1292
|
+
if (newData.every((d) => d == null)) {
|
|
1293
|
+
throw new Error(`can't find property '${pluck}' of result`);
|
|
1294
|
+
}
|
|
1295
|
+
return newData || [];
|
|
1296
|
+
}
|
|
1297
|
+
return result || [];
|
|
1298
|
+
}
|
|
1431
1299
|
/**
|
|
1432
1300
|
*
|
|
1433
1301
|
* execute data return Array
|
|
1434
1302
|
* @return {promise<Array<any>>}
|
|
1435
1303
|
*/
|
|
1436
|
-
|
|
1437
|
-
return
|
|
1438
|
-
|
|
1439
|
-
switch (_a.label) {
|
|
1440
|
-
case 0: return [4 /*yield*/, this.get()];
|
|
1441
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1442
|
-
}
|
|
1443
|
-
});
|
|
1444
|
-
});
|
|
1445
|
-
};
|
|
1304
|
+
async findMany() {
|
|
1305
|
+
return await this.get();
|
|
1306
|
+
}
|
|
1446
1307
|
/**
|
|
1447
1308
|
*
|
|
1448
1309
|
* execute data return json of result
|
|
1449
1310
|
* @return {promise<string>}
|
|
1450
1311
|
*/
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
sql = this._queryGenrate();
|
|
1459
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1460
|
-
case 1:
|
|
1461
|
-
result = _b.sent();
|
|
1462
|
-
if ((_a = this.$db.get('HIDDEN')) === null || _a === void 0 ? void 0 : _a.length)
|
|
1463
|
-
this._hiddenColumn(result);
|
|
1464
|
-
return [2 /*return*/, JSON.stringify(result)];
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
});
|
|
1468
|
-
};
|
|
1312
|
+
async toJSON() {
|
|
1313
|
+
const sql = this._buildQuery();
|
|
1314
|
+
const result = await this._queryStatement(sql);
|
|
1315
|
+
if (this.$db.get('HIDDEN')?.length)
|
|
1316
|
+
this._hiddenColumn(result);
|
|
1317
|
+
return JSON.stringify(result);
|
|
1318
|
+
}
|
|
1469
1319
|
/**
|
|
1470
1320
|
*
|
|
1471
1321
|
* execute data return array of results
|
|
1472
1322
|
* @param {string=} column [column=id]
|
|
1473
1323
|
* @return {promise<Array>}
|
|
1474
1324
|
*/
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
this.$db.set('SELECT', "".concat(this.$constants('SELECT'), " ").concat(column));
|
|
1483
|
-
sql = this._queryGenrate();
|
|
1484
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1485
|
-
case 1:
|
|
1486
|
-
result = _a.sent();
|
|
1487
|
-
toArray = result.map(function (data) { return data[column]; });
|
|
1488
|
-
return [2 /*return*/, toArray];
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
});
|
|
1492
|
-
};
|
|
1325
|
+
async toArray(column = 'id') {
|
|
1326
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} ${column}`);
|
|
1327
|
+
const sql = this._buildQuery();
|
|
1328
|
+
const result = await this._queryStatement(sql);
|
|
1329
|
+
const toArray = result.map((data) => data[column]);
|
|
1330
|
+
return toArray;
|
|
1331
|
+
}
|
|
1493
1332
|
/**
|
|
1494
1333
|
*
|
|
1495
1334
|
* execute data return number of results
|
|
1496
1335
|
* @param {string=} column [column=id]
|
|
1497
1336
|
* @return {promise<number>}
|
|
1498
1337
|
*/
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
"".concat(this.$constants('COUNT'), "(").concat(column, ")"),
|
|
1510
|
-
"".concat(this.$constants('AS'), " total")
|
|
1511
|
-
].join(' '));
|
|
1512
|
-
sql = this._queryGenrate();
|
|
1513
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1514
|
-
case 1:
|
|
1515
|
-
result = _b.sent();
|
|
1516
|
-
return [2 /*return*/, ((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.total) || 0];
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
});
|
|
1520
|
-
};
|
|
1338
|
+
async count(column = 'id') {
|
|
1339
|
+
this.$db.set('SELECT', [
|
|
1340
|
+
`${this.$constants('SELECT')}`,
|
|
1341
|
+
`${this.$constants('COUNT')}(${column})`,
|
|
1342
|
+
`${this.$constants('AS')} total`
|
|
1343
|
+
].join(' '));
|
|
1344
|
+
const sql = this._buildQuery();
|
|
1345
|
+
const result = await this._queryStatement(sql);
|
|
1346
|
+
return result?.shift()?.total || 0;
|
|
1347
|
+
}
|
|
1521
1348
|
/**
|
|
1522
1349
|
*
|
|
1523
1350
|
* execute data return result is exists
|
|
1524
1351
|
* @return {promise<boolean>}
|
|
1525
1352
|
*/
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
"".concat(this.$db.get('WHERE')),
|
|
1539
|
-
"".concat(this.$constants('LIMIT'), " 1) as 'exists'")
|
|
1540
|
-
].join(' '))];
|
|
1541
|
-
case 1:
|
|
1542
|
-
result = _b.sent();
|
|
1543
|
-
return [2 /*return*/, !!((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.exists) || false];
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
});
|
|
1547
|
-
};
|
|
1353
|
+
async exists() {
|
|
1354
|
+
const result = await this._queryStatement([
|
|
1355
|
+
`${this.$constants('SELECT')}`,
|
|
1356
|
+
`${this.$constants('EXISTS')}(${this.$constants('SELECT')}`,
|
|
1357
|
+
`*`,
|
|
1358
|
+
`${this.$db.get('FROM')}`,
|
|
1359
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1360
|
+
`${this.$db.get('WHERE')}`,
|
|
1361
|
+
`${this.$constants('LIMIT')} 1) ${this.$constants('AS')} 'exists'`
|
|
1362
|
+
].join(' '));
|
|
1363
|
+
return !!result?.shift()?.exists || false;
|
|
1364
|
+
}
|
|
1548
1365
|
/**
|
|
1549
1366
|
*
|
|
1550
1367
|
* execute data return average of results
|
|
1551
1368
|
* @param {string=} column [column=id]
|
|
1552
1369
|
* @return {promise<number>}
|
|
1553
1370
|
*/
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
"".concat(this.$constants('AVG'), "(").concat(column, ")"),
|
|
1565
|
-
"".concat(this.$constants('AS'), " avg")
|
|
1566
|
-
].join(' '));
|
|
1567
|
-
sql = this._queryGenrate();
|
|
1568
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1569
|
-
case 1:
|
|
1570
|
-
result = _b.sent();
|
|
1571
|
-
return [2 /*return*/, ((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.avg) || 0];
|
|
1572
|
-
}
|
|
1573
|
-
});
|
|
1574
|
-
});
|
|
1575
|
-
};
|
|
1371
|
+
async avg(column = 'id') {
|
|
1372
|
+
this.$db.set('SELECT', [
|
|
1373
|
+
`${this.$constants('SELECT')}`,
|
|
1374
|
+
`${this.$constants('AVG')}(${column})`,
|
|
1375
|
+
`${this.$constants('AS')} avg`
|
|
1376
|
+
].join(' '));
|
|
1377
|
+
const sql = this._buildQuery();
|
|
1378
|
+
const result = await this._queryStatement(sql);
|
|
1379
|
+
return result?.shift()?.avg || 0;
|
|
1380
|
+
}
|
|
1576
1381
|
/**
|
|
1577
1382
|
*
|
|
1578
1383
|
* execute data return summary of results
|
|
1579
1384
|
* @param {string=} column [column=id]
|
|
1580
1385
|
* @return {promise<number>}
|
|
1581
1386
|
*/
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
switch (_b.label) {
|
|
1589
|
-
case 0:
|
|
1590
|
-
this.$db.set('SELECT', "".concat(this.$constants('SELECT'), " ").concat(this.$constants('SUM'), "(").concat(column, ") ").concat(this.$constants('AS'), " sum"));
|
|
1591
|
-
sql = this._queryGenrate();
|
|
1592
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1593
|
-
case 1:
|
|
1594
|
-
result = _b.sent();
|
|
1595
|
-
return [2 /*return*/, ((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.sum) || 0];
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
});
|
|
1599
|
-
};
|
|
1387
|
+
async sum(column = 'id') {
|
|
1388
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('SUM')}(${column}) ${this.$constants('AS')} sum`);
|
|
1389
|
+
const sql = this._buildQuery();
|
|
1390
|
+
const result = await this._queryStatement(sql);
|
|
1391
|
+
return result?.shift()?.sum || 0;
|
|
1392
|
+
}
|
|
1600
1393
|
/**
|
|
1601
1394
|
*
|
|
1602
1395
|
* execute data return maximum of results
|
|
1603
1396
|
* @param {string=} column [column=id]
|
|
1604
1397
|
* @return {promise<number>}
|
|
1605
1398
|
*/
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
switch (_b.label) {
|
|
1613
|
-
case 0:
|
|
1614
|
-
this.$db.set('SELECT', "".concat(this.$constants('SELECT'), " ").concat(this.$constants('MAX'), "(").concat(column, ") ").concat(this.$constants('AS'), " max"));
|
|
1615
|
-
sql = this._queryGenrate();
|
|
1616
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1617
|
-
case 1:
|
|
1618
|
-
result = _b.sent();
|
|
1619
|
-
return [2 /*return*/, ((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.max) || 0];
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
});
|
|
1623
|
-
};
|
|
1399
|
+
async max(column = 'id') {
|
|
1400
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MAX')}(${column}) ${this.$constants('AS')} max`);
|
|
1401
|
+
const sql = this._buildQuery();
|
|
1402
|
+
const result = await this._queryStatement(sql);
|
|
1403
|
+
return result?.shift()?.max || 0;
|
|
1404
|
+
}
|
|
1624
1405
|
/**
|
|
1625
1406
|
*
|
|
1626
1407
|
* execute data return minimum of results
|
|
1627
1408
|
* @param {string=} column [column=id]
|
|
1628
1409
|
* @return {promise<number>}
|
|
1629
1410
|
*/
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
switch (_b.label) {
|
|
1637
|
-
case 0:
|
|
1638
|
-
this.$db.set('SELECT', "".concat(this.$constants('SELECT'), " ").concat(this.$constants('MIN'), "(").concat(column, ") ").concat(this.$constants('AS'), " min"));
|
|
1639
|
-
sql = this._queryGenrate();
|
|
1640
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1641
|
-
case 1:
|
|
1642
|
-
result = _b.sent();
|
|
1643
|
-
return [2 /*return*/, ((_a = result.shift()) === null || _a === void 0 ? void 0 : _a.min) || 0];
|
|
1644
|
-
}
|
|
1645
|
-
});
|
|
1646
|
-
});
|
|
1647
|
-
};
|
|
1411
|
+
async min(column = 'id') {
|
|
1412
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} ${this.$constants('MIN')}(${column}) ${this.$constants('AS')} min`);
|
|
1413
|
+
const sql = this._buildQuery();
|
|
1414
|
+
const result = await this._queryStatement(sql);
|
|
1415
|
+
return result?.shift()?.min || 0;
|
|
1416
|
+
}
|
|
1648
1417
|
/**
|
|
1649
1418
|
*
|
|
1650
1419
|
* delete data from database
|
|
1651
1420
|
* @return {promise<boolean>}
|
|
1652
1421
|
*/
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
].join(' '));
|
|
1669
|
-
return [4 /*yield*/, this._actionStatement({ sql: this.$db.get('DELETE') })];
|
|
1670
|
-
case 1:
|
|
1671
|
-
result = _b.sent();
|
|
1672
|
-
if (result)
|
|
1673
|
-
return [2 /*return*/, (_a = !!result) !== null && _a !== void 0 ? _a : false];
|
|
1674
|
-
return [2 /*return*/, false];
|
|
1675
|
-
}
|
|
1676
|
-
});
|
|
1677
|
-
});
|
|
1678
|
-
};
|
|
1422
|
+
async delete() {
|
|
1423
|
+
if (!this.$db.get('WHERE')) {
|
|
1424
|
+
throw new Error("can't delete without where condition");
|
|
1425
|
+
}
|
|
1426
|
+
this.$db.set('DELETE', [
|
|
1427
|
+
`${this.$constants('DELETE')}`,
|
|
1428
|
+
`${this.$db.get('FROM')}`,
|
|
1429
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1430
|
+
`${this.$db.get('WHERE')}`
|
|
1431
|
+
].join(' '));
|
|
1432
|
+
const result = await this._actionStatement({ sql: this.$db.get('DELETE') });
|
|
1433
|
+
if (result)
|
|
1434
|
+
return !!result ?? false;
|
|
1435
|
+
return false;
|
|
1436
|
+
}
|
|
1679
1437
|
/**
|
|
1680
1438
|
*
|
|
1681
1439
|
* delete data from database ignore where condition
|
|
1682
1440
|
* @return {promise<boolean>}
|
|
1683
1441
|
*/
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
].join(' '));
|
|
1697
|
-
return [4 /*yield*/, this._actionStatement({ sql: this.$db.get('DELETE') })];
|
|
1698
|
-
case 1:
|
|
1699
|
-
result = _b.sent();
|
|
1700
|
-
if (result)
|
|
1701
|
-
return [2 /*return*/, (_a = !!result) !== null && _a !== void 0 ? _a : false];
|
|
1702
|
-
return [2 /*return*/, false];
|
|
1703
|
-
}
|
|
1704
|
-
});
|
|
1705
|
-
});
|
|
1706
|
-
};
|
|
1442
|
+
async forceDelete() {
|
|
1443
|
+
this.$db.set('DELETE', [
|
|
1444
|
+
`${this.$constants('DELETE')}`,
|
|
1445
|
+
`${this.$db.get('FROM')}`,
|
|
1446
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1447
|
+
`${this.$db.get('WHERE')}`
|
|
1448
|
+
].join(' '));
|
|
1449
|
+
const result = await this._actionStatement({ sql: this.$db.get('DELETE') });
|
|
1450
|
+
if (result)
|
|
1451
|
+
return !!result ?? false;
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1707
1454
|
/**
|
|
1708
1455
|
*
|
|
1709
1456
|
* execute data return Array *grouping results in column
|
|
1710
1457
|
* @param {string} column
|
|
1711
1458
|
* @return {promise<Array>}
|
|
1712
1459
|
*/
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
].join(' ');
|
|
1743
|
-
return [4 /*yield*/, this._queryStatement(sqlGroups)];
|
|
1744
|
-
case 2:
|
|
1745
|
-
groups = _a.sent();
|
|
1746
|
-
resultData = results.map(function (result) {
|
|
1747
|
-
var _a;
|
|
1748
|
-
var id = result[column];
|
|
1749
|
-
var newData = groups.filter(function (data) { return data[column] === id; });
|
|
1750
|
-
return (_a = {},
|
|
1751
|
-
_a[column] = id,
|
|
1752
|
-
_a.data = newData,
|
|
1753
|
-
_a);
|
|
1754
|
-
});
|
|
1755
|
-
return [2 /*return*/, resultData];
|
|
1756
|
-
}
|
|
1460
|
+
async getGroupBy(column) {
|
|
1461
|
+
this.$db.set('GROUP_BY', `${this.$constants('GROUP_BY')} ${column}`);
|
|
1462
|
+
this.$db.set('SELECT', [
|
|
1463
|
+
`${this.$db.get('SELECT')}`,
|
|
1464
|
+
`, ${this.$constants('GROUP_CONCAT')}(id)`,
|
|
1465
|
+
`${this.$constants('AS')} data`
|
|
1466
|
+
].join(' '));
|
|
1467
|
+
const sql = this._buildQuery();
|
|
1468
|
+
const results = await this._queryStatement(sql);
|
|
1469
|
+
let data = [];
|
|
1470
|
+
results.forEach((result) => {
|
|
1471
|
+
const splits = result?.data?.split(',') ?? '0';
|
|
1472
|
+
splits.forEach((split) => data = [...data, split]);
|
|
1473
|
+
});
|
|
1474
|
+
const sqlGroups = [
|
|
1475
|
+
`${this.$constants('SELECT')}`,
|
|
1476
|
+
`*`,
|
|
1477
|
+
`${this.$constants('FROM')}`,
|
|
1478
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1479
|
+
`${this.$constants('WHERE')} id ${this.$constants('IN')}`,
|
|
1480
|
+
`(${data.map((a) => `\'${a}\'`).join(',') || ['0']})`
|
|
1481
|
+
].join(' ');
|
|
1482
|
+
const groups = await this._queryStatement(sqlGroups);
|
|
1483
|
+
const resultData = results.map((result) => {
|
|
1484
|
+
const id = result[column];
|
|
1485
|
+
const newData = groups.filter((data) => data[column] === id);
|
|
1486
|
+
return ({
|
|
1487
|
+
[column]: id,
|
|
1488
|
+
data: newData
|
|
1757
1489
|
});
|
|
1758
1490
|
});
|
|
1759
|
-
|
|
1491
|
+
return resultData;
|
|
1492
|
+
}
|
|
1760
1493
|
/**
|
|
1761
1494
|
*
|
|
1762
1495
|
* execute data return grouping results by index
|
|
1763
1496
|
* @param {string} column
|
|
1764
1497
|
* @return {promise<Array>}
|
|
1765
1498
|
*/
|
|
1766
|
-
|
|
1767
|
-
return
|
|
1768
|
-
|
|
1769
|
-
switch (_a.label) {
|
|
1770
|
-
case 0: return [4 /*yield*/, this.getGroupBy(column)];
|
|
1771
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1772
|
-
}
|
|
1773
|
-
});
|
|
1774
|
-
});
|
|
1775
|
-
};
|
|
1499
|
+
async findManyGroupBy(column) {
|
|
1500
|
+
return await this.getGroupBy(column);
|
|
1501
|
+
}
|
|
1776
1502
|
/**
|
|
1777
1503
|
* execute data when save *action [insert , update]
|
|
1778
|
-
* @param {object} transaction | DB.beginTransaction()
|
|
1779
1504
|
* @return {Promise<any>}
|
|
1780
1505
|
*/
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
query_1 = this._queryUpdate(attributes);
|
|
1795
|
-
this.$db.set('UPDATE', [
|
|
1796
|
-
"".concat(this.$constants('UPDATE')),
|
|
1797
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
1798
|
-
"".concat(query_1)
|
|
1799
|
-
].join(' '));
|
|
1800
|
-
this.$db.set('SAVE', 'UPDATE');
|
|
1801
|
-
break;
|
|
1802
|
-
}
|
|
1803
|
-
query = this._queryInsert(attributes);
|
|
1804
|
-
this.$db.set('INSERT', [
|
|
1805
|
-
"".concat(this.$constants('INSERT')),
|
|
1806
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
1807
|
-
"".concat(query)
|
|
1808
|
-
].join(' '));
|
|
1809
|
-
this.$db.set('SAVE', 'INSERT');
|
|
1810
|
-
break;
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
_b = this.$db.get('SAVE');
|
|
1814
|
-
switch (_b) {
|
|
1815
|
-
case 'INSERT_MULTIPLE': return [3 /*break*/, 1];
|
|
1816
|
-
case 'INSERT': return [3 /*break*/, 3];
|
|
1817
|
-
case 'UPDATE': return [3 /*break*/, 5];
|
|
1818
|
-
case 'INSERT_NOT_EXISTS': return [3 /*break*/, 7];
|
|
1819
|
-
case 'UPDATE_OR_INSERT': return [3 /*break*/, 9];
|
|
1820
|
-
}
|
|
1821
|
-
return [3 /*break*/, 11];
|
|
1822
|
-
case 1: return [4 /*yield*/, this._createMultiple()];
|
|
1823
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
1824
|
-
case 3: return [4 /*yield*/, this._create()];
|
|
1825
|
-
case 4: return [2 /*return*/, _c.sent()];
|
|
1826
|
-
case 5: return [4 /*yield*/, this._update()];
|
|
1827
|
-
case 6: return [2 /*return*/, _c.sent()];
|
|
1828
|
-
case 7: return [4 /*yield*/, this._insertNotExists()];
|
|
1829
|
-
case 8: return [2 /*return*/, _c.sent()];
|
|
1830
|
-
case 9: return [4 /*yield*/, this._updateOrInsert()];
|
|
1831
|
-
case 10: return [2 /*return*/, _c.sent()];
|
|
1832
|
-
case 11: return [2 /*return*/];
|
|
1506
|
+
async save() {
|
|
1507
|
+
const attributes = this.$attributes;
|
|
1508
|
+
if (Object.keys(attributes)?.length) {
|
|
1509
|
+
while (true) {
|
|
1510
|
+
if (this.$db.get('WHERE')) {
|
|
1511
|
+
const query = this._queryUpdate(attributes);
|
|
1512
|
+
this.$db.set('UPDATE', [
|
|
1513
|
+
`${this.$constants('UPDATE')}`,
|
|
1514
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1515
|
+
`${query}`
|
|
1516
|
+
].join(' '));
|
|
1517
|
+
this.$db.set('SAVE', 'UPDATE');
|
|
1518
|
+
break;
|
|
1833
1519
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1520
|
+
const query = this._queryInsert(attributes);
|
|
1521
|
+
this.$db.set('INSERT', [
|
|
1522
|
+
`${this.$constants('INSERT')}`,
|
|
1523
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1524
|
+
`${query}`
|
|
1525
|
+
].join(' '));
|
|
1526
|
+
this.$db.set('SAVE', 'INSERT');
|
|
1527
|
+
break;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
switch (this.$db.get('SAVE')) {
|
|
1531
|
+
case 'INSERT_MULTIPLE': return await this._createMultiple();
|
|
1532
|
+
case 'INSERT': return await this._create();
|
|
1533
|
+
case 'UPDATE': return await this._update();
|
|
1534
|
+
case 'INSERT_NOT_EXISTS': return await this._insertNotExists();
|
|
1535
|
+
case 'UPDATE_OR_INSERT': return await this._updateOrInsert();
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1837
1538
|
/**
|
|
1838
1539
|
*
|
|
1839
1540
|
* show columns in table
|
|
1840
1541
|
* @param {string=} table table name
|
|
1841
1542
|
* @return {Promise<Array>}
|
|
1842
1543
|
*/
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
"`".concat(table.replace(/\`/g, ''), "`")
|
|
1855
|
-
].join(' ');
|
|
1856
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1857
|
-
case 1:
|
|
1858
|
-
rawColumns = _a.sent();
|
|
1859
|
-
columns = rawColumns.map(function (column) { return column.Field; });
|
|
1860
|
-
return [2 /*return*/, columns];
|
|
1861
|
-
}
|
|
1862
|
-
});
|
|
1863
|
-
});
|
|
1864
|
-
};
|
|
1544
|
+
async showColumns(table = this.$db.get('TABLE_NAME')) {
|
|
1545
|
+
const sql = [
|
|
1546
|
+
`${this.$constants('SHOW')}`,
|
|
1547
|
+
`${this.$constants('COLUMNS')}`,
|
|
1548
|
+
`${this.$constants('FROM')}`,
|
|
1549
|
+
`\`${table.replace(/\`/g, '')}\``
|
|
1550
|
+
].join(' ');
|
|
1551
|
+
const rawColumns = await this._queryStatement(sql);
|
|
1552
|
+
const columns = rawColumns.map((column) => column.Field);
|
|
1553
|
+
return columns;
|
|
1554
|
+
}
|
|
1865
1555
|
/**
|
|
1866
1556
|
*
|
|
1867
1557
|
* show schemas in table
|
|
1868
|
-
* @param {string=} table table name
|
|
1558
|
+
* @param {string=} table [table= current table name]
|
|
1869
1559
|
* @return {Promise<Array>}
|
|
1870
1560
|
*/
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
}
|
|
1903
|
-
if (r.Default) {
|
|
1904
|
-
schema.push("DEFAULT '".concat(r.Default, "'"));
|
|
1905
|
-
}
|
|
1906
|
-
if (r.Extra) {
|
|
1907
|
-
schema.push("".concat(r.Extra.toUpperCase()));
|
|
1908
|
-
}
|
|
1909
|
-
return schema.join(' ');
|
|
1910
|
-
});
|
|
1911
|
-
return [2 /*return*/, schemas];
|
|
1912
|
-
}
|
|
1913
|
-
});
|
|
1561
|
+
async showSchemas(table = this.$db.get('TABLE_NAME')) {
|
|
1562
|
+
const sql = [
|
|
1563
|
+
`${this.$constants('SHOW')}`,
|
|
1564
|
+
`${this.$constants('COLUMNS')}`,
|
|
1565
|
+
`${this.$constants('FROM')}`,
|
|
1566
|
+
`\`${table.replace(/\`/g, '')}\``
|
|
1567
|
+
].join(' ');
|
|
1568
|
+
const raw = await this._queryStatement(sql);
|
|
1569
|
+
const schemas = raw.map((r) => {
|
|
1570
|
+
const schema = [];
|
|
1571
|
+
schema.push(`${r.Field}`);
|
|
1572
|
+
schema.push(`${r.Type}`);
|
|
1573
|
+
if (r.Null === 'YES') {
|
|
1574
|
+
schema.push(`NULL`);
|
|
1575
|
+
}
|
|
1576
|
+
if (r.Null === 'NO') {
|
|
1577
|
+
schema.push(`NOT NULL`);
|
|
1578
|
+
}
|
|
1579
|
+
if (r.Key === 'PRI') {
|
|
1580
|
+
schema.push(`PRIMARY KEY`);
|
|
1581
|
+
}
|
|
1582
|
+
if (r.Key === 'UNI') {
|
|
1583
|
+
schema.push(`UNIQUE`);
|
|
1584
|
+
}
|
|
1585
|
+
if (r.Default) {
|
|
1586
|
+
schema.push(`DEFAULT '${r.Default}'`);
|
|
1587
|
+
}
|
|
1588
|
+
if (r.Extra) {
|
|
1589
|
+
schema.push(`${r.Extra.toUpperCase()}`);
|
|
1590
|
+
}
|
|
1591
|
+
return schema.join(' ');
|
|
1914
1592
|
});
|
|
1915
|
-
|
|
1593
|
+
return schemas;
|
|
1594
|
+
}
|
|
1916
1595
|
/**
|
|
1917
1596
|
*
|
|
1918
1597
|
* show values in table
|
|
1919
1598
|
* @param {string=} table table name
|
|
1920
1599
|
* @return {Promise<Array>}
|
|
1921
1600
|
*/
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
].join(' ');
|
|
1935
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
1936
|
-
case 1:
|
|
1937
|
-
raw = _a.sent();
|
|
1938
|
-
values = raw.map(function (value) {
|
|
1939
|
-
return "(".concat(Object.values(value).map(function (v) {
|
|
1940
|
-
return v == null ? 'NULL' : "'".concat(v, "'");
|
|
1941
|
-
}).join(','), ")");
|
|
1942
|
-
});
|
|
1943
|
-
return [2 /*return*/, values];
|
|
1944
|
-
}
|
|
1945
|
-
});
|
|
1601
|
+
async showValues(table = this.$db.get('TABLE_NAME')) {
|
|
1602
|
+
const sql = [
|
|
1603
|
+
`${this.$constants('SELECT')}`,
|
|
1604
|
+
'*',
|
|
1605
|
+
`${this.$constants('FROM')}`,
|
|
1606
|
+
`\`${table.replace(/\`/g, '')}\``
|
|
1607
|
+
].join(' ');
|
|
1608
|
+
const raw = await this._queryStatement(sql);
|
|
1609
|
+
const values = raw.map((value) => {
|
|
1610
|
+
return `(${Object.values(value).map((v) => {
|
|
1611
|
+
return v == null ? 'NULL' : `'${v}'`;
|
|
1612
|
+
}).join(',')})`;
|
|
1946
1613
|
});
|
|
1947
|
-
|
|
1614
|
+
return values;
|
|
1615
|
+
}
|
|
1948
1616
|
/**
|
|
1949
1617
|
*
|
|
1950
|
-
* backup database intro new database same server or to another server
|
|
1618
|
+
* backup this database intro new database same server or to another server
|
|
1951
1619
|
* @param {Object} backupOptions
|
|
1952
1620
|
* @param {string} backup.database
|
|
1953
|
-
* @param {object?} backup.
|
|
1954
|
-
* @param {string} backup.
|
|
1955
|
-
* @param {number} backup.
|
|
1956
|
-
* @param {string} backup.
|
|
1957
|
-
* @param {string} backup.
|
|
1958
|
-
* @param {string} backup.
|
|
1621
|
+
* @param {object?} backup.to
|
|
1622
|
+
* @param {string} backup.to.host
|
|
1623
|
+
* @param {number} backup.to.port
|
|
1624
|
+
* @param {string} backup.to.database
|
|
1625
|
+
* @param {string} backup.to.username
|
|
1626
|
+
* @param {string} backup.to.password
|
|
1959
1627
|
|
|
1960
1628
|
* @return {Promise<boolean>}
|
|
1961
1629
|
*/
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
];
|
|
1991
|
-
return [4 /*yield*/, this.showValues(table)];
|
|
1992
|
-
case 5:
|
|
1993
|
-
values = _d.sent();
|
|
1994
|
-
valueSQL = [];
|
|
1995
|
-
if (!values.length) return [3 /*break*/, 7];
|
|
1996
|
-
return [4 /*yield*/, this.showColumns(table)];
|
|
1997
|
-
case 6:
|
|
1998
|
-
columns = _d.sent();
|
|
1999
|
-
valueSQL = [
|
|
2000
|
-
"".concat(this.$constants('INSERT')),
|
|
2001
|
-
"`".concat(database, ".").concat(table, "`"),
|
|
2002
|
-
"(".concat(columns.map(function (column) { return "`".concat(column, "`"); }).join(','), ")"),
|
|
2003
|
-
"".concat(this.$constants('VALUES'), " ").concat(values.join(','))
|
|
2004
|
-
];
|
|
2005
|
-
_d.label = 7;
|
|
2006
|
-
case 7:
|
|
2007
|
-
backup = __spreadArray(__spreadArray([], __read(backup), false), [
|
|
2008
|
-
{
|
|
2009
|
-
table: createTableSQL.join(' '),
|
|
2010
|
-
values: valueSQL.join(' '),
|
|
2011
|
-
}
|
|
2012
|
-
], false);
|
|
2013
|
-
_d.label = 8;
|
|
2014
|
-
case 8:
|
|
2015
|
-
tables_1_1 = tables_1.next();
|
|
2016
|
-
return [3 /*break*/, 3];
|
|
2017
|
-
case 9: return [3 /*break*/, 12];
|
|
2018
|
-
case 10:
|
|
2019
|
-
e_1_1 = _d.sent();
|
|
2020
|
-
e_1 = { error: e_1_1 };
|
|
2021
|
-
return [3 /*break*/, 12];
|
|
2022
|
-
case 11:
|
|
2023
|
-
try {
|
|
2024
|
-
if (tables_1_1 && !tables_1_1.done && (_b = tables_1.return)) _b.call(tables_1);
|
|
2025
|
-
}
|
|
2026
|
-
finally { if (e_1) throw e_1.error; }
|
|
2027
|
-
return [7 /*endfinally*/];
|
|
2028
|
-
case 12:
|
|
2029
|
-
if (connection != null && Object.keys(connection).length)
|
|
2030
|
-
this.connection(connection);
|
|
2031
|
-
return [4 /*yield*/, this._queryStatement("".concat(this.$constants('CREATE_DATABASE_NOT_EXISTS'), " `").concat(database, "`"))];
|
|
2032
|
-
case 13:
|
|
2033
|
-
_d.sent();
|
|
2034
|
-
_d.label = 14;
|
|
2035
|
-
case 14:
|
|
2036
|
-
_d.trys.push([14, 20, 21, 22]);
|
|
2037
|
-
backup_1 = __values(backup), backup_1_1 = backup_1.next();
|
|
2038
|
-
_d.label = 15;
|
|
2039
|
-
case 15:
|
|
2040
|
-
if (!!backup_1_1.done) return [3 /*break*/, 19];
|
|
2041
|
-
b = backup_1_1.value;
|
|
2042
|
-
return [4 /*yield*/, this._queryStatement(b.table)];
|
|
2043
|
-
case 16:
|
|
2044
|
-
_d.sent();
|
|
2045
|
-
if (!b.values) return [3 /*break*/, 18];
|
|
2046
|
-
return [4 /*yield*/, this._queryStatement(b.values)];
|
|
2047
|
-
case 17:
|
|
2048
|
-
_d.sent();
|
|
2049
|
-
_d.label = 18;
|
|
2050
|
-
case 18:
|
|
2051
|
-
backup_1_1 = backup_1.next();
|
|
2052
|
-
return [3 /*break*/, 15];
|
|
2053
|
-
case 19: return [3 /*break*/, 22];
|
|
2054
|
-
case 20:
|
|
2055
|
-
e_2_1 = _d.sent();
|
|
2056
|
-
e_2 = { error: e_2_1 };
|
|
2057
|
-
return [3 /*break*/, 22];
|
|
2058
|
-
case 21:
|
|
2059
|
-
try {
|
|
2060
|
-
if (backup_1_1 && !backup_1_1.done && (_c = backup_1.return)) _c.call(backup_1);
|
|
2061
|
-
}
|
|
2062
|
-
finally { if (e_2) throw e_2.error; }
|
|
2063
|
-
return [7 /*endfinally*/];
|
|
2064
|
-
case 22: return [2 /*return*/, true];
|
|
1630
|
+
async backup({ database, to }) {
|
|
1631
|
+
const tables = await this._queryStatement('SHOW TABLES');
|
|
1632
|
+
let backup = [];
|
|
1633
|
+
for (const t of tables) {
|
|
1634
|
+
const table = String(Object.values(t).shift());
|
|
1635
|
+
const schemas = await this.showSchemas(table);
|
|
1636
|
+
const createTableSQL = [
|
|
1637
|
+
`${this.$constants('CREATE_TABLE_NOT_EXISTS')}`,
|
|
1638
|
+
`\`${database}.${table}\``,
|
|
1639
|
+
`(${schemas.join(',')})`,
|
|
1640
|
+
`${this.$constants('ENGINE')}`,
|
|
1641
|
+
];
|
|
1642
|
+
const values = await this.showValues(table);
|
|
1643
|
+
let valueSQL = [];
|
|
1644
|
+
if (values.length) {
|
|
1645
|
+
const columns = await this.showColumns(table);
|
|
1646
|
+
valueSQL = [
|
|
1647
|
+
`${this.$constants('INSERT')}`,
|
|
1648
|
+
`\`${database}.${table}\``,
|
|
1649
|
+
`(${columns.map((column) => `\`${column}\``).join(',')})`,
|
|
1650
|
+
`${this.$constants('VALUES')} ${values.join(',')}`
|
|
1651
|
+
];
|
|
1652
|
+
}
|
|
1653
|
+
backup = [
|
|
1654
|
+
...backup,
|
|
1655
|
+
{
|
|
1656
|
+
table: createTableSQL.join(' '),
|
|
1657
|
+
values: valueSQL.join(' '),
|
|
2065
1658
|
}
|
|
2066
|
-
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
tables_2_1 = tables_2.next();
|
|
2123
|
-
return [3 /*break*/, 3];
|
|
2124
|
-
case 9: return [3 /*break*/, 12];
|
|
2125
|
-
case 10:
|
|
2126
|
-
e_3_1 = _d.sent();
|
|
2127
|
-
e_3 = { error: e_3_1 };
|
|
2128
|
-
return [3 /*break*/, 12];
|
|
2129
|
-
case 11:
|
|
2130
|
-
try {
|
|
2131
|
-
if (tables_2_1 && !tables_2_1.done && (_b = tables_2.return)) _b.call(tables_2);
|
|
2132
|
-
}
|
|
2133
|
-
finally { if (e_3) throw e_3.error; }
|
|
2134
|
-
return [7 /*endfinally*/];
|
|
2135
|
-
case 12:
|
|
2136
|
-
if (connection != null && Object.keys(connection).length)
|
|
2137
|
-
this.connection(connection);
|
|
2138
|
-
sql = [
|
|
2139
|
-
"SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";",
|
|
2140
|
-
"START TRANSACTION;",
|
|
2141
|
-
"SET time_zone = \"+00:00\";",
|
|
2142
|
-
"".concat(this.$constants('CREATE_DATABASE_NOT_EXISTS'), " `").concat(database, "`;"),
|
|
2143
|
-
"USE `".concat(database, "`;")
|
|
2144
|
-
];
|
|
2145
|
-
try {
|
|
2146
|
-
for (backup_2 = __values(backup), backup_2_1 = backup_2.next(); !backup_2_1.done; backup_2_1 = backup_2.next()) {
|
|
2147
|
-
b = backup_2_1.value;
|
|
2148
|
-
sql = __spreadArray(__spreadArray([], __read(sql), false), [b.table], false);
|
|
2149
|
-
if (b.values) {
|
|
2150
|
-
sql = __spreadArray(__spreadArray([], __read(sql), false), [b.values], false);
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
2155
|
-
finally {
|
|
2156
|
-
try {
|
|
2157
|
-
if (backup_2_1 && !backup_2_1.done && (_c = backup_2.return)) _c.call(backup_2);
|
|
2158
|
-
}
|
|
2159
|
-
finally { if (e_4) throw e_4.error; }
|
|
2160
|
-
}
|
|
2161
|
-
fs_1.default.writeFileSync(filePath, (0, sql_formatter_1.format)(__spreadArray(__spreadArray([], __read(sql), false), ['COMMIT;'], false).join('\n'), {
|
|
2162
|
-
language: 'spark',
|
|
2163
|
-
tabWidth: 2,
|
|
2164
|
-
keywordCase: 'upper',
|
|
2165
|
-
linesBetweenQueries: 1,
|
|
2166
|
-
}));
|
|
2167
|
-
return [2 /*return*/, true];
|
|
1659
|
+
];
|
|
1660
|
+
}
|
|
1661
|
+
if (to != null && Object.keys(to).length)
|
|
1662
|
+
this.connection(to);
|
|
1663
|
+
await this._queryStatement(`${this.$constants('CREATE_DATABASE_NOT_EXISTS')} \`${database}\``);
|
|
1664
|
+
for (const b of backup) {
|
|
1665
|
+
await this._queryStatement(b.table);
|
|
1666
|
+
if (b.values) {
|
|
1667
|
+
await this._queryStatement(b.values);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
return true;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
*
|
|
1674
|
+
* backup database intro file
|
|
1675
|
+
* @param {Object} backupOptions
|
|
1676
|
+
* @param {string} backup.database
|
|
1677
|
+
* @param {object?} backup.filePath
|
|
1678
|
+
* @param {object?} backup.connection
|
|
1679
|
+
* @param {string} backup.connection.host
|
|
1680
|
+
* @param {number} backup.connection.port
|
|
1681
|
+
* @param {string} backup.connection.database
|
|
1682
|
+
* @param {string} backup.connection.username
|
|
1683
|
+
* @param {string} backup.connection.password
|
|
1684
|
+
|
|
1685
|
+
* @return {Promise<boolean>}
|
|
1686
|
+
*/
|
|
1687
|
+
async backupToFile({ filePath, database, connection }) {
|
|
1688
|
+
const tables = await this._queryStatement('SHOW TABLES');
|
|
1689
|
+
let backup = [];
|
|
1690
|
+
for (const t of tables) {
|
|
1691
|
+
const table = String(Object.values(t)?.shift());
|
|
1692
|
+
const schemas = await this.showSchemas(table);
|
|
1693
|
+
const createTableSQL = [
|
|
1694
|
+
`${this.$constants('CREATE_TABLE_NOT_EXISTS')}`,
|
|
1695
|
+
`\`${table}\``,
|
|
1696
|
+
`(${schemas.join(',')})`,
|
|
1697
|
+
`${this.$constants('ENGINE')};`,
|
|
1698
|
+
];
|
|
1699
|
+
const values = await this.showValues(table);
|
|
1700
|
+
let valueSQL = [];
|
|
1701
|
+
if (values.length) {
|
|
1702
|
+
const columns = await this.showColumns(table);
|
|
1703
|
+
valueSQL = [
|
|
1704
|
+
`${this.$constants('INSERT')}`,
|
|
1705
|
+
`\`${table}\``,
|
|
1706
|
+
`(${columns.map((column) => `\`${column}\``).join(',')})`,
|
|
1707
|
+
`${this.$constants('VALUES')} ${values.join(',')};`
|
|
1708
|
+
];
|
|
1709
|
+
}
|
|
1710
|
+
backup = [
|
|
1711
|
+
...backup,
|
|
1712
|
+
{
|
|
1713
|
+
table: createTableSQL.join(' '),
|
|
1714
|
+
values: valueSQL.join(' ')
|
|
2168
1715
|
}
|
|
2169
|
-
|
|
2170
|
-
}
|
|
2171
|
-
|
|
1716
|
+
];
|
|
1717
|
+
}
|
|
1718
|
+
if (connection != null && Object.keys(connection)?.length)
|
|
1719
|
+
this.connection(connection);
|
|
1720
|
+
let sql = [
|
|
1721
|
+
`SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";`,
|
|
1722
|
+
`START TRANSACTION;`,
|
|
1723
|
+
`SET time_zone = "+00:00";`,
|
|
1724
|
+
`${this.$constants('CREATE_DATABASE_NOT_EXISTS')} \`${database}\`;`,
|
|
1725
|
+
`USE \`${database}\`;`
|
|
1726
|
+
];
|
|
1727
|
+
for (const b of backup) {
|
|
1728
|
+
sql = [...sql, b.table];
|
|
1729
|
+
if (b.values) {
|
|
1730
|
+
sql = [...sql, b.values];
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
fs_1.default.writeFileSync(filePath, (0, sql_formatter_1.format)([...sql, 'COMMIT;'].join('\n'), {
|
|
1734
|
+
language: 'spark',
|
|
1735
|
+
tabWidth: 2,
|
|
1736
|
+
keywordCase: 'upper',
|
|
1737
|
+
linesBetweenQueries: 1,
|
|
1738
|
+
}));
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
2172
1741
|
/**
|
|
2173
1742
|
*
|
|
2174
1743
|
* fake data
|
|
2175
1744
|
* @param {number} rows number of rows
|
|
2176
1745
|
* @return {promise<any}
|
|
2177
1746
|
*/
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
finally {
|
|
2215
|
-
try {
|
|
2216
|
-
if (fields_1_1 && !fields_1_1.done && (_b = fields_1.return)) _b.call(fields_1);
|
|
2217
|
-
}
|
|
2218
|
-
finally { if (e_5) throw e_5.error; }
|
|
2219
|
-
}
|
|
2220
|
-
data = __spreadArray(__spreadArray([], __read(data), false), [columnAndValue], false);
|
|
2221
|
-
_d.label = 3;
|
|
2222
|
-
case 3:
|
|
2223
|
-
row++;
|
|
2224
|
-
return [3 /*break*/, 1];
|
|
2225
|
-
case 4:
|
|
2226
|
-
query = this._queryInsertMultiple(data);
|
|
2227
|
-
this.$db.set('INSERT', "".concat(this.$constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
|
|
2228
|
-
this.$db.set('SAVE', 'INSERT_MULTIPLE');
|
|
2229
|
-
return [2 /*return*/, this.save()];
|
|
2230
|
-
}
|
|
2231
|
-
});
|
|
2232
|
-
});
|
|
2233
|
-
};
|
|
1747
|
+
async faker(rows = 1) {
|
|
1748
|
+
let data = [];
|
|
1749
|
+
for (let row = 0; row < rows; row++) {
|
|
1750
|
+
if (this.$db.get('TABLE_NAME') === '' || this.$db.get('TABLE_NAME') == null) {
|
|
1751
|
+
throw new Error("unknow this table");
|
|
1752
|
+
}
|
|
1753
|
+
const sql = [
|
|
1754
|
+
`${this.$constants('SHOW')}`,
|
|
1755
|
+
`${this.$constants('FIELDS')}`,
|
|
1756
|
+
`${this.$constants('FROM')}`,
|
|
1757
|
+
`${this.$db.get('TABLE_NAME')}`
|
|
1758
|
+
].join(' ');
|
|
1759
|
+
const fields = await this._queryStatement(sql);
|
|
1760
|
+
let columnAndValue = {};
|
|
1761
|
+
for (const { Field: field, Type: type } of fields) {
|
|
1762
|
+
const passed = field.toLowerCase() === 'id' ||
|
|
1763
|
+
field.toLowerCase() === '_id' ||
|
|
1764
|
+
field.toLowerCase() === 'uuid';
|
|
1765
|
+
if (passed)
|
|
1766
|
+
continue;
|
|
1767
|
+
columnAndValue = {
|
|
1768
|
+
...columnAndValue,
|
|
1769
|
+
[field]: this.$utils.faker(type)
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
data = [...data, columnAndValue];
|
|
1773
|
+
}
|
|
1774
|
+
const query = this._queryInsertMultiple(data);
|
|
1775
|
+
this.$db.set('INSERT', [
|
|
1776
|
+
`${this.$constants('INSERT')}`,
|
|
1777
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1778
|
+
`${query}`
|
|
1779
|
+
].join(' '));
|
|
1780
|
+
this.$db.set('SAVE', 'INSERT_MULTIPLE');
|
|
1781
|
+
return this.save();
|
|
1782
|
+
}
|
|
2234
1783
|
/**
|
|
2235
1784
|
*
|
|
2236
1785
|
* truncate of table
|
|
2237
1786
|
* @return {promise<boolean>}
|
|
2238
1787
|
*/
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
case 1:
|
|
2248
|
-
_a.sent();
|
|
2249
|
-
return [2 /*return*/, true];
|
|
2250
|
-
}
|
|
2251
|
-
});
|
|
2252
|
-
});
|
|
2253
|
-
};
|
|
1788
|
+
async truncate() {
|
|
1789
|
+
const sql = [
|
|
1790
|
+
`${this.$constants('TRUNCATE_TABLE')}`,
|
|
1791
|
+
`${this.$db.get('TABLE_NAME')}`
|
|
1792
|
+
].join(' ');
|
|
1793
|
+
await this._queryStatement(sql);
|
|
1794
|
+
return true;
|
|
1795
|
+
}
|
|
2254
1796
|
/**
|
|
2255
1797
|
*
|
|
2256
1798
|
* drop of table
|
|
2257
1799
|
* @return {promise<boolean>}
|
|
2258
1800
|
*/
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
1801
|
+
async drop() {
|
|
1802
|
+
const sql = [
|
|
1803
|
+
`${this.$constants('DROP_TABLE')}`,
|
|
1804
|
+
`${this.$db.get('TABLE_NAME')}`
|
|
1805
|
+
].join(' ');
|
|
1806
|
+
await this._queryStatement(sql);
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
_queryWhereIsExists() {
|
|
1810
|
+
return this.$db.get('WHERE')?.includes(this.$constants('WHERE')) || false;
|
|
1811
|
+
}
|
|
1812
|
+
_bindTableAndColumnInQueryWhere(column) {
|
|
1813
|
+
return `${this.$db.get('TABLE_NAME')}.\`${column}\``;
|
|
1814
|
+
}
|
|
1815
|
+
async _insertNotExists() {
|
|
1816
|
+
if (!this.$db.get('WHERE'))
|
|
1817
|
+
throw new Error("Can't insert not exists without where condition");
|
|
1818
|
+
let sql = [
|
|
1819
|
+
`${this.$constants('SELECT')}`,
|
|
1820
|
+
`${this.$constants('EXISTS')}(${this.$constants('SELECT')}`,
|
|
1821
|
+
`*`,
|
|
1822
|
+
`${this.$db.get('FROM')}`,
|
|
1823
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1824
|
+
`${this.$db.get('WHERE')}`,
|
|
1825
|
+
`${this.$constants('LIMIT')} 1)`,
|
|
1826
|
+
`${this.$constants('AS')} 'exists'`
|
|
1827
|
+
].join(' ');
|
|
1828
|
+
const [{ exists: result }] = await this._queryStatement(sql);
|
|
1829
|
+
const check = !!Number.parseInt(result);
|
|
1830
|
+
switch (check) {
|
|
1831
|
+
case false: {
|
|
1832
|
+
const [result, id] = await this._actionStatement({
|
|
1833
|
+
sql: this.$db.get('INSERT'),
|
|
1834
|
+
returnId: true
|
|
1835
|
+
});
|
|
1836
|
+
if (this.$db.get('TRANSACTION')) {
|
|
1837
|
+
this.$db.get('TRANSACTION')?.query.push({
|
|
1838
|
+
table: this.$db.get('TABLE_NAME'),
|
|
1839
|
+
id
|
|
1840
|
+
});
|
|
2270
1841
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
var sql, check, _b, result, _c, _d, result_1, id, sql_1, data;
|
|
2281
|
-
return __generator(this, function (_e) {
|
|
2282
|
-
switch (_e.label) {
|
|
2283
|
-
case 0:
|
|
2284
|
-
if (!this.$db.get('WHERE'))
|
|
2285
|
-
throw new Error("Can't insert not exists without where condition");
|
|
2286
|
-
sql = '';
|
|
2287
|
-
check = false;
|
|
2288
|
-
sql = [
|
|
2289
|
-
"".concat(this.$constants('SELECT')),
|
|
2290
|
-
"".concat(this.$constants('EXISTS'), "(").concat(this.$constants('SELECT')),
|
|
2291
|
-
"*",
|
|
2292
|
-
"".concat(this.$db.get('FROM')),
|
|
2293
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
2294
|
-
"".concat(this.$db.get('WHERE')),
|
|
2295
|
-
"".concat(this.$constants('LIMIT'), " 1)"),
|
|
2296
|
-
"".concat(this.$constants('AS'), " 'exists'")
|
|
2297
|
-
].join(' ');
|
|
2298
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
2299
|
-
case 1:
|
|
2300
|
-
_b = __read.apply(void 0, [_e.sent(), 1]), result = _b[0].exists;
|
|
2301
|
-
check = !!parseInt(result);
|
|
2302
|
-
_c = check;
|
|
2303
|
-
switch (_c) {
|
|
2304
|
-
case false: return [3 /*break*/, 2];
|
|
2305
|
-
case true: return [3 /*break*/, 6];
|
|
2306
|
-
}
|
|
2307
|
-
return [3 /*break*/, 7];
|
|
2308
|
-
case 2: return [4 /*yield*/, this._actionStatement({ sql: this.$db.get('INSERT'), returnId: true })];
|
|
2309
|
-
case 3:
|
|
2310
|
-
_d = __read.apply(void 0, [_e.sent(), 2]), result_1 = _d[0], id = _d[1];
|
|
2311
|
-
if (this.$db.get('TRANSACTION')) {
|
|
2312
|
-
(_a = this.$db.get('TRANSACTION')) === null || _a === void 0 ? void 0 : _a.query.push({
|
|
2313
|
-
table: this.$db.get('TABLE_NAME'),
|
|
2314
|
-
id: id
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
if (!result_1) return [3 /*break*/, 5];
|
|
2318
|
-
sql_1 = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$constants('WHERE'), " id = ").concat(id);
|
|
2319
|
-
return [4 /*yield*/, this._queryStatement(sql_1)];
|
|
2320
|
-
case 4:
|
|
2321
|
-
data = _e.sent();
|
|
2322
|
-
return [2 /*return*/, (data === null || data === void 0 ? void 0 : data.shift()) || null];
|
|
2323
|
-
case 5: return [2 /*return*/, null];
|
|
2324
|
-
case 6:
|
|
2325
|
-
{
|
|
2326
|
-
return [2 /*return*/, null];
|
|
2327
|
-
}
|
|
2328
|
-
_e.label = 7;
|
|
2329
|
-
case 7:
|
|
2330
|
-
{
|
|
2331
|
-
return [2 /*return*/, null];
|
|
2332
|
-
}
|
|
2333
|
-
_e.label = 8;
|
|
2334
|
-
case 8: return [2 /*return*/];
|
|
1842
|
+
if (result) {
|
|
1843
|
+
const sql = [
|
|
1844
|
+
`${this.$db.get('SELECT')}`,
|
|
1845
|
+
`${this.$db.get('FROM')}`,
|
|
1846
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1847
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
1848
|
+
].join(' ');
|
|
1849
|
+
const data = await this._queryStatement(sql);
|
|
1850
|
+
return data?.shift() || null;
|
|
2335
1851
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
1852
|
+
return null;
|
|
1853
|
+
}
|
|
1854
|
+
case true: {
|
|
1855
|
+
return null;
|
|
1856
|
+
}
|
|
1857
|
+
default: {
|
|
1858
|
+
return null;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
_setupPool() {
|
|
1863
|
+
let pool = connection_1.Pool;
|
|
2342
1864
|
return {
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
case 0: return [4 /*yield*/, pool.query(sql)];
|
|
2347
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
2348
|
-
}
|
|
2349
|
-
});
|
|
2350
|
-
}); },
|
|
2351
|
-
set: function (newConnection) {
|
|
1865
|
+
load: () => pool,
|
|
1866
|
+
get: async (sql) => await pool.query(sql),
|
|
1867
|
+
set: (newConnection) => {
|
|
2352
1868
|
pool = newConnection;
|
|
2353
1869
|
return;
|
|
2354
1870
|
}
|
|
2355
1871
|
};
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
1872
|
+
}
|
|
1873
|
+
async _queryStatement(sql) {
|
|
1874
|
+
if (this.$db.get('DEBUG'))
|
|
1875
|
+
this.$utils.consoleDebug(sql);
|
|
1876
|
+
return await this.$pool.get(sql);
|
|
1877
|
+
}
|
|
1878
|
+
async _actionStatement({ sql, returnId = false }) {
|
|
1879
|
+
try {
|
|
1880
|
+
if (this.$db.get('DEBUG'))
|
|
1881
|
+
this.$utils.consoleDebug(sql);
|
|
1882
|
+
if (returnId) {
|
|
1883
|
+
const result = await this.$pool.get(sql);
|
|
1884
|
+
return [result.affectedRows, result.insertId];
|
|
1885
|
+
}
|
|
1886
|
+
const { affectedRows: result } = await this.$pool.get(sql);
|
|
1887
|
+
return result;
|
|
1888
|
+
}
|
|
1889
|
+
catch (err) {
|
|
1890
|
+
throw new Error(err.message);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
async _create() {
|
|
1894
|
+
const [result, id] = await this._actionStatement({
|
|
1895
|
+
sql: this.$db.get('INSERT'),
|
|
1896
|
+
returnId: true
|
|
2374
1897
|
});
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
var result_2, result, err_2;
|
|
2380
|
-
return __generator(this, function (_d) {
|
|
2381
|
-
switch (_d.label) {
|
|
2382
|
-
case 0:
|
|
2383
|
-
_d.trys.push([0, 4, , 5]);
|
|
2384
|
-
if (this.$db.get('DEBUG'))
|
|
2385
|
-
this.$utils.consoleDebug(sql);
|
|
2386
|
-
if (!returnId) return [3 /*break*/, 2];
|
|
2387
|
-
return [4 /*yield*/, this.$pool.get(sql)];
|
|
2388
|
-
case 1:
|
|
2389
|
-
result_2 = _d.sent();
|
|
2390
|
-
return [2 /*return*/, [result_2.affectedRows, result_2.insertId]];
|
|
2391
|
-
case 2: return [4 /*yield*/, this.$pool.get(sql)];
|
|
2392
|
-
case 3:
|
|
2393
|
-
result = (_d.sent()).affectedRows;
|
|
2394
|
-
return [2 /*return*/, result];
|
|
2395
|
-
case 4:
|
|
2396
|
-
err_2 = _d.sent();
|
|
2397
|
-
throw new Error(err_2.message);
|
|
2398
|
-
case 5: return [2 /*return*/];
|
|
2399
|
-
}
|
|
1898
|
+
if (this.$db.get('TRANSACTION')) {
|
|
1899
|
+
this.$db.get('TRANSACTION').query.push({
|
|
1900
|
+
table: this.$db.get('TABLE_NAME'),
|
|
1901
|
+
id
|
|
2400
1902
|
});
|
|
1903
|
+
}
|
|
1904
|
+
if (result) {
|
|
1905
|
+
const sql = [
|
|
1906
|
+
`${this.$db.get('SELECT')}`,
|
|
1907
|
+
`${this.$db.get('FROM')}`,
|
|
1908
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1909
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
1910
|
+
].join(' ');
|
|
1911
|
+
const data = await this._queryStatement(sql);
|
|
1912
|
+
const result = data?.shift() || null;
|
|
1913
|
+
this.$db.set('RESULT', result);
|
|
1914
|
+
return result;
|
|
1915
|
+
}
|
|
1916
|
+
return null;
|
|
1917
|
+
}
|
|
1918
|
+
async _createMultiple() {
|
|
1919
|
+
const [result, id] = await this._actionStatement({
|
|
1920
|
+
sql: this.$db.get('INSERT'),
|
|
1921
|
+
returnId: true
|
|
2401
1922
|
});
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
_a = __read.apply(void 0, [_b.sent(), 2]), result = _a[0], id = _a[1];
|
|
2411
|
-
if (this.$db.get('TRANSACTION')) {
|
|
2412
|
-
this.$db.get('TRANSACTION').query.push({
|
|
2413
|
-
table: this.$db.get('TABLE_NAME'),
|
|
2414
|
-
id: id
|
|
2415
|
-
});
|
|
2416
|
-
}
|
|
2417
|
-
if (!result) return [3 /*break*/, 3];
|
|
2418
|
-
sql = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$constants('WHERE'), " id = ").concat(id);
|
|
2419
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
2420
|
-
case 2:
|
|
2421
|
-
data = _b.sent();
|
|
2422
|
-
result_3 = (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
2423
|
-
this.$db.set('RESULT', result_3);
|
|
2424
|
-
return [2 /*return*/, result_3];
|
|
2425
|
-
case 3: return [2 /*return*/, null];
|
|
1923
|
+
if (result) {
|
|
1924
|
+
const arrayId = [...Array(result)].map((_, i) => i + id);
|
|
1925
|
+
for (const id of arrayId) {
|
|
1926
|
+
if (this.$db.get('TRANSACTION')) {
|
|
1927
|
+
this.$db.get('TRANSACTION').query.push({
|
|
1928
|
+
table: this.$db.get('TABLE_NAME'),
|
|
1929
|
+
id
|
|
1930
|
+
});
|
|
2426
1931
|
}
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
1932
|
+
}
|
|
1933
|
+
const sql = [
|
|
1934
|
+
`${this.$db.get('SELECT')}`,
|
|
1935
|
+
`${this.$db.get('FROM')}`,
|
|
1936
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1937
|
+
`${this.$constants('WHERE')} id`,
|
|
1938
|
+
`${this.$constants('IN')} (${arrayId})`
|
|
1939
|
+
].join(' ');
|
|
1940
|
+
const data = await this._queryStatement(sql);
|
|
1941
|
+
const resultData = data || null;
|
|
1942
|
+
this.$db.set('RESULT', resultData);
|
|
1943
|
+
return resultData;
|
|
1944
|
+
}
|
|
1945
|
+
return null;
|
|
1946
|
+
}
|
|
1947
|
+
async _updateOrInsert() {
|
|
1948
|
+
if (!this.$db.get('WHERE')) {
|
|
1949
|
+
throw new Error("Can't update or insert without where condition");
|
|
1950
|
+
}
|
|
1951
|
+
let sql = [
|
|
1952
|
+
`${this.$constants('SELECT')}`,
|
|
1953
|
+
`${this.$constants('EXISTS')}(${this.$constants('SELECT')}`,
|
|
1954
|
+
`*`,
|
|
1955
|
+
`${this.$db.get('FROM')}`,
|
|
1956
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1957
|
+
`${this.$db.get('WHERE')}`,
|
|
1958
|
+
`${this.$constants('LIMIT')} 1)`,
|
|
1959
|
+
`${this.$constants('AS')} 'exists'`
|
|
1960
|
+
].join(' ');
|
|
1961
|
+
let check = false;
|
|
1962
|
+
const [{ exists: result }] = await this._queryStatement(sql);
|
|
1963
|
+
check = !!parseInt(result);
|
|
1964
|
+
switch (check) {
|
|
1965
|
+
case false: {
|
|
1966
|
+
const [result, id] = await this._actionStatement({
|
|
1967
|
+
sql: this.$db.get('INSERT'),
|
|
1968
|
+
returnId: true
|
|
1969
|
+
});
|
|
1970
|
+
if (this.$db.get('TRANSACTION')) {
|
|
1971
|
+
this.$db.get('TRANSACTION').query.push({
|
|
1972
|
+
table: this.$db.get('TABLE_NAME'),
|
|
1973
|
+
id
|
|
1974
|
+
});
|
|
2467
1975
|
}
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
throw new Error("Can't update or insert without where condition");
|
|
2480
|
-
sql = [
|
|
2481
|
-
"".concat(this.$constants('SELECT')),
|
|
2482
|
-
"".concat(this.$constants('EXISTS'), "(").concat(this.$constants('SELECT')),
|
|
2483
|
-
"*",
|
|
2484
|
-
"".concat(this.$db.get('FROM')),
|
|
2485
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
2486
|
-
"".concat(this.$db.get('WHERE')),
|
|
2487
|
-
"".concat(this.$constants('LIMIT'), " 1)"),
|
|
2488
|
-
"".concat(this.$constants('AS'), " 'exists'")
|
|
2489
|
-
].join(' ');
|
|
2490
|
-
check = false;
|
|
2491
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
2492
|
-
case 1:
|
|
2493
|
-
_a = __read.apply(void 0, [_e.sent(), 1]), result = _a[0].exists;
|
|
2494
|
-
check = !!parseInt(result);
|
|
2495
|
-
_b = check;
|
|
2496
|
-
switch (_b) {
|
|
2497
|
-
case false: return [3 /*break*/, 2];
|
|
2498
|
-
case true: return [3 /*break*/, 6];
|
|
2499
|
-
}
|
|
2500
|
-
return [3 /*break*/, 10];
|
|
2501
|
-
case 2: return [4 /*yield*/, this._actionStatement({ sql: this.$db.get('INSERT'), returnId: true })];
|
|
2502
|
-
case 3:
|
|
2503
|
-
_c = __read.apply(void 0, [_e.sent(), 2]), result_4 = _c[0], id = _c[1];
|
|
2504
|
-
if (this.$db.get('TRANSACTION')) {
|
|
2505
|
-
this.$db.get('TRANSACTION').query.push({
|
|
2506
|
-
table: this.$db.get('TABLE_NAME'),
|
|
2507
|
-
id: id
|
|
2508
|
-
});
|
|
2509
|
-
}
|
|
2510
|
-
if (!result_4) return [3 /*break*/, 5];
|
|
2511
|
-
sql_2 = [
|
|
2512
|
-
"".concat(this.$db.get('SELECT')),
|
|
2513
|
-
"".concat(this.$db.get('FROM')),
|
|
2514
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
2515
|
-
"".concat(this.$constants('WHERE'), " id = ").concat(id)
|
|
2516
|
-
].join(' ');
|
|
2517
|
-
return [4 /*yield*/, this._queryStatement(sql_2)];
|
|
2518
|
-
case 4:
|
|
2519
|
-
data = _e.sent();
|
|
2520
|
-
resultData = __assign(__assign({}, data === null || data === void 0 ? void 0 : data.shift()), { action_status: 'insert' }) || null;
|
|
2521
|
-
this.$db.set('RESULT', resultData);
|
|
2522
|
-
return [2 /*return*/, resultData];
|
|
2523
|
-
case 5: return [2 /*return*/, null];
|
|
2524
|
-
case 6: return [4 /*yield*/, this._actionStatement({ sql: "".concat(this.$db.get('UPDATE'), " ").concat(this.$db.get('WHERE')) })];
|
|
2525
|
-
case 7:
|
|
2526
|
-
result_5 = _e.sent();
|
|
2527
|
-
if (!result_5) return [3 /*break*/, 9];
|
|
2528
|
-
return [4 /*yield*/, this._queryStatement([
|
|
2529
|
-
"".concat(this.$db.get('SELECT')),
|
|
2530
|
-
"".concat(this.$db.get('FROM')),
|
|
2531
|
-
"".concat(this.$db.get('TABLE_NAME')),
|
|
2532
|
-
"".concat(this.$db.get('WHERE'))
|
|
2533
|
-
].join(' '))];
|
|
2534
|
-
case 8:
|
|
2535
|
-
data = _e.sent();
|
|
2536
|
-
if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
|
|
2537
|
-
try {
|
|
2538
|
-
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
2539
|
-
val = data_1_1.value;
|
|
2540
|
-
val.action_status = 'update';
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2544
|
-
finally {
|
|
2545
|
-
try {
|
|
2546
|
-
if (data_1_1 && !data_1_1.done && (_d = data_1.return)) _d.call(data_1);
|
|
2547
|
-
}
|
|
2548
|
-
finally { if (e_7) throw e_7.error; }
|
|
2549
|
-
}
|
|
2550
|
-
return [2 /*return*/, data || []];
|
|
2551
|
-
}
|
|
2552
|
-
return [2 /*return*/, __assign(__assign({}, data === null || data === void 0 ? void 0 : data.shift()), { action_status: 'update' }) || null];
|
|
2553
|
-
case 9: return [2 /*return*/, null];
|
|
2554
|
-
case 10:
|
|
2555
|
-
{
|
|
2556
|
-
return [2 /*return*/, null];
|
|
2557
|
-
}
|
|
2558
|
-
_e.label = 11;
|
|
2559
|
-
case 11: return [2 /*return*/];
|
|
1976
|
+
if (result) {
|
|
1977
|
+
const sql = [
|
|
1978
|
+
`${this.$db.get('SELECT')}`,
|
|
1979
|
+
`${this.$db.get('FROM')}`,
|
|
1980
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
1981
|
+
`${this.$constants('WHERE')} id = ${id}`
|
|
1982
|
+
].join(' ');
|
|
1983
|
+
const data = await this._queryStatement(sql);
|
|
1984
|
+
const resultData = { ...data?.shift(), action_status: 'insert' } || null;
|
|
1985
|
+
this.$db.set('RESULT', resultData);
|
|
1986
|
+
return resultData;
|
|
2560
1987
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
return [4 /*yield*/, this._queryStatement(sql)];
|
|
2585
|
-
case 2:
|
|
2586
|
-
data = _a.sent();
|
|
2587
|
-
if ((data === null || data === void 0 ? void 0 : data.length) > 1)
|
|
2588
|
-
return [2 /*return*/, data || []];
|
|
2589
|
-
res = (data === null || data === void 0 ? void 0 : data.shift()) || null;
|
|
2590
|
-
this.$db.set('RESULT', res);
|
|
2591
|
-
return [2 /*return*/, res];
|
|
1988
|
+
return null;
|
|
1989
|
+
}
|
|
1990
|
+
case true: {
|
|
1991
|
+
const result = await this._actionStatement({
|
|
1992
|
+
sql: [
|
|
1993
|
+
`${this.$db.get('UPDATE')}`,
|
|
1994
|
+
`${this.$db.get('WHERE')}`
|
|
1995
|
+
].join(' ')
|
|
1996
|
+
});
|
|
1997
|
+
if (result) {
|
|
1998
|
+
const data = await this._queryStatement([
|
|
1999
|
+
`${this.$db.get('SELECT')}`,
|
|
2000
|
+
`${this.$db.get('FROM')}`,
|
|
2001
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
2002
|
+
`${this.$db.get('WHERE')}`
|
|
2003
|
+
].join(' '));
|
|
2004
|
+
if (data?.length > 1) {
|
|
2005
|
+
for (const val of data) {
|
|
2006
|
+
val.action_status = 'update';
|
|
2007
|
+
}
|
|
2008
|
+
return data || [];
|
|
2009
|
+
}
|
|
2010
|
+
return { ...data?.shift(), action_status: 'update' } || null;
|
|
2592
2011
|
}
|
|
2593
|
-
|
|
2012
|
+
return null;
|
|
2013
|
+
}
|
|
2014
|
+
default: {
|
|
2015
|
+
return null;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
async _update(ignoreWhere = false) {
|
|
2020
|
+
if (!this.$db.get('WHERE') && !ignoreWhere)
|
|
2021
|
+
throw new Error("can't update without where condition");
|
|
2022
|
+
const result = await this._actionStatement({
|
|
2023
|
+
sql: [
|
|
2024
|
+
`${this.$db.get('UPDATE')}`, `${this.$db.get('WHERE')}`
|
|
2025
|
+
].join(' ')
|
|
2594
2026
|
});
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2027
|
+
if (!result)
|
|
2028
|
+
return null;
|
|
2029
|
+
const sql = [
|
|
2030
|
+
`${this.$db.get('SELECT')}`,
|
|
2031
|
+
`${this.$db.get('FROM')}`,
|
|
2032
|
+
`${this.$db.get('TABLE_NAME')}`,
|
|
2033
|
+
`${this.$db.get('WHERE')}`
|
|
2034
|
+
].join(' ');
|
|
2035
|
+
const data = await this._queryStatement(sql);
|
|
2036
|
+
if (data?.length > 1)
|
|
2037
|
+
return data || [];
|
|
2038
|
+
const res = data?.shift() || null;
|
|
2039
|
+
this.$db.set('RESULT', res);
|
|
2040
|
+
return res;
|
|
2041
|
+
}
|
|
2042
|
+
_hiddenColumn(data) {
|
|
2043
|
+
const hidden = this.$db.get('HIDDEN');
|
|
2044
|
+
if (Object.keys(data)?.length) {
|
|
2045
|
+
hidden.forEach((column) => {
|
|
2046
|
+
data.forEach((objColumn) => {
|
|
2602
2047
|
delete objColumn[column];
|
|
2603
2048
|
});
|
|
2604
2049
|
});
|
|
2605
2050
|
}
|
|
2606
2051
|
return data;
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
var _b = __read(_a, 2), column = _b[0], value = _b[1];
|
|
2612
|
-
return "".concat(column, " = ").concat(value == null || value === 'NULL'
|
|
2052
|
+
}
|
|
2053
|
+
_queryUpdate(data) {
|
|
2054
|
+
const values = Object.entries(data).map(([column, value]) => {
|
|
2055
|
+
return `${column} = ${value == null || value === 'NULL'
|
|
2613
2056
|
? 'NULL'
|
|
2614
|
-
:
|
|
2057
|
+
: `'${this.$utils.covertBooleanToNumber(value)}'`}`;
|
|
2615
2058
|
});
|
|
2616
|
-
return
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
return "".concat(value == null || value === 'NULL'
|
|
2059
|
+
return `${this.$constants('SET')} ${values}`;
|
|
2060
|
+
}
|
|
2061
|
+
_queryInsert(data) {
|
|
2062
|
+
const columns = Object.keys(data).map((column) => `\`${column}\``);
|
|
2063
|
+
const values = Object.values(data).map((value) => {
|
|
2064
|
+
return `${value == null || value === 'NULL'
|
|
2623
2065
|
? 'NULL'
|
|
2624
|
-
:
|
|
2066
|
+
: `'${this.$utils.covertBooleanToNumber(value)}'`}`;
|
|
2625
2067
|
});
|
|
2626
|
-
return
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
values.push("(".concat(vals.join(','), ")"));
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
2645
|
-
finally {
|
|
2646
|
-
try {
|
|
2647
|
-
if (data_2_1 && !data_2_1.done && (_a = data_2.return)) _a.call(data_2);
|
|
2648
|
-
}
|
|
2649
|
-
finally { if (e_8) throw e_8.error; }
|
|
2068
|
+
return [
|
|
2069
|
+
`(${columns})`,
|
|
2070
|
+
`${this.$constants('VALUES')}`,
|
|
2071
|
+
`(${values})`
|
|
2072
|
+
].join(' ');
|
|
2073
|
+
}
|
|
2074
|
+
_queryInsertMultiple(data) {
|
|
2075
|
+
let values = [];
|
|
2076
|
+
for (let objects of data) {
|
|
2077
|
+
const vals = Object.values(objects).map((value) => {
|
|
2078
|
+
return `${value == null || value === 'NULL'
|
|
2079
|
+
? 'NULL'
|
|
2080
|
+
: `'${this.$utils.covertBooleanToNumber(value)}'`}`;
|
|
2081
|
+
});
|
|
2082
|
+
values.push(`(${vals.join(',')})`);
|
|
2650
2083
|
}
|
|
2651
|
-
|
|
2652
|
-
return
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2084
|
+
const columns = Object.keys([...data]?.shift()).map((column) => `\`${column}\``);
|
|
2085
|
+
return [
|
|
2086
|
+
`(${columns})`,
|
|
2087
|
+
`${this.$constants('VALUES')}`,
|
|
2088
|
+
`${values.join(',')}`
|
|
2089
|
+
].join(' ');
|
|
2090
|
+
}
|
|
2091
|
+
_valueAndOperator(value, operator, useDefault = false) {
|
|
2656
2092
|
if (useDefault)
|
|
2657
2093
|
return [operator, '='];
|
|
2658
2094
|
if (operator == null)
|
|
2659
2095
|
throw new Error('bad arguments');
|
|
2660
|
-
if (operator.toUpperCase() === this.$constants('LIKE'))
|
|
2096
|
+
if (operator.toUpperCase() === this.$constants('LIKE')) {
|
|
2661
2097
|
operator = operator.toUpperCase();
|
|
2098
|
+
}
|
|
2662
2099
|
return [value, operator];
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2100
|
+
}
|
|
2101
|
+
_valueTrueFalse(value) {
|
|
2665
2102
|
if (value === true)
|
|
2666
2103
|
return 1;
|
|
2667
2104
|
if (value === false)
|
|
2668
2105
|
return 0;
|
|
2669
2106
|
return value;
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
|
|
2107
|
+
}
|
|
2108
|
+
_buildQuery() {
|
|
2109
|
+
let sql = [];
|
|
2673
2110
|
while (true) {
|
|
2674
2111
|
if (this.$db.get('INSERT')) {
|
|
2675
|
-
|
|
2676
|
-
this.$db.get('INSERT')
|
|
2112
|
+
sql = [
|
|
2113
|
+
this.$db.get('INSERT')
|
|
2677
2114
|
];
|
|
2678
2115
|
break;
|
|
2679
2116
|
}
|
|
2680
2117
|
if (this.$db.get('UPDATE')) {
|
|
2681
|
-
|
|
2118
|
+
sql = [
|
|
2682
2119
|
this.$db.get('UPDATE'),
|
|
2683
|
-
this.$db.get('WHERE')
|
|
2120
|
+
this.$db.get('WHERE')
|
|
2684
2121
|
];
|
|
2685
2122
|
break;
|
|
2686
2123
|
}
|
|
2687
2124
|
if (this.$db.get('DELETE')) {
|
|
2688
|
-
|
|
2125
|
+
sql = [
|
|
2689
2126
|
this.$db.get('DELETE')
|
|
2690
2127
|
];
|
|
2691
2128
|
break;
|
|
2692
2129
|
}
|
|
2693
|
-
|
|
2130
|
+
sql = [
|
|
2694
2131
|
this.$db.get('SELECT'),
|
|
2695
2132
|
this.$db.get('FROM'),
|
|
2696
2133
|
this.$db.get('TABLE_NAME'),
|
|
@@ -2704,46 +2141,33 @@ var Database = /** @class */ (function (_super) {
|
|
|
2704
2141
|
];
|
|
2705
2142
|
break;
|
|
2706
2143
|
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
Database.prototype._setupLogger = function () {
|
|
2712
|
-
var logger = [];
|
|
2144
|
+
return sql.filter(s => s !== '' || s == null).join(' ');
|
|
2145
|
+
}
|
|
2146
|
+
_setupLogger() {
|
|
2147
|
+
let logger = [];
|
|
2713
2148
|
return {
|
|
2714
|
-
get:
|
|
2715
|
-
set:
|
|
2716
|
-
logger =
|
|
2149
|
+
get: () => logger,
|
|
2150
|
+
set: (data) => {
|
|
2151
|
+
logger = [...logger, data];
|
|
2717
2152
|
return;
|
|
2718
2153
|
},
|
|
2719
|
-
check:
|
|
2154
|
+
check: (data) => logger.indexOf(data) != -1
|
|
2720
2155
|
};
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2156
|
+
}
|
|
2157
|
+
_initialConnection() {
|
|
2723
2158
|
this.$pool = this._setupPool();
|
|
2724
2159
|
this.$logger = this._setupLogger();
|
|
2725
2160
|
this.$utils = utils_1.default;
|
|
2726
|
-
this.$constants =
|
|
2727
|
-
var e_9, _a;
|
|
2161
|
+
this.$constants = (name) => {
|
|
2728
2162
|
if (!name)
|
|
2729
2163
|
return constants_1.default;
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
if (index === name)
|
|
2734
|
-
return constant;
|
|
2164
|
+
for (const [index, constant] of Object?.entries(constants_1.default)) {
|
|
2165
|
+
if (index === name.toLocaleUpperCase()) {
|
|
2166
|
+
return constant;
|
|
2735
2167
|
}
|
|
2736
2168
|
}
|
|
2737
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
2738
|
-
finally {
|
|
2739
|
-
try {
|
|
2740
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2741
|
-
}
|
|
2742
|
-
finally { if (e_9) throw e_9.error; }
|
|
2743
|
-
}
|
|
2744
2169
|
};
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
}(AbstractDatabase_1.default));
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2748
2172
|
exports.Database = Database;
|
|
2749
2173
|
exports.default = Database;
|