oak-db 3.3.10 → 3.3.12
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.d.ts +15 -15
- package/lib/MySQL/connector.js +77 -77
- package/lib/MySQL/store.d.ts +30 -4
- package/lib/MySQL/store.js +125 -3
- package/lib/MySQL/translator.d.ts +114 -107
- package/lib/MySQL/translator.js +1207 -969
- package/lib/MySQL/types/Configuration.d.ts +12 -12
- package/lib/MySQL/types/Configuration.js +2 -2
- package/lib/PostgreSQL/connector.d.ts +31 -0
- package/lib/PostgreSQL/connector.js +157 -0
- package/lib/PostgreSQL/store.d.ts +38 -0
- package/lib/PostgreSQL/store.js +329 -0
- package/lib/PostgreSQL/translator.d.ts +83 -0
- package/lib/PostgreSQL/translator.js +1770 -0
- package/lib/PostgreSQL/types/Configuration.d.ts +13 -0
- package/lib/PostgreSQL/types/Configuration.js +2 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +5 -4
- package/lib/sqlTranslator.d.ts +68 -55
- package/lib/sqlTranslator.js +72 -39
- package/lib/types/Translator.d.ts +3 -3
- package/lib/types/Translator.js +2 -2
- package/lib/types/configuration.d.ts +7 -0
- package/lib/types/configuration.js +2 -0
- package/lib/types/dbStore.d.ts +8 -0
- package/lib/types/dbStore.js +3 -0
- package/package.json +6 -5
package/lib/MySQL/connector.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import mysql, { Pool } from 'mysql2/promise';
|
|
2
|
-
import { TxnOption } from 'oak-domain/lib/types';
|
|
3
|
-
import { MySQLConfiguration } from './types/Configuration';
|
|
4
|
-
export declare class MySqlConnector {
|
|
5
|
-
pool: Pool;
|
|
6
|
-
configuration: MySQLConfiguration;
|
|
7
|
-
txnDict: Record<string, mysql.PoolConnection>;
|
|
8
|
-
constructor(configuration: MySQLConfiguration);
|
|
9
|
-
connect(): void;
|
|
10
|
-
disconnect(): Promise<void>;
|
|
11
|
-
startTransaction(option?: TxnOption): Promise<string>;
|
|
12
|
-
exec(sql: string, txn?: string): Promise<[mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket | mysql.OkPacket[] | mysql.ResultSetHeader, mysql.FieldPacket[]]>;
|
|
13
|
-
commitTransaction(txn: string): Promise<void>;
|
|
14
|
-
rollbackTransaction(txn: string): Promise<void>;
|
|
15
|
-
}
|
|
1
|
+
import mysql, { Pool } from 'mysql2/promise';
|
|
2
|
+
import { TxnOption } from 'oak-domain/lib/types';
|
|
3
|
+
import { MySQLConfiguration } from './types/Configuration';
|
|
4
|
+
export declare class MySqlConnector {
|
|
5
|
+
pool: Pool;
|
|
6
|
+
configuration: MySQLConfiguration;
|
|
7
|
+
txnDict: Record<string, mysql.PoolConnection>;
|
|
8
|
+
constructor(configuration: MySQLConfiguration);
|
|
9
|
+
connect(): void;
|
|
10
|
+
disconnect(): Promise<void>;
|
|
11
|
+
startTransaction(option?: TxnOption): Promise<string>;
|
|
12
|
+
exec(sql: string, txn?: string): Promise<[mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket | mysql.OkPacket[] | mysql.ResultSetHeader, mysql.FieldPacket[]]>;
|
|
13
|
+
commitTransaction(txn: string): Promise<void>;
|
|
14
|
+
rollbackTransaction(txn: string): Promise<void>;
|
|
15
|
+
}
|
package/lib/MySQL/connector.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MySqlConnector = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const promise_1 = tslib_1.__importDefault(require("mysql2/promise"));
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
-
class MySqlConnector {
|
|
9
|
-
pool;
|
|
10
|
-
configuration;
|
|
11
|
-
txnDict;
|
|
12
|
-
constructor(configuration) {
|
|
13
|
-
this.configuration = configuration;
|
|
14
|
-
this.txnDict = {};
|
|
15
|
-
this.pool = promise_1.default.createPool(this.configuration);
|
|
16
|
-
}
|
|
17
|
-
connect() {
|
|
18
|
-
}
|
|
19
|
-
disconnect() {
|
|
20
|
-
return this.pool.end();
|
|
21
|
-
}
|
|
22
|
-
async startTransaction(option) {
|
|
23
|
-
// 防止用户配置connection可复用
|
|
24
|
-
const startInner = async () => {
|
|
25
|
-
const connection = await this.pool.getConnection();
|
|
26
|
-
// 分配出来的connection不能被别的事务占据
|
|
27
|
-
for (const txn2 in this.txnDict) {
|
|
28
|
-
if (this.txnDict[txn2] === connection) {
|
|
29
|
-
return new Promise((resolve) => {
|
|
30
|
-
this.pool.on('release', () => resolve(startInner()));
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
await connection.beginTransaction();
|
|
35
|
-
const id = (0, uuid_1.v4)();
|
|
36
|
-
// console.log('start_txn', id, connection.threadId);
|
|
37
|
-
this.txnDict[id] = connection;
|
|
38
|
-
if (option?.isolationLevel) {
|
|
39
|
-
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${option.isolationLevel};`);
|
|
40
|
-
}
|
|
41
|
-
return id;
|
|
42
|
-
};
|
|
43
|
-
return startInner();
|
|
44
|
-
}
|
|
45
|
-
async exec(sql, txn) {
|
|
46
|
-
if (process.env.NODE_ENV === 'development') {
|
|
47
|
-
// console.log(sql);
|
|
48
|
-
}
|
|
49
|
-
if (txn) {
|
|
50
|
-
const connection = this.txnDict[txn];
|
|
51
|
-
(0, assert_1.default)(connection);
|
|
52
|
-
const result = await connection.query(sql);
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const result = await this.pool.query(sql);
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async commitTransaction(txn) {
|
|
61
|
-
const connection = this.txnDict[txn];
|
|
62
|
-
(0, assert_1.default)(connection);
|
|
63
|
-
delete this.txnDict[txn];
|
|
64
|
-
// console.log('commit_txn', txn, connection.threadId);
|
|
65
|
-
await connection.commit();
|
|
66
|
-
connection.release();
|
|
67
|
-
}
|
|
68
|
-
async rollbackTransaction(txn) {
|
|
69
|
-
const connection = this.txnDict[txn];
|
|
70
|
-
(0, assert_1.default)(connection);
|
|
71
|
-
// console.log('rollback_txn', txn, connection.threadId);
|
|
72
|
-
await connection.rollback();
|
|
73
|
-
delete this.txnDict[txn];
|
|
74
|
-
connection.release();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.MySqlConnector = MySqlConnector;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlConnector = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const promise_1 = tslib_1.__importDefault(require("mysql2/promise"));
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
+
class MySqlConnector {
|
|
9
|
+
pool;
|
|
10
|
+
configuration;
|
|
11
|
+
txnDict;
|
|
12
|
+
constructor(configuration) {
|
|
13
|
+
this.configuration = configuration;
|
|
14
|
+
this.txnDict = {};
|
|
15
|
+
this.pool = promise_1.default.createPool(this.configuration);
|
|
16
|
+
}
|
|
17
|
+
connect() {
|
|
18
|
+
}
|
|
19
|
+
disconnect() {
|
|
20
|
+
return this.pool.end();
|
|
21
|
+
}
|
|
22
|
+
async startTransaction(option) {
|
|
23
|
+
// 防止用户配置connection可复用
|
|
24
|
+
const startInner = async () => {
|
|
25
|
+
const connection = await this.pool.getConnection();
|
|
26
|
+
// 分配出来的connection不能被别的事务占据
|
|
27
|
+
for (const txn2 in this.txnDict) {
|
|
28
|
+
if (this.txnDict[txn2] === connection) {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
this.pool.on('release', () => resolve(startInner()));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
await connection.beginTransaction();
|
|
35
|
+
const id = (0, uuid_1.v4)();
|
|
36
|
+
// console.log('start_txn', id, connection.threadId);
|
|
37
|
+
this.txnDict[id] = connection;
|
|
38
|
+
if (option?.isolationLevel) {
|
|
39
|
+
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${option.isolationLevel};`);
|
|
40
|
+
}
|
|
41
|
+
return id;
|
|
42
|
+
};
|
|
43
|
+
return startInner();
|
|
44
|
+
}
|
|
45
|
+
async exec(sql, txn) {
|
|
46
|
+
if (process.env.NODE_ENV === 'development') {
|
|
47
|
+
// console.log(`${sql}; \n`);
|
|
48
|
+
}
|
|
49
|
+
if (txn) {
|
|
50
|
+
const connection = this.txnDict[txn];
|
|
51
|
+
(0, assert_1.default)(connection);
|
|
52
|
+
const result = await connection.query(sql);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const result = await this.pool.query(sql);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async commitTransaction(txn) {
|
|
61
|
+
const connection = this.txnDict[txn];
|
|
62
|
+
(0, assert_1.default)(connection);
|
|
63
|
+
delete this.txnDict[txn];
|
|
64
|
+
// console.log('commit_txn', txn, connection.threadId);
|
|
65
|
+
await connection.commit();
|
|
66
|
+
connection.release();
|
|
67
|
+
}
|
|
68
|
+
async rollbackTransaction(txn) {
|
|
69
|
+
const connection = this.txnDict[txn];
|
|
70
|
+
(0, assert_1.default)(connection);
|
|
71
|
+
// console.log('rollback_txn', txn, connection.threadId);
|
|
72
|
+
await connection.rollback();
|
|
73
|
+
delete this.txnDict[txn];
|
|
74
|
+
connection.release();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.MySqlConnector = MySqlConnector;
|
package/lib/MySQL/store.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { EntityDict, OperateOption, OperationResult, TxnOption, StorageSchema, SelectOption, AggregationResult } from 'oak-domain/lib/types';
|
|
1
|
+
import { EntityDict, OperateOption, OperationResult, TxnOption, StorageSchema, SelectOption, AggregationResult, Attribute, Index } 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
|
-
import { AsyncContext
|
|
7
|
+
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
|
8
8
|
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
|
9
9
|
import { CreateEntityOption } from '../types/Translator';
|
|
10
|
-
|
|
10
|
+
import { DbStore } from '../types/dbStore';
|
|
11
|
+
export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends CascadeStore<ED> implements DbStore<ED, Cxt> {
|
|
11
12
|
protected countAbjointRow<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): number;
|
|
12
13
|
protected aggregateAbjointRowSync<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): AggregationResult<ED[T]['Schema']>;
|
|
13
14
|
protected selectAbjointRow<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: SyncContext<ED>, option: OP): Partial<ED[T]['Schema']>[];
|
|
@@ -31,7 +32,32 @@ export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt exte
|
|
|
31
32
|
begin(option?: TxnOption): Promise<string>;
|
|
32
33
|
commit(txnId: string): Promise<void>;
|
|
33
34
|
rollback(txnId: string): Promise<void>;
|
|
34
|
-
connect(): void
|
|
35
|
+
connect(): Promise<void>;
|
|
35
36
|
disconnect(): Promise<void>;
|
|
36
37
|
initialize(option: CreateEntityOption): Promise<void>;
|
|
38
|
+
readSchema(): Promise<StorageSchema<ED>>;
|
|
39
|
+
/**
|
|
40
|
+
* 根据载入的dataSchema,和数据库中原来的schema,决定如何来upgrade
|
|
41
|
+
* 制订出来的plan分为两阶段:增加阶段和削减阶段,在两个阶段之间,由用户来修正数据
|
|
42
|
+
*/
|
|
43
|
+
makeUpgradePlan(): Promise<Plan>;
|
|
44
|
+
/**
|
|
45
|
+
* 比较两个schema的不同,这里计算的是new对old的增量
|
|
46
|
+
* @param schemaOld
|
|
47
|
+
* @param SchemaNew
|
|
48
|
+
*/
|
|
49
|
+
diffSchema(schemaOld: StorageSchema<any>, schemaNew: StorageSchema<any>): Plan;
|
|
37
50
|
}
|
|
51
|
+
type Plan = {
|
|
52
|
+
newTables: Record<string, {
|
|
53
|
+
attributes: Record<string, Attribute>;
|
|
54
|
+
}>;
|
|
55
|
+
newIndexes: Record<string, Index<any>[]>;
|
|
56
|
+
updatedTables: Record<string, {
|
|
57
|
+
attributes: Record<string, Attribute & {
|
|
58
|
+
isNew: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
}>;
|
|
61
|
+
updatedIndexes: Record<string, Index<any>[]>;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
package/lib/MySQL/store.js
CHANGED
|
@@ -209,7 +209,7 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
209
209
|
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
210
210
|
// assert(schema[e].toModi || r[`${attr}Id`] === r[attr].id, `对象${<string>e}取数据时,发现其外键与连接的对象的主键不一致,rowId是${r.id},其${attr}Id值为${r[`${attr}Id`]},连接的对象的主键为${r[attr].id}`);
|
|
211
211
|
if (r[attr].id === null) {
|
|
212
|
-
(0, assert_1.default)(schema[e].toModi || r[`${attr}Id`] === null);
|
|
212
|
+
(0, assert_1.default)(schema[e].toModi || r[`${attr}Id`] === null, `对象${String(e)}取数据时,发现其外键找不到目标对象,rowId是${r.id},其外键${attr}Id值为${r[`${attr}Id`]}`);
|
|
213
213
|
delete r[attr];
|
|
214
214
|
continue;
|
|
215
215
|
}
|
|
@@ -289,8 +289,8 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
289
289
|
async rollback(txnId) {
|
|
290
290
|
await this.connector.rollbackTransaction(txnId);
|
|
291
291
|
}
|
|
292
|
-
connect() {
|
|
293
|
-
this.connector.connect();
|
|
292
|
+
async connect() {
|
|
293
|
+
await this.connector.connect();
|
|
294
294
|
}
|
|
295
295
|
async disconnect() {
|
|
296
296
|
await this.connector.disconnect();
|
|
@@ -304,5 +304,127 @@ class MysqlStore extends CascadeStore_1.CascadeStore {
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
+
// 从数据库中读取当前schema
|
|
308
|
+
readSchema() {
|
|
309
|
+
return this.translator.readSchema((sql) => this.connector.exec(sql));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* 根据载入的dataSchema,和数据库中原来的schema,决定如何来upgrade
|
|
313
|
+
* 制订出来的plan分为两阶段:增加阶段和削减阶段,在两个阶段之间,由用户来修正数据
|
|
314
|
+
*/
|
|
315
|
+
async makeUpgradePlan() {
|
|
316
|
+
const originSchema = await this.readSchema();
|
|
317
|
+
const plan = this.diffSchema(originSchema, this.translator.schema);
|
|
318
|
+
return plan;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* 比较两个schema的不同,这里计算的是new对old的增量
|
|
322
|
+
* @param schemaOld
|
|
323
|
+
* @param SchemaNew
|
|
324
|
+
*/
|
|
325
|
+
diffSchema(schemaOld, schemaNew) {
|
|
326
|
+
const plan = {
|
|
327
|
+
newTables: {},
|
|
328
|
+
newIndexes: {},
|
|
329
|
+
updatedIndexes: {},
|
|
330
|
+
updatedTables: {},
|
|
331
|
+
};
|
|
332
|
+
for (const table in schemaNew) {
|
|
333
|
+
// mysql数据字典不分大小写的
|
|
334
|
+
if (schemaOld[table] || schemaOld[table.toLowerCase()]) {
|
|
335
|
+
const { attributes, indexes } = schemaOld[table] || schemaOld[table.toLowerCase()];
|
|
336
|
+
const { attributes: attributesNew, indexes: indexesNew } = schemaNew[table];
|
|
337
|
+
const assignToUpdateTables = (attr, isNew) => {
|
|
338
|
+
if (!plan.updatedTables[table]) {
|
|
339
|
+
plan.updatedTables[table] = {
|
|
340
|
+
attributes: {
|
|
341
|
+
[attr]: {
|
|
342
|
+
...attributesNew[attr],
|
|
343
|
+
isNew,
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
plan.updatedTables[table].attributes[attr] = {
|
|
350
|
+
...attributesNew[attr],
|
|
351
|
+
isNew,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
for (const attr in attributesNew) {
|
|
356
|
+
if (attributes[attr]) {
|
|
357
|
+
// 因为反向无法复原原来定义的attribute类型,这里就比较两次创建的sql是不是一致。
|
|
358
|
+
const sql1 = this.translator.translateAttributeDef(attr, attributesNew[attr]);
|
|
359
|
+
const sql2 = this.translator.translateAttributeDef(attr, attributes[attr]);
|
|
360
|
+
if (!this.translator.compareSql(sql1, sql2)) {
|
|
361
|
+
assignToUpdateTables(attr, false);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
assignToUpdateTables(attr, true);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (indexesNew) {
|
|
369
|
+
const assignToIndexes = (index, isNew) => {
|
|
370
|
+
if (isNew) {
|
|
371
|
+
if (plan.newIndexes[table]) {
|
|
372
|
+
plan.newIndexes[table].push(index);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
plan.newIndexes[table] = [index];
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
if (plan.updatedIndexes[table]) {
|
|
380
|
+
plan.updatedIndexes[table].push(index);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
plan.updatedIndexes[table] = [index];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const compareConfig = (config1, config2) => {
|
|
388
|
+
const unique1 = config1?.unique || false;
|
|
389
|
+
const unique2 = config2?.unique || false;
|
|
390
|
+
if (unique1 !== unique2) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
const type1 = config1?.type || 'btree';
|
|
394
|
+
const type2 = config2?.type || 'btree';
|
|
395
|
+
// parser目前无法从mysql中读出来,所以不比了
|
|
396
|
+
return type1 === type2;
|
|
397
|
+
};
|
|
398
|
+
for (const index of indexesNew) {
|
|
399
|
+
const { name, config, attributes } = index;
|
|
400
|
+
const origin = indexes?.find(ele => ele.name === name);
|
|
401
|
+
if (origin) {
|
|
402
|
+
if (JSON.stringify(attributes) !== JSON.stringify(origin.attributes)) {
|
|
403
|
+
// todo,这里要细致比较,不能用json.stringify
|
|
404
|
+
assignToIndexes(index, false);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
if (!compareConfig(config, origin.config)) {
|
|
408
|
+
assignToIndexes(index, false);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
assignToIndexes(index, true);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
plan.newTables[table] = {
|
|
420
|
+
attributes: schemaNew[table].attributes,
|
|
421
|
+
};
|
|
422
|
+
if (schemaNew[table].indexes) {
|
|
423
|
+
plan.newIndexes[table] = schemaNew[table].indexes;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return plan;
|
|
428
|
+
}
|
|
307
429
|
}
|
|
308
430
|
exports.MysqlStore = MysqlStore;
|
|
@@ -1,107 +1,114 @@
|
|
|
1
|
-
import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema } from "oak-domain/lib/types";
|
|
2
|
-
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
3
|
-
import { DataType } from "oak-domain/lib/types/schema/DataTypes";
|
|
4
|
-
import { SqlOperateOption, SqlSelectOption, SqlTranslator } from "../sqlTranslator";
|
|
5
|
-
import { CreateEntityOption } from '../types/Translator';
|
|
6
|
-
export interface MySqlSelectOption extends SqlSelectOption {
|
|
7
|
-
}
|
|
8
|
-
export interface MysqlOperateOption extends SqlOperateOption {
|
|
9
|
-
}
|
|
10
|
-
export declare class MySqlTranslator<ED extends EntityDict & BaseEntityDict> extends SqlTranslator<ED> {
|
|
11
|
-
protected getDefaultSelectFilter(alias: string, option?: MySqlSelectOption): string;
|
|
12
|
-
private makeUpSchema;
|
|
13
|
-
constructor(schema: StorageSchema<ED>);
|
|
14
|
-
static supportedDataTypes: DataType[];
|
|
15
|
-
static spatialTypes: DataType[];
|
|
16
|
-
static withLengthDataTypes: DataType[];
|
|
17
|
-
static withPrecisionDataTypes: DataType[];
|
|
18
|
-
static withScaleDataTypes: DataType[];
|
|
19
|
-
static unsignedAndZerofillTypes: DataType[];
|
|
20
|
-
static withWidthDataTypes: DataType[];
|
|
21
|
-
static dataTypeDefaults: {
|
|
22
|
-
varchar: {
|
|
23
|
-
length: number;
|
|
24
|
-
};
|
|
25
|
-
nvarchar: {
|
|
26
|
-
length: number;
|
|
27
|
-
};
|
|
28
|
-
"national varchar": {
|
|
29
|
-
length: number;
|
|
30
|
-
};
|
|
31
|
-
char: {
|
|
32
|
-
length: number;
|
|
33
|
-
};
|
|
34
|
-
binary: {
|
|
35
|
-
length: number;
|
|
36
|
-
};
|
|
37
|
-
varbinary: {
|
|
38
|
-
length: number;
|
|
39
|
-
};
|
|
40
|
-
decimal: {
|
|
41
|
-
precision: number;
|
|
42
|
-
scale: number;
|
|
43
|
-
};
|
|
44
|
-
dec: {
|
|
45
|
-
precision: number;
|
|
46
|
-
scale: number;
|
|
47
|
-
};
|
|
48
|
-
numeric: {
|
|
49
|
-
precision: number;
|
|
50
|
-
scale: number;
|
|
51
|
-
};
|
|
52
|
-
fixed: {
|
|
53
|
-
precision: number;
|
|
54
|
-
scale: number;
|
|
55
|
-
};
|
|
56
|
-
float: {
|
|
57
|
-
precision: number;
|
|
58
|
-
};
|
|
59
|
-
double: {
|
|
60
|
-
precision: number;
|
|
61
|
-
};
|
|
62
|
-
time: {
|
|
63
|
-
precision: number;
|
|
64
|
-
};
|
|
65
|
-
datetime: {
|
|
66
|
-
precision: number;
|
|
67
|
-
};
|
|
68
|
-
timestamp: {
|
|
69
|
-
precision: number;
|
|
70
|
-
};
|
|
71
|
-
bit: {
|
|
72
|
-
width: number;
|
|
73
|
-
};
|
|
74
|
-
int: {
|
|
75
|
-
width: number;
|
|
76
|
-
};
|
|
77
|
-
integer: {
|
|
78
|
-
width: number;
|
|
79
|
-
};
|
|
80
|
-
tinyint: {
|
|
81
|
-
width: number;
|
|
82
|
-
};
|
|
83
|
-
smallint: {
|
|
84
|
-
width: number;
|
|
85
|
-
};
|
|
86
|
-
mediumint: {
|
|
87
|
-
width: number;
|
|
88
|
-
};
|
|
89
|
-
bigint: {
|
|
90
|
-
width: number;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
maxAliasLength: number;
|
|
94
|
-
private populateDataTypeDef;
|
|
95
|
-
protected translateAttrProjection(dataType: DataType, alias: string, attr: string): string;
|
|
96
|
-
protected translateObjectPredicate(predicate: Record<string, any>, alias: string, attr: string): string;
|
|
97
|
-
protected translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
|
|
98
|
-
protected translateAttrValue(dataType: DataType | Ref, value: any): string;
|
|
99
|
-
protected translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
private
|
|
103
|
-
|
|
104
|
-
protected
|
|
105
|
-
protected
|
|
106
|
-
protected
|
|
107
|
-
|
|
1
|
+
import { EntityDict, Q_FullTextValue, RefOrExpression, Ref, StorageSchema, Attribute } from "oak-domain/lib/types";
|
|
2
|
+
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
3
|
+
import { DataType } from "oak-domain/lib/types/schema/DataTypes";
|
|
4
|
+
import { SqlOperateOption, SqlSelectOption, SqlTranslator } from "../sqlTranslator";
|
|
5
|
+
import { CreateEntityOption } from '../types/Translator';
|
|
6
|
+
export interface MySqlSelectOption extends SqlSelectOption {
|
|
7
|
+
}
|
|
8
|
+
export interface MysqlOperateOption extends SqlOperateOption {
|
|
9
|
+
}
|
|
10
|
+
export declare class MySqlTranslator<ED extends EntityDict & BaseEntityDict> extends SqlTranslator<ED> {
|
|
11
|
+
protected getDefaultSelectFilter(alias: string, option?: MySqlSelectOption): string;
|
|
12
|
+
private makeUpSchema;
|
|
13
|
+
constructor(schema: StorageSchema<ED>);
|
|
14
|
+
static supportedDataTypes: DataType[];
|
|
15
|
+
static spatialTypes: DataType[];
|
|
16
|
+
static withLengthDataTypes: DataType[];
|
|
17
|
+
static withPrecisionDataTypes: DataType[];
|
|
18
|
+
static withScaleDataTypes: DataType[];
|
|
19
|
+
static unsignedAndZerofillTypes: DataType[];
|
|
20
|
+
static withWidthDataTypes: DataType[];
|
|
21
|
+
static dataTypeDefaults: {
|
|
22
|
+
varchar: {
|
|
23
|
+
length: number;
|
|
24
|
+
};
|
|
25
|
+
nvarchar: {
|
|
26
|
+
length: number;
|
|
27
|
+
};
|
|
28
|
+
"national varchar": {
|
|
29
|
+
length: number;
|
|
30
|
+
};
|
|
31
|
+
char: {
|
|
32
|
+
length: number;
|
|
33
|
+
};
|
|
34
|
+
binary: {
|
|
35
|
+
length: number;
|
|
36
|
+
};
|
|
37
|
+
varbinary: {
|
|
38
|
+
length: number;
|
|
39
|
+
};
|
|
40
|
+
decimal: {
|
|
41
|
+
precision: number;
|
|
42
|
+
scale: number;
|
|
43
|
+
};
|
|
44
|
+
dec: {
|
|
45
|
+
precision: number;
|
|
46
|
+
scale: number;
|
|
47
|
+
};
|
|
48
|
+
numeric: {
|
|
49
|
+
precision: number;
|
|
50
|
+
scale: number;
|
|
51
|
+
};
|
|
52
|
+
fixed: {
|
|
53
|
+
precision: number;
|
|
54
|
+
scale: number;
|
|
55
|
+
};
|
|
56
|
+
float: {
|
|
57
|
+
precision: number;
|
|
58
|
+
};
|
|
59
|
+
double: {
|
|
60
|
+
precision: number;
|
|
61
|
+
};
|
|
62
|
+
time: {
|
|
63
|
+
precision: number;
|
|
64
|
+
};
|
|
65
|
+
datetime: {
|
|
66
|
+
precision: number;
|
|
67
|
+
};
|
|
68
|
+
timestamp: {
|
|
69
|
+
precision: number;
|
|
70
|
+
};
|
|
71
|
+
bit: {
|
|
72
|
+
width: number;
|
|
73
|
+
};
|
|
74
|
+
int: {
|
|
75
|
+
width: number;
|
|
76
|
+
};
|
|
77
|
+
integer: {
|
|
78
|
+
width: number;
|
|
79
|
+
};
|
|
80
|
+
tinyint: {
|
|
81
|
+
width: number;
|
|
82
|
+
};
|
|
83
|
+
smallint: {
|
|
84
|
+
width: number;
|
|
85
|
+
};
|
|
86
|
+
mediumint: {
|
|
87
|
+
width: number;
|
|
88
|
+
};
|
|
89
|
+
bigint: {
|
|
90
|
+
width: number;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
maxAliasLength: number;
|
|
94
|
+
private populateDataTypeDef;
|
|
95
|
+
protected translateAttrProjection(dataType: DataType, alias: string, attr: string): string;
|
|
96
|
+
protected translateObjectPredicate(predicate: Record<string, any>, alias: string, attr: string): string;
|
|
97
|
+
protected translateObjectProjection(projection: Record<string, any>, alias: string, attr: string, prefix: string): string;
|
|
98
|
+
protected translateAttrValue(dataType: DataType | Ref, value: any): string;
|
|
99
|
+
protected translateFullTextSearch<T extends keyof ED>(value: Q_FullTextValue, entity: T, alias: string): string;
|
|
100
|
+
translateAttributeDef(attr: string, attrDef: Attribute): string;
|
|
101
|
+
translateCreateEntity<T extends keyof ED>(entity: T, options?: CreateEntityOption): string[];
|
|
102
|
+
private translateFnName;
|
|
103
|
+
private translateAttrInExpression;
|
|
104
|
+
protected translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]["OpSchema"]>, refDict: Record<string, [string, keyof ED]>): string;
|
|
105
|
+
protected populateSelectStmt<T extends keyof ED>(projectionText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, groupByText?: string, indexFrom?: number, count?: number, option?: MySqlSelectOption): string;
|
|
106
|
+
protected populateUpdateStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string;
|
|
107
|
+
protected populateRemoveStmt(updateText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string;
|
|
108
|
+
/**
|
|
109
|
+
* 将MySQL返回的Type回译成oak的类型,是 populateDataTypeDef 的反函数
|
|
110
|
+
* @param type
|
|
111
|
+
*/
|
|
112
|
+
private reTranslateToAttribute;
|
|
113
|
+
readSchema(execFn: (sql: string) => Promise<any>): Promise<StorageSchema<ED>>;
|
|
114
|
+
}
|