oak-db 1.0.7 → 2.0.2
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.d.ts +9 -5
- package/lib/MySQL/store.js +11 -7
- package/lib/MySQL/translator.js +13 -2
- package/lib/sqlTranslator.js +4 -0
- package/package.json +3 -3
package/lib/MySQL/store.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { EntityDict,
|
|
1
|
+
import { EntityDict, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, OperationResult, TxnOption, StorageSchema, DeduceCreateMultipleOperation, SelectOption } from 'oak-domain/lib/types';
|
|
2
2
|
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
3
3
|
import { CascadeStore } from 'oak-domain/lib/store/CascadeStore';
|
|
4
4
|
import { MySQLConfiguration } from './types/Configuration';
|
|
5
5
|
import { MySqlConnector } from './connector';
|
|
6
6
|
import { MySqlTranslator, MySqlSelectOption, MysqlOperateOption } from './translator';
|
|
7
|
-
|
|
7
|
+
import { AsyncContext, AsyncRowStore } from 'oak-domain/lib/store/AsyncRowStore';
|
|
8
|
+
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
|
9
|
+
export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends CascadeStore<ED> implements AsyncRowStore<ED, Cxt> {
|
|
10
|
+
protected selectAbjointRow<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: SyncContext<ED>, option: OP): Partial<ED[T]['Schema']>[];
|
|
11
|
+
protected updateAbjointRow<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: SyncContext<ED>, option: OP): number;
|
|
8
12
|
connector: MySqlConnector;
|
|
9
13
|
translator: MySqlTranslator<ED>;
|
|
10
14
|
constructor(storageSchema: StorageSchema<ED>, configuration: MySQLConfiguration);
|
|
11
15
|
protected supportManyToOneJoin(): boolean;
|
|
12
16
|
protected supportMultipleCreate(): boolean;
|
|
13
17
|
private formResult;
|
|
14
|
-
protected
|
|
15
|
-
protected
|
|
18
|
+
protected selectAbjointRowAsync<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: AsyncContext<ED>, option?: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
19
|
+
protected updateAbjointRowAsync<T extends keyof ED>(entity: T, operation: DeduceCreateMultipleOperation<ED[T]['Schema']> | DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: AsyncContext<ED>, option?: MysqlOperateOption): Promise<number>;
|
|
16
20
|
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OperateOption): Promise<OperationResult<ED>>;
|
|
17
|
-
select<T extends keyof ED,
|
|
21
|
+
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: SelectOption): Promise<Partial<ED[T]['Schema']>[]>;
|
|
18
22
|
count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
|
|
19
23
|
begin(option?: TxnOption): Promise<string>;
|
|
20
24
|
commit(txnId: string): Promise<void>;
|
package/lib/MySQL/store.js
CHANGED
|
@@ -28,6 +28,12 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
28
28
|
_this.translator = new translator_1.MySqlTranslator(storageSchema);
|
|
29
29
|
return _this;
|
|
30
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
|
+
};
|
|
31
37
|
MysqlStore.prototype.supportManyToOneJoin = function () {
|
|
32
38
|
return true;
|
|
33
39
|
};
|
|
@@ -166,7 +172,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
166
172
|
}
|
|
167
173
|
return formSingleRow(result);
|
|
168
174
|
};
|
|
169
|
-
MysqlStore.prototype.
|
|
175
|
+
MysqlStore.prototype.selectAbjointRowAsync = function (entity, selection, context, option) {
|
|
170
176
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
171
177
|
var sql, result;
|
|
172
178
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -181,7 +187,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
181
187
|
});
|
|
182
188
|
});
|
|
183
189
|
};
|
|
184
|
-
MysqlStore.prototype.
|
|
190
|
+
MysqlStore.prototype.updateAbjointRowAsync = function (entity, operation, context, option) {
|
|
185
191
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
186
192
|
var _a, translator, connector, action, txn, _b, data, sql, sql, sql;
|
|
187
193
|
return tslib_1.__generator(this, function (_c) {
|
|
@@ -252,7 +258,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
252
258
|
case 0:
|
|
253
259
|
action = operation.action;
|
|
254
260
|
(0, assert_1.default)(!['select', 'download', 'stat'].includes(action), '现在不支持使用select operation');
|
|
255
|
-
return [4 /*yield*/, this.
|
|
261
|
+
return [4 /*yield*/, this.cascadeUpdateAsync(entity, operation, context, option)];
|
|
256
262
|
case 1: return [2 /*return*/, _a.sent()];
|
|
257
263
|
}
|
|
258
264
|
});
|
|
@@ -263,12 +269,10 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
263
269
|
var result;
|
|
264
270
|
return tslib_1.__generator(this, function (_a) {
|
|
265
271
|
switch (_a.label) {
|
|
266
|
-
case 0: return [4 /*yield*/, this.
|
|
272
|
+
case 0: return [4 /*yield*/, this.cascadeSelectAsync(entity, selection, context, option)];
|
|
267
273
|
case 1:
|
|
268
274
|
result = _a.sent();
|
|
269
|
-
return [2 /*return*/,
|
|
270
|
-
result: result,
|
|
271
|
-
}];
|
|
275
|
+
return [2 /*return*/, result];
|
|
272
276
|
}
|
|
273
277
|
});
|
|
274
278
|
});
|
package/lib/MySQL/translator.js
CHANGED
|
@@ -124,7 +124,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
MySqlTranslator.prototype.populateDataTypeDef = function (type, params) {
|
|
127
|
-
if (['date', 'datetime', 'time'].includes(type)) {
|
|
127
|
+
if (['date', 'datetime', 'time', 'sequence'].includes(type)) {
|
|
128
128
|
return 'bigint ';
|
|
129
129
|
}
|
|
130
130
|
if (['object', 'array'].includes(type)) {
|
|
@@ -250,6 +250,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
250
250
|
var schema = this.schema;
|
|
251
251
|
var entityDef = schema[entity];
|
|
252
252
|
var storageName = entityDef.storageName, attributes = entityDef.attributes, indexes = entityDef.indexes, view = entityDef.view;
|
|
253
|
+
var hasSequence = false;
|
|
253
254
|
// todo view暂还不支持
|
|
254
255
|
var entityType = view ? 'view' : 'table';
|
|
255
256
|
var sql = "create ".concat(entityType, " ");
|
|
@@ -267,7 +268,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
267
268
|
// 翻译所有的属性
|
|
268
269
|
Object.keys(attributes).forEach(function (attr, idx) {
|
|
269
270
|
var attrDef = attributes[attr];
|
|
270
|
-
var type = attrDef.type, params = attrDef.params, defaultValue = attrDef.default, unique = attrDef.unique, notNull = attrDef.notNull;
|
|
271
|
+
var type = attrDef.type, params = attrDef.params, defaultValue = attrDef.default, unique = attrDef.unique, notNull = attrDef.notNull, sequenceStart = attrDef.sequenceStart;
|
|
271
272
|
sql += "`".concat(attr, "` ");
|
|
272
273
|
sql += _this.populateDataTypeDef(type, params);
|
|
273
274
|
if (notNull || type === 'geometry') {
|
|
@@ -276,6 +277,13 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
276
277
|
if (unique) {
|
|
277
278
|
sql += ' unique ';
|
|
278
279
|
}
|
|
280
|
+
if (sequenceStart) {
|
|
281
|
+
if (hasSequence) {
|
|
282
|
+
throw new Error("\u300C".concat(entity, "\u300D\u53EA\u80FD\u6709\u4E00\u4E2Asequence\u5217"));
|
|
283
|
+
}
|
|
284
|
+
hasSequence = sequenceStart;
|
|
285
|
+
sql += ' auto_increment unique ';
|
|
286
|
+
}
|
|
279
287
|
if (defaultValue !== undefined) {
|
|
280
288
|
(0, assert_1.default)(type !== 'ref');
|
|
281
289
|
sql += " default ".concat(_this.translateAttrValue(type, defaultValue));
|
|
@@ -338,6 +346,9 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
|
|
338
346
|
}
|
|
339
347
|
}
|
|
340
348
|
sql += ')';
|
|
349
|
+
if (typeof hasSequence === 'number') {
|
|
350
|
+
sql += "auto_increment = ".concat(hasSequence);
|
|
351
|
+
}
|
|
341
352
|
if (!replace) {
|
|
342
353
|
return [sql];
|
|
343
354
|
}
|
package/lib/sqlTranslator.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "oak-db",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lodash": "^4.17.21",
|
|
19
19
|
"mysql": "^2.18.1",
|
|
20
20
|
"mysql2": "^2.3.3",
|
|
21
|
-
"oak-domain": "^
|
|
21
|
+
"oak-domain": "^2.0.1",
|
|
22
22
|
"uuid": "^8.3.2"
|
|
23
23
|
},
|
|
24
24
|
"license": "ISC",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "^17.0.42",
|
|
30
30
|
"@types/uuid": "^8.3.4",
|
|
31
31
|
"mocha": "^10.0.0",
|
|
32
|
-
"oak-general-business": "
|
|
32
|
+
"oak-general-business": "^2.0.1",
|
|
33
33
|
"ts-node": "~10.9.1",
|
|
34
34
|
"tslib": "^2.4.0",
|
|
35
35
|
"typescript": "~4.7.4"
|