tsconfig.json target改成ESNext
This commit is contained in:
parent
3dd5608c2a
commit
404d7ca9ba
|
|
@ -1,46 +1,47 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MySqlConnector = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var mysql2_1 = tslib_1.__importDefault(require("mysql2"));
|
||||
var uuid_1 = require("uuid");
|
||||
var assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
var MySqlConnector = /** @class */ (function () {
|
||||
function MySqlConnector(configuration) {
|
||||
const tslib_1 = require("tslib");
|
||||
const mysql2_1 = tslib_1.__importDefault(require("mysql2"));
|
||||
const uuid_1 = require("uuid");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
class MySqlConnector {
|
||||
pool;
|
||||
configuration;
|
||||
txnDict;
|
||||
constructor(configuration) {
|
||||
this.configuration = configuration;
|
||||
this.txnDict = {};
|
||||
}
|
||||
MySqlConnector.prototype.connect = function () {
|
||||
connect() {
|
||||
this.pool = mysql2_1.default.createPool(this.configuration);
|
||||
};
|
||||
MySqlConnector.prototype.disconnect = function () {
|
||||
}
|
||||
disconnect() {
|
||||
this.pool.end();
|
||||
};
|
||||
MySqlConnector.prototype.startTransaction = function (option) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this.pool.getConnection(function (err, connection) {
|
||||
}
|
||||
startTransaction(option) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pool.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
var isolationLevel = (option || {}).isolationLevel;
|
||||
var startTxn = function () {
|
||||
var sql = 'START TRANSACTION;';
|
||||
connection.query(sql, function (err2) {
|
||||
var _a;
|
||||
const { isolationLevel } = option || {};
|
||||
const startTxn = () => {
|
||||
let sql = 'START TRANSACTION;';
|
||||
connection.query(sql, (err2) => {
|
||||
if (err2) {
|
||||
connection.release();
|
||||
return reject(err2);
|
||||
}
|
||||
var id = (0, uuid_1.v4)();
|
||||
Object.assign(_this.txnDict, (_a = {},
|
||||
_a[id] = connection,
|
||||
_a));
|
||||
const id = (0, uuid_1.v4)();
|
||||
Object.assign(this.txnDict, {
|
||||
[id]: connection,
|
||||
});
|
||||
resolve(id);
|
||||
});
|
||||
};
|
||||
if (isolationLevel) {
|
||||
connection.query("SET TRANSACTION ISOLATION LEVEL ".concat(isolationLevel, ";"), function (err2) {
|
||||
connection.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel};`, (err2) => {
|
||||
if (err2) {
|
||||
connection.release();
|
||||
return reject(err2);
|
||||
|
|
@ -53,51 +54,44 @@ var MySqlConnector = /** @class */ (function () {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MySqlConnector.prototype.exec = function (sql, txn) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var connection_1;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
}
|
||||
async exec(sql, txn) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log(sql);
|
||||
}
|
||||
if (txn) {
|
||||
connection_1 = this.txnDict[txn];
|
||||
(0, assert_1.default)(connection_1);
|
||||
return [2 /*return*/, new Promise(function (resolve, reject) {
|
||||
connection_1.query(sql, function (err, result) {
|
||||
const connection = this.txnDict[txn];
|
||||
(0, assert_1.default)(connection);
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
console.error("sql exec err: ".concat(sql), err);
|
||||
console.error(`sql exec err: ${sql}`, err);
|
||||
return reject(err);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
})];
|
||||
});
|
||||
}
|
||||
else {
|
||||
return [2 /*return*/, new Promise(function (resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// if (process.env.DEBUG) {
|
||||
// console.log(sql);
|
||||
//}
|
||||
_this.pool.query(sql, function (err, result) {
|
||||
this.pool.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
console.error("sql exec err: ".concat(sql), err);
|
||||
console.error(`sql exec err: ${sql}`, err);
|
||||
return reject(err);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
})];
|
||||
});
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
MySqlConnector.prototype.commitTransaction = function (txn) {
|
||||
var connection = this.txnDict[txn];
|
||||
}
|
||||
commitTransaction(txn) {
|
||||
const connection = this.txnDict[txn];
|
||||
(0, assert_1.default)(connection);
|
||||
return new Promise(function (resolve, reject) {
|
||||
connection.query('COMMIT;', function (err) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query('COMMIT;', (err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
|
@ -105,12 +99,12 @@ var MySqlConnector = /** @class */ (function () {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
MySqlConnector.prototype.rollbackTransaction = function (txn) {
|
||||
var connection = this.txnDict[txn];
|
||||
}
|
||||
rollbackTransaction(txn) {
|
||||
const connection = this.txnDict[txn];
|
||||
(0, assert_1.default)(connection);
|
||||
return new Promise(function (resolve, reject) {
|
||||
connection.query('ROLLBACK;', function (err) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query('ROLLBACK;', (err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
|
@ -118,7 +112,6 @@ var MySqlConnector = /** @class */ (function () {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
return MySqlConnector;
|
||||
}());
|
||||
}
|
||||
}
|
||||
exports.MySqlConnector = MySqlConnector;
|
||||
|
|
|
|||
|
|
@ -1,71 +1,61 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MysqlStore = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
||||
var connector_1 = require("./connector");
|
||||
var translator_1 = require("./translator");
|
||||
var lodash_1 = require("lodash");
|
||||
var assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
var relation_1 = require("oak-domain/lib/store/relation");
|
||||
const tslib_1 = require("tslib");
|
||||
const CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
||||
const connector_1 = require("./connector");
|
||||
const translator_1 = require("./translator");
|
||||
const lodash_1 = require("lodash");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const relation_1 = require("oak-domain/lib/store/relation");
|
||||
function convertGeoTextToObject(geoText) {
|
||||
if (geoText.startsWith('POINT')) {
|
||||
var coord = geoText.match((/(\d|\.)+(?=\)|\s)/g));
|
||||
const coord = geoText.match((/(\d|\.)+(?=\)|\s)/g));
|
||||
return {
|
||||
type: 'Point',
|
||||
coordinate: coord.map(function (ele) { return parseFloat(ele); }),
|
||||
coordinate: coord.map(ele => parseFloat(ele)),
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new Error('only support Point now');
|
||||
}
|
||||
}
|
||||
var MysqlStore = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(MysqlStore, _super);
|
||||
function MysqlStore(storageSchema, configuration) {
|
||||
var _this = _super.call(this, storageSchema) || this;
|
||||
_this.connector = new connector_1.MySqlConnector(configuration);
|
||||
_this.translator = new translator_1.MySqlTranslator(storageSchema);
|
||||
return _this;
|
||||
class MysqlStore extends CascadeStore_1.CascadeStore {
|
||||
aggregateSync(entity, aggregation, context, option) {
|
||||
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
||||
}
|
||||
MysqlStore.prototype.aggregateSync = function (entity, aggregation, context, option) {
|
||||
selectAbjointRow(entity, selection, context, option) {
|
||||
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
||||
};
|
||||
MysqlStore.prototype.selectAbjointRow = function (entity, selection, context, option) {
|
||||
throw new Error('MySQL store不支持同步取数据,不应该跑到这儿');
|
||||
};
|
||||
MysqlStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
||||
}
|
||||
updateAbjointRow(entity, operation, context, option) {
|
||||
throw new Error('MySQL store不支持同步更新数据,不应该跑到这儿');
|
||||
};
|
||||
MysqlStore.prototype.exec = function (script, txnId) {
|
||||
return this.connector.exec(script, txnId);
|
||||
};
|
||||
MysqlStore.prototype.aggregateAsync = function (entity, aggregation, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var sql, result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
sql = this.translator.translateAggregate(entity, aggregation, option);
|
||||
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/, this.formResult(entity, result)];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.aggregate = function (entity, aggregation, context, option) {
|
||||
exec(script, txnId) {
|
||||
return this.connector.exec(script, txnId);
|
||||
}
|
||||
connector;
|
||||
translator;
|
||||
constructor(storageSchema, configuration) {
|
||||
super(storageSchema);
|
||||
this.connector = new connector_1.MySqlConnector(configuration);
|
||||
this.translator = new translator_1.MySqlTranslator(storageSchema);
|
||||
}
|
||||
async aggregateAsync(entity, aggregation, context, option) {
|
||||
const sql = this.translator.translateAggregate(entity, aggregation, option);
|
||||
const result = await this.connector.exec(sql, context.getCurrentTxnId());
|
||||
return this.formResult(entity, result);
|
||||
}
|
||||
aggregate(entity, aggregation, context, option) {
|
||||
return this.aggregateAsync(entity, aggregation, context, option);
|
||||
};
|
||||
MysqlStore.prototype.supportManyToOneJoin = function () {
|
||||
}
|
||||
supportManyToOneJoin() {
|
||||
return true;
|
||||
};
|
||||
MysqlStore.prototype.supportMultipleCreate = function () {
|
||||
}
|
||||
supportMultipleCreate() {
|
||||
return true;
|
||||
};
|
||||
MysqlStore.prototype.formResult = function (entity, result) {
|
||||
var schema = this.getSchema();
|
||||
}
|
||||
formResult(entity, result) {
|
||||
const schema = this.getSchema();
|
||||
/* function resolveObject(r: Record<string, any>, path: string, value: any) {
|
||||
const i = path.indexOf(".");
|
||||
const bs = path.indexOf('[');
|
||||
|
|
@ -86,14 +76,13 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
}
|
||||
} */
|
||||
function resolveAttribute(entity2, r, attr, value) {
|
||||
var _a;
|
||||
var _b = schema[entity2], attributes = _b.attributes, view = _b.view;
|
||||
const { attributes, view } = schema[entity2];
|
||||
if (!view) {
|
||||
var i = attr.indexOf(".");
|
||||
const i = attr.indexOf(".");
|
||||
if (i !== -1) {
|
||||
var attrHead = attr.slice(0, i);
|
||||
var attrTail = attr.slice(i + 1);
|
||||
var rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
|
||||
const attrHead = attr.slice(0, i);
|
||||
const attrTail = attr.slice(i + 1);
|
||||
const rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
|
||||
if (rel === 1) {
|
||||
(0, lodash_1.set)(r, attr, value);
|
||||
}
|
||||
|
|
@ -114,7 +103,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
else if (attributes[attr]) {
|
||||
var type = attributes[attr].type;
|
||||
const { type } = attributes[attr];
|
||||
switch (type) {
|
||||
case 'date':
|
||||
case 'time': {
|
||||
|
|
@ -148,7 +137,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
case 'function': {
|
||||
if (typeof value === 'string') {
|
||||
// 函数的执行环境需要的参数只有创建函数者知悉,只能由上层再创建Function
|
||||
r[attr] = "return ".concat(Buffer.from(value, 'base64').toString());
|
||||
r[attr] = `return ${Buffer.from(value, 'base64').toString()}`;
|
||||
}
|
||||
else {
|
||||
r[attr] = value;
|
||||
|
|
@ -189,31 +178,31 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(r, (_a = {},
|
||||
_a[attr] = value,
|
||||
_a));
|
||||
(0, lodash_1.assign)(r, {
|
||||
[attr]: value,
|
||||
});
|
||||
}
|
||||
}
|
||||
function removeNullObjects(r, e) {
|
||||
// assert(r.id && typeof r.id === 'string', `对象${<string>e}取数据时发现id为非法值${r.id},rowId是${r.id}`)
|
||||
for (var attr in r) {
|
||||
var rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
||||
for (let attr in r) {
|
||||
const rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
||||
if (rel === 2) {
|
||||
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
||||
(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));
|
||||
(0, assert_1.default)(schema[e].toModi || r.entity !== attr || r.entityId === r[attr].id, `对象${e}取数据时,发现entityId与连接的对象的主键不一致,rowId是${r.id},其entityId值为${r.entityId},连接的对象的主键为${r[attr].id}`);
|
||||
if (r[attr].id === null) {
|
||||
(0, assert_1.default)(schema[e].toModi || r.entity !== attr);
|
||||
delete r[attr];
|
||||
continue;
|
||||
}
|
||||
(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));
|
||||
(0, assert_1.default)(r.entity === attr, `对象${e}取数据时,发现entity值与连接的外键对象不一致,rowId是${r.id},其entity值为${r.entity},连接的对象为${attr}`);
|
||||
removeNullObjects(r[attr], attr);
|
||||
}
|
||||
else if (typeof rel === 'string') {
|
||||
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
||||
(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));
|
||||
(0, assert_1.default)(schema[e].toModi || r[`${attr}Id`] === r[attr].id, `对象${e}取数据时,发现其外键与连接的对象的主键不一致,rowId是${r.id},其${attr}Id值为${r[`${attr}Id`]},连接的对象的主键为${r[attr].id}`);
|
||||
if (r[attr].id === null) {
|
||||
(0, assert_1.default)(schema[e].toModi || r["".concat(attr, "Id")] === null);
|
||||
(0, assert_1.default)(schema[e].toModi || r[`${attr}Id`] === null);
|
||||
delete r[attr];
|
||||
continue;
|
||||
}
|
||||
|
|
@ -222,85 +211,61 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
function formSingleRow(r) {
|
||||
var result2 = {};
|
||||
for (var attr in r) {
|
||||
var value = r[attr];
|
||||
let result2 = {};
|
||||
for (let attr in r) {
|
||||
const value = r[attr];
|
||||
resolveAttribute(entity, result2, attr, value);
|
||||
}
|
||||
removeNullObjects(result2, entity);
|
||||
return result2;
|
||||
}
|
||||
if (result instanceof Array) {
|
||||
return result.map(function (r) { return formSingleRow(r); });
|
||||
return result.map(r => formSingleRow(r));
|
||||
}
|
||||
return formSingleRow(result);
|
||||
};
|
||||
MysqlStore.prototype.selectAbjointRowAsync = function (entity, selection, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var sql, result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
sql = this.translator.translateSelect(entity, selection, option);
|
||||
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/, this.formResult(entity, result)];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.updateAbjointRowAsync = function (entity, operation, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var _a, translator, connector, action, txn, _b, data, sql, sql, sql;
|
||||
return tslib_1.__generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
_a = this, translator = _a.translator, connector = _a.connector;
|
||||
action = operation.action;
|
||||
txn = context.getCurrentTxnId();
|
||||
_b = action;
|
||||
switch (_b) {
|
||||
case 'create': return [3 /*break*/, 1];
|
||||
case 'remove': return [3 /*break*/, 3];
|
||||
async selectAbjointRowAsync(entity, selection, context, option) {
|
||||
const sql = this.translator.translateSelect(entity, selection, option);
|
||||
const result = await this.connector.exec(sql, context.getCurrentTxnId());
|
||||
return this.formResult(entity, result);
|
||||
}
|
||||
return [3 /*break*/, 5];
|
||||
case 1:
|
||||
data = operation.data;
|
||||
sql = translator.translateInsert(entity, data instanceof Array ? data : [data]);
|
||||
return [4 /*yield*/, connector.exec(sql, txn)];
|
||||
case 2:
|
||||
_c.sent();
|
||||
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
||||
async updateAbjointRowAsync(entity, operation, context, option) {
|
||||
const { translator, connector } = this;
|
||||
const { action } = operation;
|
||||
const txn = context.getCurrentTxnId();
|
||||
switch (action) {
|
||||
case 'create': {
|
||||
const { data } = operation;
|
||||
const sql = translator.translateInsert(entity, data instanceof Array ? data : [data]);
|
||||
await connector.exec(sql, txn);
|
||||
if (!option?.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'c',
|
||||
d: data,
|
||||
e: entity,
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, data instanceof Array ? data.length : 1];
|
||||
case 3:
|
||||
sql = translator.translateRemove(entity, operation, option);
|
||||
return [4 /*yield*/, connector.exec(sql, txn)];
|
||||
case 4:
|
||||
_c.sent();
|
||||
return data instanceof Array ? data.length : 1;
|
||||
}
|
||||
case 'remove': {
|
||||
const sql = translator.translateRemove(entity, operation, option);
|
||||
await connector.exec(sql, txn);
|
||||
// todo 这里对sorter和indexfrom/count的支持不完整
|
||||
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
||||
if (!option?.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'r',
|
||||
e: entity,
|
||||
f: operation.filter,
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, 1];
|
||||
case 5:
|
||||
return 1;
|
||||
}
|
||||
default: {
|
||||
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action));
|
||||
sql = translator.translateUpdate(entity, operation, option);
|
||||
return [4 /*yield*/, connector.exec(sql, txn)];
|
||||
case 6:
|
||||
_c.sent();
|
||||
const sql = translator.translateUpdate(entity, operation, option);
|
||||
await connector.exec(sql, txn);
|
||||
// todo 这里对sorter和indexfrom/count的支持不完整
|
||||
if (!(option === null || option === void 0 ? void 0 : option.dontCollect)) {
|
||||
if (!option?.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'u',
|
||||
e: entity,
|
||||
|
|
@ -308,132 +273,48 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
f: operation.filter,
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, 1];
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.operate = function (entity, operation, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var action;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
action = operation.action;
|
||||
}
|
||||
}
|
||||
async operate(entity, operation, context, option) {
|
||||
const { action } = operation;
|
||||
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action), '现在不支持使用select operation');
|
||||
return [4 /*yield*/, _super.prototype.operateAsync.call(this, entity, operation, context, option)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
return await super.operateAsync(entity, operation, context, option);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.select = function (entity, selection, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, _super.prototype.selectAsync.call(this, entity, selection, context, option)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/, result];
|
||||
async select(entity, selection, context, option) {
|
||||
const result = await super.selectAsync(entity, selection, context, option);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.count = function (entity, selection, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var sql, result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
sql = this.translator.translateCount(entity, selection, option);
|
||||
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/, result[0].cnt];
|
||||
async count(entity, selection, context, option) {
|
||||
const sql = this.translator.translateCount(entity, selection, option);
|
||||
const result = await this.connector.exec(sql, context.getCurrentTxnId());
|
||||
return result[0].cnt;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.begin = function (option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var txn;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.connector.startTransaction(option)];
|
||||
case 1:
|
||||
txn = _a.sent();
|
||||
return [2 /*return*/, txn];
|
||||
async begin(option) {
|
||||
const txn = await this.connector.startTransaction(option);
|
||||
return txn;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.commit = function (txnId) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.connector.commitTransaction(txnId)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
async commit(txnId) {
|
||||
await this.connector.commitTransaction(txnId);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.rollback = function (txnId) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.connector.rollbackTransaction(txnId)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
async rollback(txnId) {
|
||||
await this.connector.rollbackTransaction(txnId);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MysqlStore.prototype.connect = function () {
|
||||
connect() {
|
||||
this.connector.connect();
|
||||
};
|
||||
MysqlStore.prototype.disconnect = function () {
|
||||
this.connector.disconnect();
|
||||
};
|
||||
MysqlStore.prototype.initialize = function (dropIfExists) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var schema, _a, _b, _i, entity, sqls, _c, sqls_1, sql;
|
||||
return tslib_1.__generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
schema = this.getSchema();
|
||||
_a = [];
|
||||
for (_b in schema)
|
||||
_a.push(_b);
|
||||
_i = 0;
|
||||
_d.label = 1;
|
||||
case 1:
|
||||
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
||||
entity = _a[_i];
|
||||
sqls = this.translator.translateCreateEntity(entity, { replace: dropIfExists });
|
||||
_c = 0, sqls_1 = sqls;
|
||||
_d.label = 2;
|
||||
case 2:
|
||||
if (!(_c < sqls_1.length)) return [3 /*break*/, 5];
|
||||
sql = sqls_1[_c];
|
||||
return [4 /*yield*/, this.connector.exec(sql)];
|
||||
case 3:
|
||||
_d.sent();
|
||||
_d.label = 4;
|
||||
case 4:
|
||||
_c++;
|
||||
return [3 /*break*/, 2];
|
||||
case 5:
|
||||
_i++;
|
||||
return [3 /*break*/, 1];
|
||||
case 6: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return MysqlStore;
|
||||
}(CascadeStore_1.CascadeStore));
|
||||
disconnect() {
|
||||
this.connector.disconnect();
|
||||
}
|
||||
async initialize(dropIfExists) {
|
||||
const schema = this.getSchema();
|
||||
for (const entity in schema) {
|
||||
const sqls = this.translator.translateCreateEntity(entity, { replace: dropIfExists });
|
||||
for (const sql of sqls) {
|
||||
await this.connector.exec(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.MysqlStore = MysqlStore;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,4 +1,4 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./MySQL/store"), exports);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -30,10 +30,10 @@
|
|||
"@types/sqlstring": "^2.3.0",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"cross-env": "^7.0.3",
|
||||
"mocha": "^10.0.0",
|
||||
"mocha": "^10.2.0",
|
||||
"oak-general-business": "file:../oak-general-business",
|
||||
"ts-node": "~10.9.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "~4.7.4"
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"target": "es5",
|
||||
"target": "ESNext",
|
||||
"declaration": true,
|
||||
"allowJs": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
"skipLibCheck": true,
|
||||
"importHelpers": true,
|
||||
"lib": [
|
||||
"ES2020",
|
||||
"ESNext",
|
||||
"DOM"
|
||||
],
|
||||
"outDir": "lib", /* Redirect output structure to the directory. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue