oak-db 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/MySQL/connector.js +5 -43
- package/lib/MySQL/store.js +21 -74
- package/lib/MySQL/translator.js +3 -20
- package/lib/index.js +2 -15
- package/lib/sqlTranslator.js +2 -4
- package/package.json +37 -33
- package/.mocharc.json +0 -5
- package/script/makeTestDomain.ts +0 -8
- package/src/MySQL/connector.ts +0 -137
- package/src/MySQL/store.ts +0 -276
- package/src/MySQL/translator.ts +0 -798
- package/src/MySQL/types/Configuration.ts +0 -12
- package/src/sqlTranslator.ts +0 -920
- package/src/types/Translator.ts +0 -0
- package/test/entities/House.ts +0 -24
- package/test/testMySQLStore.ts +0 -771
- package/test/testSqlTranslator.ts +0 -58
- package/tsconfig.json +0 -31
package/lib/MySQL/connector.js
CHANGED
|
@@ -1,48 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.MySqlConnector = void 0;
|
|
43
|
-
var
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var mysql2_1 = tslib_1.__importDefault(require("mysql2"));
|
|
44
6
|
var uuid_1 = require("uuid");
|
|
45
|
-
var assert_1 = __importDefault(require("assert"));
|
|
7
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
46
8
|
var MySqlConnector = /** @class */ (function () {
|
|
47
9
|
function MySqlConnector(configuration) {
|
|
48
10
|
this.configuration = configuration;
|
|
@@ -93,10 +55,10 @@ var MySqlConnector = /** @class */ (function () {
|
|
|
93
55
|
});
|
|
94
56
|
};
|
|
95
57
|
MySqlConnector.prototype.exec = function (sql, txn) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
97
59
|
var connection_1;
|
|
98
60
|
var _this = this;
|
|
99
|
-
return __generator(this, function (_a) {
|
|
61
|
+
return tslib_1.__generator(this, function (_a) {
|
|
100
62
|
if (process.env.NODE_ENV === 'development') {
|
|
101
63
|
console.log(sql);
|
|
102
64
|
}
|
package/lib/MySQL/store.js
CHANGED
|
@@ -1,65 +1,12 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
3
|
exports.MysqlStore = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
58
5
|
var CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
|
59
6
|
var connector_1 = require("./connector");
|
|
60
7
|
var translator_1 = require("./translator");
|
|
61
8
|
var lodash_1 = require("lodash");
|
|
62
|
-
var assert_1 = __importDefault(require("assert"));
|
|
9
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
63
10
|
var relation_1 = require("oak-domain/lib/store/relation");
|
|
64
11
|
function convertGeoTextToObject(geoText) {
|
|
65
12
|
if (geoText.startsWith('POINT')) {
|
|
@@ -74,7 +21,7 @@ function convertGeoTextToObject(geoText) {
|
|
|
74
21
|
}
|
|
75
22
|
}
|
|
76
23
|
var MysqlStore = /** @class */ (function (_super) {
|
|
77
|
-
__extends(MysqlStore, _super);
|
|
24
|
+
tslib_1.__extends(MysqlStore, _super);
|
|
78
25
|
function MysqlStore(storageSchema, configuration) {
|
|
79
26
|
var _this = _super.call(this, storageSchema) || this;
|
|
80
27
|
_this.connector = new connector_1.MySqlConnector(configuration);
|
|
@@ -207,9 +154,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
207
154
|
return formSingleRow(result);
|
|
208
155
|
};
|
|
209
156
|
MysqlStore.prototype.selectAbjointRow = function (entity, selection, context, option) {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
211
158
|
var sql, result;
|
|
212
|
-
return __generator(this, function (_a) {
|
|
159
|
+
return tslib_1.__generator(this, function (_a) {
|
|
213
160
|
switch (_a.label) {
|
|
214
161
|
case 0:
|
|
215
162
|
sql = this.translator.translateSelect(entity, selection, option);
|
|
@@ -222,9 +169,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
222
169
|
});
|
|
223
170
|
};
|
|
224
171
|
MysqlStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
|
225
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
226
173
|
var _a, translator, connector, action, txn, _b, data, sql, sql, sql;
|
|
227
|
-
return __generator(this, function (_c) {
|
|
174
|
+
return tslib_1.__generator(this, function (_c) {
|
|
228
175
|
switch (_c.label) {
|
|
229
176
|
case 0:
|
|
230
177
|
_a = this, translator = _a.translator, connector = _a.connector;
|
|
@@ -285,9 +232,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
285
232
|
});
|
|
286
233
|
};
|
|
287
234
|
MysqlStore.prototype.operate = function (entity, operation, context, params) {
|
|
288
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
289
236
|
var action;
|
|
290
|
-
return __generator(this, function (_a) {
|
|
237
|
+
return tslib_1.__generator(this, function (_a) {
|
|
291
238
|
switch (_a.label) {
|
|
292
239
|
case 0:
|
|
293
240
|
action = operation.action;
|
|
@@ -299,9 +246,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
299
246
|
});
|
|
300
247
|
};
|
|
301
248
|
MysqlStore.prototype.select = function (entity, selection, context, option) {
|
|
302
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
249
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
303
250
|
var result;
|
|
304
|
-
return __generator(this, function (_a) {
|
|
251
|
+
return tslib_1.__generator(this, function (_a) {
|
|
305
252
|
switch (_a.label) {
|
|
306
253
|
case 0: return [4 /*yield*/, this.cascadeSelect(entity, selection, context, option)];
|
|
307
254
|
case 1:
|
|
@@ -314,9 +261,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
314
261
|
});
|
|
315
262
|
};
|
|
316
263
|
MysqlStore.prototype.count = function (entity, selection, context, option) {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
318
265
|
var sql, result;
|
|
319
|
-
return __generator(this, function (_a) {
|
|
266
|
+
return tslib_1.__generator(this, function (_a) {
|
|
320
267
|
switch (_a.label) {
|
|
321
268
|
case 0:
|
|
322
269
|
sql = this.translator.translateCount(entity, selection, option);
|
|
@@ -329,9 +276,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
329
276
|
});
|
|
330
277
|
};
|
|
331
278
|
MysqlStore.prototype.begin = function (option) {
|
|
332
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
333
280
|
var txn;
|
|
334
|
-
return __generator(this, function (_a) {
|
|
281
|
+
return tslib_1.__generator(this, function (_a) {
|
|
335
282
|
switch (_a.label) {
|
|
336
283
|
case 0: return [4 /*yield*/, this.connector.startTransaction(option)];
|
|
337
284
|
case 1:
|
|
@@ -342,8 +289,8 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
342
289
|
});
|
|
343
290
|
};
|
|
344
291
|
MysqlStore.prototype.commit = function (txnId) {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
return __generator(this, function (_a) {
|
|
292
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
293
|
+
return tslib_1.__generator(this, function (_a) {
|
|
347
294
|
switch (_a.label) {
|
|
348
295
|
case 0: return [4 /*yield*/, this.connector.commitTransaction(txnId)];
|
|
349
296
|
case 1:
|
|
@@ -354,8 +301,8 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
354
301
|
});
|
|
355
302
|
};
|
|
356
303
|
MysqlStore.prototype.rollback = function (txnId) {
|
|
357
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
-
return __generator(this, function (_a) {
|
|
304
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
305
|
+
return tslib_1.__generator(this, function (_a) {
|
|
359
306
|
switch (_a.label) {
|
|
360
307
|
case 0: return [4 /*yield*/, this.connector.rollbackTransaction(txnId)];
|
|
361
308
|
case 1:
|
|
@@ -372,9 +319,9 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
372
319
|
this.connector.disconnect();
|
|
373
320
|
};
|
|
374
321
|
MysqlStore.prototype.initialize = function (dropIfExists) {
|
|
375
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
322
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
376
323
|
var schema, _a, _b, _i, entity, sqls, _c, sqls_1, sql;
|
|
377
|
-
return __generator(this, function (_d) {
|
|
324
|
+
return tslib_1.__generator(this, function (_d) {
|
|
378
325
|
switch (_d.label) {
|
|
379
326
|
case 0:
|
|
380
327
|
schema = this.getSchema();
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
3
|
exports.MySqlTranslator = void 0;
|
|
22
|
-
var
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
23
6
|
var util_1 = require("util");
|
|
24
7
|
var lodash_1 = require("lodash");
|
|
25
8
|
var luxon_1 = require("luxon");
|
|
@@ -89,7 +72,7 @@ function transformGeoData(data) {
|
|
|
89
72
|
}
|
|
90
73
|
}
|
|
91
74
|
var MySqlTranslator = /** @class */ (function (_super) {
|
|
92
|
-
__extends(MySqlTranslator, _super);
|
|
75
|
+
tslib_1.__extends(MySqlTranslator, _super);
|
|
93
76
|
function MySqlTranslator(schema) {
|
|
94
77
|
var _this = _super.call(this, schema) || this;
|
|
95
78
|
_this.maxAliasLength = 63;
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./MySQL/store"), exports);
|
package/lib/sqlTranslator.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.SqlTranslator = void 0;
|
|
7
|
-
var
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
6
|
var lodash_1 = require("lodash");
|
|
9
7
|
var luxon_1 = require("luxon");
|
|
10
8
|
var types_1 = require("oak-domain/lib/types");
|
package/package.json
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
2
|
+
"name": "oak-db",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "oak-db",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "XuChang"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"lib/**/*"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "mocha",
|
|
14
|
+
"make:test:domain": "ts-node script/makeTestDomain.ts",
|
|
15
|
+
"build": "tsc"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"lodash": "^4.17.21",
|
|
19
|
+
"luxon": "^2.4.0",
|
|
20
|
+
"mysql": "^2.18.1",
|
|
21
|
+
"mysql2": "^2.3.3",
|
|
22
|
+
"oak-domain": "^1.0.4",
|
|
23
|
+
"uuid": "^8.3.2"
|
|
24
|
+
},
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/lodash": "^4.14.182",
|
|
28
|
+
"@types/luxon": "^2.3.2",
|
|
29
|
+
"@types/mocha": "^9.1.1",
|
|
30
|
+
"@types/node": "^17.0.42",
|
|
31
|
+
"@types/uuid": "^8.3.4",
|
|
32
|
+
"mocha": "^10.0.0",
|
|
33
|
+
"oak-general-business": "^1.0.2",
|
|
34
|
+
"ts-node": "~10.9.1",
|
|
35
|
+
"tslib": "^2.4.0",
|
|
36
|
+
"typescript": "~4.7.4"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/.mocharc.json
DELETED
package/script/makeTestDomain.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSchema,
|
|
3
|
-
analyzeEntities,
|
|
4
|
-
} from 'oak-domain/src/compiler/schemalBuilder';
|
|
5
|
-
|
|
6
|
-
analyzeEntities(`${process.cwd()}/node_modules/oak-general-business/src/entities`);
|
|
7
|
-
analyzeEntities(`${process.cwd()}/test/entities`);
|
|
8
|
-
buildSchema(`${process.cwd()}/test/test-app-domain`);
|
package/src/MySQL/connector.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import mysql from 'mysql2';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
import { TxnOption } from 'oak-domain/lib/types';
|
|
4
|
-
import { MySQLConfiguration } from './types/Configuration';
|
|
5
|
-
import assert from 'assert';
|
|
6
|
-
|
|
7
|
-
export class MySqlConnector {
|
|
8
|
-
pool?: mysql.Pool;
|
|
9
|
-
configuration: MySQLConfiguration;
|
|
10
|
-
txnDict: Record<string, mysql.PoolConnection>;
|
|
11
|
-
|
|
12
|
-
constructor(configuration: MySQLConfiguration) {
|
|
13
|
-
this.configuration = configuration;
|
|
14
|
-
this.txnDict = {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
connect() {
|
|
18
|
-
this.pool = mysql.createPool(this.configuration);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
disconnect() {
|
|
22
|
-
this.pool!.end();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
startTransaction(option?: TxnOption): Promise<string> {
|
|
26
|
-
return new Promise(
|
|
27
|
-
(resolve, reject) => {
|
|
28
|
-
this.pool!.getConnection((err, connection) => {
|
|
29
|
-
if (err) {
|
|
30
|
-
return reject(err);
|
|
31
|
-
}
|
|
32
|
-
const { isolationLevel } = option || {};
|
|
33
|
-
const startTxn = () => {
|
|
34
|
-
let sql = 'START TRANSACTION;';
|
|
35
|
-
connection.query(sql, (err2: Error) => {
|
|
36
|
-
if (err2) {
|
|
37
|
-
connection.release();
|
|
38
|
-
return reject(err2);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const id = v4();
|
|
42
|
-
Object.assign(this.txnDict, {
|
|
43
|
-
[id]: connection,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
resolve(id);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (isolationLevel) {
|
|
50
|
-
connection.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel};`, (err2: Error) => {
|
|
51
|
-
if (err2) {
|
|
52
|
-
connection.release();
|
|
53
|
-
return reject(err2);
|
|
54
|
-
}
|
|
55
|
-
startTxn();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
startTxn();
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async exec(sql: string, txn?: string): Promise<any> {
|
|
67
|
-
if (process.env.NODE_ENV === 'development') {
|
|
68
|
-
console.log(sql);
|
|
69
|
-
}
|
|
70
|
-
if (txn) {
|
|
71
|
-
const connection = this.txnDict[txn];
|
|
72
|
-
assert(connection);
|
|
73
|
-
|
|
74
|
-
return new Promise(
|
|
75
|
-
(resolve, reject) => {
|
|
76
|
-
connection.query(sql, (err, result) => {
|
|
77
|
-
if (err) {
|
|
78
|
-
console.error(`sql exec err: ${sql}`, err);
|
|
79
|
-
return reject(err);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
resolve(result);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
return new Promise(
|
|
89
|
-
(resolve, reject) => {
|
|
90
|
-
// if (process.env.DEBUG) {
|
|
91
|
-
// console.log(sql);
|
|
92
|
-
//}
|
|
93
|
-
this.pool!.query(sql, (err, result) => {
|
|
94
|
-
if (err) {
|
|
95
|
-
console.error(`sql exec err: ${sql}`, err);
|
|
96
|
-
return reject(err);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
resolve(result);
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
commitTransaction(txn: string): Promise<void> {
|
|
107
|
-
const connection = this.txnDict[txn];
|
|
108
|
-
assert(connection);
|
|
109
|
-
return new Promise(
|
|
110
|
-
(resolve, reject) => {
|
|
111
|
-
connection.query('COMMIT;', (err) => {
|
|
112
|
-
if (err) {
|
|
113
|
-
return reject(err);
|
|
114
|
-
}
|
|
115
|
-
connection.release();
|
|
116
|
-
resolve();
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
rollbackTransaction(txn: string): Promise<void> {
|
|
123
|
-
const connection = this.txnDict[txn];
|
|
124
|
-
assert(connection);
|
|
125
|
-
return new Promise(
|
|
126
|
-
(resolve, reject) => {
|
|
127
|
-
connection.query('ROLLBACK;', (err: Error) => {
|
|
128
|
-
if (err) {
|
|
129
|
-
return reject(err);
|
|
130
|
-
}
|
|
131
|
-
connection.release();
|
|
132
|
-
resolve();
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|