oak-db 1.0.2 → 1.0.4
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/store.js +1 -1
- package/lib/MySQL/translator.js +20 -17
- package/lib/sqlTranslator.js +27 -15
- package/package.json +4 -4
- package/src/index.ts +0 -2
package/lib/MySQL/store.js
CHANGED
|
@@ -270,7 +270,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
270
270
|
return [4 /*yield*/, this.connector.exec(sql, context.getCurrentTxnId())];
|
|
271
271
|
case 1:
|
|
272
272
|
result = _a.sent();
|
|
273
|
-
return [2 /*return*/, result.
|
|
273
|
+
return [2 /*return*/, result[0].cnt];
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
276
|
});
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -125,6 +125,18 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
MySqlTranslator.prototype.populateDataTypeDef = function (type, params) {
|
|
128
|
+
if (['date', 'datetime', 'time'].includes(type)) {
|
|
129
|
+
return 'bigint ';
|
|
130
|
+
}
|
|
131
|
+
if (['object', 'array'].includes(type)) {
|
|
132
|
+
return 'text ';
|
|
133
|
+
}
|
|
134
|
+
if (['image', 'function'].includes(type)) {
|
|
135
|
+
return 'text ';
|
|
136
|
+
}
|
|
137
|
+
if (type === 'ref') {
|
|
138
|
+
return 'char(36)';
|
|
139
|
+
}
|
|
128
140
|
if (MySqlTranslator.withLengthDataTypes.includes(type)) {
|
|
129
141
|
if (params) {
|
|
130
142
|
var length_1 = params.length;
|
|
@@ -172,18 +184,6 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
172
184
|
}
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
|
-
if (['date'].includes(type)) {
|
|
176
|
-
return 'datetime';
|
|
177
|
-
}
|
|
178
|
-
if (['object', 'array'].includes(type)) {
|
|
179
|
-
return 'text ';
|
|
180
|
-
}
|
|
181
|
-
if (['image', 'function'].includes(type)) {
|
|
182
|
-
return 'text ';
|
|
183
|
-
}
|
|
184
|
-
if (type === 'ref') {
|
|
185
|
-
return 'char(36)';
|
|
186
|
-
}
|
|
187
187
|
return "".concat(type, " ");
|
|
188
188
|
};
|
|
189
189
|
MySqlTranslator.prototype.translateAttrProjection = function (dataType, alias, attr) {
|
|
@@ -197,21 +197,23 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
199
|
MySqlTranslator.prototype.translateAttrValue = function (dataType, value) {
|
|
200
|
-
if (value === null) {
|
|
200
|
+
if (value === null || value === undefined) {
|
|
201
201
|
return 'null';
|
|
202
202
|
}
|
|
203
203
|
switch (dataType) {
|
|
204
204
|
case 'geometry': {
|
|
205
205
|
return transformGeoData(value);
|
|
206
206
|
}
|
|
207
|
+
case 'datetime':
|
|
208
|
+
case 'time':
|
|
207
209
|
case 'date': {
|
|
208
210
|
if (value instanceof Date) {
|
|
209
|
-
return
|
|
211
|
+
return "".concat(value.valueOf());
|
|
210
212
|
}
|
|
211
213
|
else if (typeof value === 'number') {
|
|
212
|
-
return
|
|
214
|
+
return "".concat(value);
|
|
213
215
|
}
|
|
214
|
-
return value;
|
|
216
|
+
return "'".concat((new Date(value)).valueOf(), "'");
|
|
215
217
|
}
|
|
216
218
|
case 'object':
|
|
217
219
|
case 'array': {
|
|
@@ -547,7 +549,8 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
547
549
|
// todo using index
|
|
548
550
|
var alias = aliasDict['./'];
|
|
549
551
|
var now = luxon_1.DateTime.now().toFormat('yyyy-LL-dd HH:mm:ss');
|
|
550
|
-
|
|
552
|
+
(0, assert_1.default)(updateText);
|
|
553
|
+
var sql = "update ".concat(fromText, " set ").concat(updateText);
|
|
551
554
|
if (filterText) {
|
|
552
555
|
sql += " where ".concat(filterText);
|
|
553
556
|
}
|
package/lib/sqlTranslator.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.SqlTranslator = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var lodash_1 = require("lodash");
|
|
7
|
-
var luxon_1 = require("luxon");
|
|
8
7
|
var types_1 = require("oak-domain/lib/types");
|
|
9
8
|
var relation_1 = require("oak-domain/lib/store/relation");
|
|
10
9
|
;
|
|
@@ -26,21 +25,21 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
26
25
|
},
|
|
27
26
|
},
|
|
28
27
|
$$createAt$$: {
|
|
29
|
-
type: '
|
|
28
|
+
type: 'datetime',
|
|
30
29
|
notNull: true,
|
|
31
30
|
},
|
|
32
31
|
$$updateAt$$: {
|
|
33
|
-
type: '
|
|
32
|
+
type: 'datetime',
|
|
34
33
|
notNull: true,
|
|
35
34
|
},
|
|
36
35
|
$$deleteAt$$: {
|
|
37
|
-
type: '
|
|
36
|
+
type: 'datetime',
|
|
38
37
|
},
|
|
39
38
|
$$triggerData$$: {
|
|
40
39
|
type: 'object',
|
|
41
40
|
},
|
|
42
41
|
$$triggerTimestamp$$: {
|
|
43
|
-
type: '
|
|
42
|
+
type: 'datetime',
|
|
44
43
|
},
|
|
45
44
|
});
|
|
46
45
|
// 增加默认的索引
|
|
@@ -113,15 +112,18 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
113
112
|
var schema = this.schema;
|
|
114
113
|
var _a = schema[entity], attributes = _a.attributes, _b = _a.storageName, storageName = _b === void 0 ? entity : _b;
|
|
115
114
|
var sql = "insert into `".concat(storageName, "`(");
|
|
116
|
-
|
|
115
|
+
/**
|
|
116
|
+
* 这里的attrs要用所有行的union集合
|
|
117
|
+
*/
|
|
118
|
+
var dataFull = data.reduce(function (prev, cur) { return Object.assign({}, cur, prev); }, {});
|
|
119
|
+
var attrs = Object.keys(dataFull).filter(function (ele) { return attributes.hasOwnProperty(ele); });
|
|
117
120
|
attrs.forEach(function (attr, idx) {
|
|
118
121
|
sql += " `".concat(attr, "`");
|
|
119
122
|
if (idx < attrs.length - 1) {
|
|
120
123
|
sql += ',';
|
|
121
124
|
}
|
|
122
125
|
});
|
|
123
|
-
sql += '
|
|
124
|
-
var now = luxon_1.DateTime.now().toFormat('yyyy-LL-dd HH:mm:ss');
|
|
126
|
+
sql += ') values ';
|
|
125
127
|
data.forEach(function (d, dataIndex) {
|
|
126
128
|
sql += '(';
|
|
127
129
|
attrs.forEach(function (attr, attrIdx) {
|
|
@@ -133,9 +135,11 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
133
135
|
sql += ',';
|
|
134
136
|
}
|
|
135
137
|
});
|
|
136
|
-
sql += ", '".concat(now, "', '").concat(now, "')");
|
|
137
138
|
if (dataIndex < data.length - 1) {
|
|
138
|
-
sql += ',';
|
|
139
|
+
sql += '),';
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
sql += ')';
|
|
139
143
|
}
|
|
140
144
|
});
|
|
141
145
|
return sql;
|
|
@@ -179,6 +183,14 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
179
183
|
alias: alias,
|
|
180
184
|
}); });
|
|
181
185
|
}
|
|
186
|
+
else if (['$not'].includes(op)) {
|
|
187
|
+
analyzeFilterNode({
|
|
188
|
+
node: node[op],
|
|
189
|
+
path: path,
|
|
190
|
+
entityName: entityName,
|
|
191
|
+
alias: alias,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
182
194
|
else {
|
|
183
195
|
var rel = (0, relation_1.judgeRelation)(_this.schema, entityName, op);
|
|
184
196
|
if (typeof rel === 'string') {
|
|
@@ -218,7 +230,7 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
218
230
|
analyzeFilterNode({
|
|
219
231
|
node: node[op],
|
|
220
232
|
path: pathAttr,
|
|
221
|
-
entityName:
|
|
233
|
+
entityName: op,
|
|
222
234
|
alias: alias2,
|
|
223
235
|
});
|
|
224
236
|
}
|
|
@@ -537,7 +549,7 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
537
549
|
currentNumber = cn2;
|
|
538
550
|
}
|
|
539
551
|
else {
|
|
540
|
-
var rel = (0, relation_1.judgeRelation)(_this.schema,
|
|
552
|
+
var rel = (0, relation_1.judgeRelation)(_this.schema, entity2, attr);
|
|
541
553
|
if (rel === 2) {
|
|
542
554
|
whereText += " ".concat(translateInner(attr, "".concat(path).concat(attr, "/"), filter2[attr]));
|
|
543
555
|
}
|
|
@@ -685,11 +697,11 @@ var SqlTranslator = /** @class */ (function () {
|
|
|
685
697
|
var _a = this.analyzeJoin(entity, {
|
|
686
698
|
filter: filter,
|
|
687
699
|
}), fromText = _a.from, aliasDict = _a.aliasDict, extraWhere = _a.extraWhere, filterRefAlias = _a.filterRefAlias, currentNumber = _a.currentNumber;
|
|
688
|
-
var projText = 'count(1)';
|
|
700
|
+
var projText = 'count(1) cnt';
|
|
689
701
|
var filterText = this.translateFilter(entity, selection, aliasDict, filterRefAlias, currentNumber, extraWhere, option).stmt;
|
|
690
702
|
if (count) {
|
|
691
|
-
var subQuerySql = this.populateSelectStmt('1', fromText, Object.assign({}, selection, { indexFrom: 0 }), aliasDict, filterText, undefined, undefined, undefined, option);
|
|
692
|
-
return "select count(1) from (".concat(subQuerySql, ")");
|
|
703
|
+
var subQuerySql = this.populateSelectStmt('1', fromText, Object.assign({}, selection, { indexFrom: 0, count: count }), aliasDict, filterText, undefined, undefined, undefined, option);
|
|
704
|
+
return "select count(1) cnt from (".concat(subQuerySql, ") __tmp");
|
|
693
705
|
}
|
|
694
706
|
return this.populateSelectStmt(projText, fromText, selection, aliasDict, filterText, undefined, undefined, undefined, option);
|
|
695
707
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "oak-db",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "XuChang"
|
|
8
8
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"luxon": "^2.4.0",
|
|
20
20
|
"mysql": "^2.18.1",
|
|
21
21
|
"mysql2": "^2.3.3",
|
|
22
|
-
"oak-domain": "
|
|
22
|
+
"oak-domain": "1.1.11",
|
|
23
23
|
"uuid": "^8.3.2"
|
|
24
24
|
},
|
|
25
25
|
"license": "ISC",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@types/node": "^17.0.42",
|
|
31
31
|
"@types/uuid": "^8.3.4",
|
|
32
32
|
"mocha": "^10.0.0",
|
|
33
|
-
"oak-general-business": "
|
|
33
|
+
"oak-general-business": "1.0.13",
|
|
34
34
|
"ts-node": "~10.9.1",
|
|
35
35
|
"tslib": "^2.4.0",
|
|
36
36
|
"typescript": "~4.7.4"
|
package/src/index.ts
DELETED