oak-db 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -36
- package/lib/MySQL/connector.d.ts +15 -15
- package/lib/MySQL/connector.js +124 -124
- package/lib/MySQL/store.d.ts +29 -29
- package/lib/MySQL/store.js +377 -376
- package/lib/MySQL/translator.d.ts +104 -104
- package/lib/MySQL/translator.js +732 -732
- package/lib/MySQL/types/Configuration.d.ts +11 -11
- package/lib/MySQL/types/Configuration.js +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -4
- package/lib/sqlTranslator.d.ts +51 -51
- package/lib/sqlTranslator.js +755 -755
- package/lib/types/Translator.js +1 -1
- package/package.json +36 -36
package/lib/MySQL/store.js
CHANGED
|
@@ -1,376 +1,377 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MysqlStore = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
|
6
|
-
var connector_1 = require("./connector");
|
|
7
|
-
var translator_1 = require("./translator");
|
|
8
|
-
var lodash_1 = require("lodash");
|
|
9
|
-
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
10
|
-
var relation_1 = require("oak-domain/lib/store/relation");
|
|
11
|
-
function convertGeoTextToObject(geoText) {
|
|
12
|
-
if (geoText.startsWith('POINT')) {
|
|
13
|
-
var coord = geoText.match((/(\d|\.)+(?=\)|\s)/g));
|
|
14
|
-
return {
|
|
15
|
-
type: 'Point',
|
|
16
|
-
coordinates: coord.map(function (ele) { return parseFloat(ele); }),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
throw new Error('only support Point now');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
var MysqlStore = /** @class */ (function (_super) {
|
|
24
|
-
tslib_1.__extends(MysqlStore, _super);
|
|
25
|
-
function MysqlStore(storageSchema, configuration) {
|
|
26
|
-
var _this = _super.call(this, storageSchema) || this;
|
|
27
|
-
_this.connector = new connector_1.MySqlConnector(configuration);
|
|
28
|
-
_this.translator = new translator_1.MySqlTranslator(storageSchema);
|
|
29
|
-
return _this;
|
|
30
|
-
}
|
|
31
|
-
MysqlStore.prototype.selectAbjointRow = function (entity, selection, context, option) {
|
|
32
|
-
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
|
33
|
-
};
|
|
34
|
-
MysqlStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
|
35
|
-
throw new Error('MySQL store不支持同步更新数据,不应该跑到这儿');
|
|
36
|
-
};
|
|
37
|
-
MysqlStore.prototype.supportManyToOneJoin = function () {
|
|
38
|
-
return true;
|
|
39
|
-
};
|
|
40
|
-
MysqlStore.prototype.supportMultipleCreate = function () {
|
|
41
|
-
return true;
|
|
42
|
-
};
|
|
43
|
-
MysqlStore.prototype.formResult = function (entity, result) {
|
|
44
|
-
var schema = this.getSchema();
|
|
45
|
-
function resolveAttribute(entity2, r, attr, value) {
|
|
46
|
-
var _a;
|
|
47
|
-
var _b = schema[entity2], attributes = _b.attributes, view = _b.view;
|
|
48
|
-
if (!view) {
|
|
49
|
-
var i = attr.indexOf(".");
|
|
50
|
-
if (i !== -1) {
|
|
51
|
-
var attrHead = attr.slice(0, i);
|
|
52
|
-
var attrTail = attr.slice(i + 1);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
(0,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
case '
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
case
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
case
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
case
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
case
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
_d.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MysqlStore = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
|
6
|
+
var connector_1 = require("./connector");
|
|
7
|
+
var translator_1 = require("./translator");
|
|
8
|
+
var lodash_1 = require("lodash");
|
|
9
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
10
|
+
var relation_1 = require("oak-domain/lib/store/relation");
|
|
11
|
+
function convertGeoTextToObject(geoText) {
|
|
12
|
+
if (geoText.startsWith('POINT')) {
|
|
13
|
+
var coord = geoText.match((/(\d|\.)+(?=\)|\s)/g));
|
|
14
|
+
return {
|
|
15
|
+
type: 'Point',
|
|
16
|
+
coordinates: coord.map(function (ele) { return parseFloat(ele); }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new Error('only support Point now');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
var MysqlStore = /** @class */ (function (_super) {
|
|
24
|
+
tslib_1.__extends(MysqlStore, _super);
|
|
25
|
+
function MysqlStore(storageSchema, configuration) {
|
|
26
|
+
var _this = _super.call(this, storageSchema) || this;
|
|
27
|
+
_this.connector = new connector_1.MySqlConnector(configuration);
|
|
28
|
+
_this.translator = new translator_1.MySqlTranslator(storageSchema);
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
MysqlStore.prototype.selectAbjointRow = function (entity, selection, context, option) {
|
|
32
|
+
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
|
33
|
+
};
|
|
34
|
+
MysqlStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
|
35
|
+
throw new Error('MySQL store不支持同步更新数据,不应该跑到这儿');
|
|
36
|
+
};
|
|
37
|
+
MysqlStore.prototype.supportManyToOneJoin = function () {
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
MysqlStore.prototype.supportMultipleCreate = function () {
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
MysqlStore.prototype.formResult = function (entity, result) {
|
|
44
|
+
var schema = this.getSchema();
|
|
45
|
+
function resolveAttribute(entity2, r, attr, value) {
|
|
46
|
+
var _a;
|
|
47
|
+
var _b = schema[entity2], attributes = _b.attributes, view = _b.view;
|
|
48
|
+
if (!view) {
|
|
49
|
+
var i = attr.indexOf(".");
|
|
50
|
+
if (i !== -1) {
|
|
51
|
+
var attrHead = attr.slice(0, i);
|
|
52
|
+
var attrTail = attr.slice(i + 1);
|
|
53
|
+
if (!r[attrHead]) {
|
|
54
|
+
r[attrHead] = {};
|
|
55
|
+
}
|
|
56
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
|
|
57
|
+
if (rel === 2) {
|
|
58
|
+
resolveAttribute(attrHead, r[attrHead], attrTail, value);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
(0, assert_1.default)(typeof rel === 'string');
|
|
62
|
+
resolveAttribute(rel, r[attrHead], attrTail, value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (attributes[attr]) {
|
|
66
|
+
var type = attributes[attr].type;
|
|
67
|
+
switch (type) {
|
|
68
|
+
case 'date':
|
|
69
|
+
case 'time': {
|
|
70
|
+
if (value instanceof Date) {
|
|
71
|
+
r[attr] = value.valueOf();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
r[attr] = value;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case 'geometry': {
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
r[attr] = convertGeoTextToObject(value);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
r[attr] = value;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'object':
|
|
88
|
+
case 'array': {
|
|
89
|
+
if (typeof value === 'string') {
|
|
90
|
+
r[attr] = JSON.parse(value.replace(/[\r]/g, '\\r').replace(/[\n]/g, '\\n'));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
r[attr] = value;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'function': {
|
|
98
|
+
if (typeof value === 'string') {
|
|
99
|
+
// 函数的执行环境需要的参数只有创建函数者知悉,只能由上层再创建Function
|
|
100
|
+
r[attr] = "return ".concat(Buffer.from(value, 'base64').toString());
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
r[attr] = value;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case 'bool':
|
|
108
|
+
case 'boolean': {
|
|
109
|
+
if (value === 0) {
|
|
110
|
+
r[attr] = false;
|
|
111
|
+
}
|
|
112
|
+
else if (value === 1) {
|
|
113
|
+
r[attr] = true;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
r[attr] = value;
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
121
|
+
r[attr] = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
r[attr] = value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
(0, lodash_1.assign)(r, (_a = {},
|
|
131
|
+
_a[attr] = value,
|
|
132
|
+
_a));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function removeNullObjects(r, e) {
|
|
136
|
+
(0, assert_1.default)(r.id && typeof r.id === 'string', "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\u53D1\u73B0id\u4E3A\u975E\u6CD5\u503C").concat(r.id, ",rowId\u662F").concat(r.id));
|
|
137
|
+
for (var attr in r) {
|
|
138
|
+
var rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
|
139
|
+
if (rel === 2) {
|
|
140
|
+
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
141
|
+
(0, assert_1.default)(schema[e].toModi || r.entity !== attr || r.entityId === r[attr].id, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0entityId\u4E0E\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176entityId\u503C\u4E3A").concat(r.entityId, "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E3A").concat(r[attr].id));
|
|
142
|
+
if (r[attr].id === null) {
|
|
143
|
+
(0, assert_1.default)(schema[e].toModi || r.entity !== attr);
|
|
144
|
+
delete r[attr];
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
(0, assert_1.default)(r.entity === attr, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0entity\u503C\u4E0E\u8FDE\u63A5\u7684\u5916\u952E\u5BF9\u8C61\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176entity\u503C\u4E3A").concat(r.entity, "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u4E3A").concat(attr));
|
|
148
|
+
removeNullObjects(r[attr], attr);
|
|
149
|
+
}
|
|
150
|
+
else if (typeof rel === 'string') {
|
|
151
|
+
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
152
|
+
(0, assert_1.default)(schema[e].toModi || r["".concat(attr, "Id")] === r[attr].id, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0\u5176\u5916\u952E\u4E0E\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176").concat(attr, "Id\u503C\u4E3A").concat(r["".concat(attr, "Id")], "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E3A").concat(r[attr].id));
|
|
153
|
+
if (r[attr].id === null) {
|
|
154
|
+
(0, assert_1.default)(schema[e].toModi || r["".concat(attr, "Id")] === null);
|
|
155
|
+
delete r[attr];
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
removeNullObjects(r[attr], rel);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function formSingleRow(r) {
|
|
163
|
+
var result2 = {};
|
|
164
|
+
for (var attr in r) {
|
|
165
|
+
var value = r[attr];
|
|
166
|
+
resolveAttribute(entity, result2, attr, value);
|
|
167
|
+
}
|
|
168
|
+
removeNullObjects(result2, entity);
|
|
169
|
+
return result2;
|
|
170
|
+
}
|
|
171
|
+
if (result instanceof Array) {
|
|
172
|
+
return result.map(function (r) { return formSingleRow(r); });
|
|
173
|
+
}
|
|
174
|
+
return formSingleRow(result);
|
|
175
|
+
};
|
|
176
|
+
MysqlStore.prototype.selectAbjointRowAsync = function (entity, selection, context, option) {
|
|
177
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
178
|
+
var sql, result;
|
|
179
|
+
return tslib_1.__generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
sql = this.translator.translateSelect(entity, selection, option);
|
|
183
|
+
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
|
184
|
+
case 1:
|
|
185
|
+
result = _a.sent();
|
|
186
|
+
return [2 /*return*/, this.formResult(entity, result)];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
MysqlStore.prototype.updateAbjointRowAsync = function (entity, operation, context, option) {
|
|
192
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var _a, translator, connector, action, txn, _b, data, sql, sql, sql;
|
|
194
|
+
return tslib_1.__generator(this, function (_c) {
|
|
195
|
+
switch (_c.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
_a = this, translator = _a.translator, connector = _a.connector;
|
|
198
|
+
action = operation.action;
|
|
199
|
+
txn = context.getCurrentTxnId();
|
|
200
|
+
_b = action;
|
|
201
|
+
switch (_b) {
|
|
202
|
+
case 'create': return [3 /*break*/, 1];
|
|
203
|
+
case 'remove': return [3 /*break*/, 3];
|
|
204
|
+
}
|
|
205
|
+
return [3 /*break*/, 5];
|
|
206
|
+
case 1:
|
|
207
|
+
data = operation.data;
|
|
208
|
+
sql = translator.translateInsert(entity, data instanceof Array ? data : [data]);
|
|
209
|
+
return [4 /*yield*/, connector.exec(sql, txn)];
|
|
210
|
+
case 2:
|
|
211
|
+
_c.sent();
|
|
212
|
+
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
|
213
|
+
context.opRecords.push({
|
|
214
|
+
a: 'c',
|
|
215
|
+
d: data,
|
|
216
|
+
e: entity,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return [2 /*return*/, data instanceof Array ? data.length : 1];
|
|
220
|
+
case 3:
|
|
221
|
+
sql = translator.translateRemove(entity, operation, option);
|
|
222
|
+
return [4 /*yield*/, connector.exec(sql, txn)];
|
|
223
|
+
case 4:
|
|
224
|
+
_c.sent();
|
|
225
|
+
// todo 这里对sorter和indexfrom/count的支持不完整
|
|
226
|
+
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
|
227
|
+
context.opRecords.push({
|
|
228
|
+
a: 'r',
|
|
229
|
+
e: entity,
|
|
230
|
+
f: operation.filter,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return [2 /*return*/, 1];
|
|
234
|
+
case 5:
|
|
235
|
+
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action));
|
|
236
|
+
sql = translator.translateUpdate(entity, operation, option);
|
|
237
|
+
return [4 /*yield*/, connector.exec(sql, txn)];
|
|
238
|
+
case 6:
|
|
239
|
+
_c.sent();
|
|
240
|
+
// todo 这里对sorter和indexfrom/count的支持不完整
|
|
241
|
+
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
|
242
|
+
context.opRecords.push({
|
|
243
|
+
a: 'u',
|
|
244
|
+
e: entity,
|
|
245
|
+
d: operation.data,
|
|
246
|
+
f: operation.filter,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return [2 /*return*/, 1];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
MysqlStore.prototype.operate = function (entity, operation, context, option) {
|
|
255
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var action;
|
|
257
|
+
return tslib_1.__generator(this, function (_a) {
|
|
258
|
+
switch (_a.label) {
|
|
259
|
+
case 0:
|
|
260
|
+
action = operation.action;
|
|
261
|
+
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action), '现在不支持使用select operation');
|
|
262
|
+
return [4 /*yield*/, this.cascadeUpdateAsync(entity, operation, context, option)];
|
|
263
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
MysqlStore.prototype.select = function (entity, selection, context, option) {
|
|
269
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var result;
|
|
271
|
+
return tslib_1.__generator(this, function (_a) {
|
|
272
|
+
switch (_a.label) {
|
|
273
|
+
case 0: return [4 /*yield*/, this.cascadeSelectAsync(entity, selection, context, option)];
|
|
274
|
+
case 1:
|
|
275
|
+
result = _a.sent();
|
|
276
|
+
return [2 /*return*/, result];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
MysqlStore.prototype.count = function (entity, selection, context, option) {
|
|
282
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
283
|
+
var sql, result;
|
|
284
|
+
return tslib_1.__generator(this, function (_a) {
|
|
285
|
+
switch (_a.label) {
|
|
286
|
+
case 0:
|
|
287
|
+
sql = this.translator.translateCount(entity, selection, option);
|
|
288
|
+
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
|
289
|
+
case 1:
|
|
290
|
+
result = _a.sent();
|
|
291
|
+
return [2 /*return*/, result[0].cnt];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
MysqlStore.prototype.begin = function (option) {
|
|
297
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
298
|
+
var txn;
|
|
299
|
+
return tslib_1.__generator(this, function (_a) {
|
|
300
|
+
switch (_a.label) {
|
|
301
|
+
case 0: return [4 /*yield*/, this.connector.startTransaction(option)];
|
|
302
|
+
case 1:
|
|
303
|
+
txn = _a.sent();
|
|
304
|
+
return [2 /*return*/, txn];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
MysqlStore.prototype.commit = function (txnId) {
|
|
310
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
311
|
+
return tslib_1.__generator(this, function (_a) {
|
|
312
|
+
switch (_a.label) {
|
|
313
|
+
case 0: return [4 /*yield*/, this.connector.commitTransaction(txnId)];
|
|
314
|
+
case 1:
|
|
315
|
+
_a.sent();
|
|
316
|
+
return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
MysqlStore.prototype.rollback = function (txnId) {
|
|
322
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
323
|
+
return tslib_1.__generator(this, function (_a) {
|
|
324
|
+
switch (_a.label) {
|
|
325
|
+
case 0: return [4 /*yield*/, this.connector.rollbackTransaction(txnId)];
|
|
326
|
+
case 1:
|
|
327
|
+
_a.sent();
|
|
328
|
+
return [2 /*return*/];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
MysqlStore.prototype.connect = function () {
|
|
334
|
+
this.connector.connect();
|
|
335
|
+
};
|
|
336
|
+
MysqlStore.prototype.disconnect = function () {
|
|
337
|
+
this.connector.disconnect();
|
|
338
|
+
};
|
|
339
|
+
MysqlStore.prototype.initialize = function (dropIfExists) {
|
|
340
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
341
|
+
var schema, _a, _b, _i, entity, sqls, _c, sqls_1, sql;
|
|
342
|
+
return tslib_1.__generator(this, function (_d) {
|
|
343
|
+
switch (_d.label) {
|
|
344
|
+
case 0:
|
|
345
|
+
schema = this.getSchema();
|
|
346
|
+
_a = [];
|
|
347
|
+
for (_b in schema)
|
|
348
|
+
_a.push(_b);
|
|
349
|
+
_i = 0;
|
|
350
|
+
_d.label = 1;
|
|
351
|
+
case 1:
|
|
352
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
353
|
+
entity = _a[_i];
|
|
354
|
+
sqls = this.translator.translateCreateEntity(entity, { replace: dropIfExists });
|
|
355
|
+
_c = 0, sqls_1 = sqls;
|
|
356
|
+
_d.label = 2;
|
|
357
|
+
case 2:
|
|
358
|
+
if (!(_c < sqls_1.length)) return [3 /*break*/, 5];
|
|
359
|
+
sql = sqls_1[_c];
|
|
360
|
+
return [4 /*yield*/, this.connector.exec(sql)];
|
|
361
|
+
case 3:
|
|
362
|
+
_d.sent();
|
|
363
|
+
_d.label = 4;
|
|
364
|
+
case 4:
|
|
365
|
+
_c++;
|
|
366
|
+
return [3 /*break*/, 2];
|
|
367
|
+
case 5:
|
|
368
|
+
_i++;
|
|
369
|
+
return [3 /*break*/, 1];
|
|
370
|
+
case 6: return [2 /*return*/];
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
return MysqlStore;
|
|
376
|
+
}(CascadeStore_1.CascadeStore));
|
|
377
|
+
exports.MysqlStore = MysqlStore;
|