@eggjs/dal-decorator 4.0.0-beta.4 → 4.0.0-beta.6
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/README.md +13 -1
- package/dist/decorator/Column.d.ts +6 -0
- package/dist/decorator/Column.js +17 -0
- package/dist/decorator/Dao.d.ts +6 -0
- package/dist/decorator/Dao.js +20 -0
- package/dist/decorator/DataSourceQualifier.d.ts +4 -0
- package/dist/decorator/DataSourceQualifier.js +12 -0
- package/dist/decorator/Table.d.ts +6 -0
- package/dist/decorator/Table.js +21 -0
- package/dist/decorator/TableIndex.d.ts +6 -0
- package/dist/decorator/TableIndex.js +12 -0
- package/dist/decorator/index.js +7 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +21 -0
- package/dist/model/ColumnModel.d.ts +38 -0
- package/dist/model/ColumnModel.js +59 -0
- package/dist/model/IndexModel.d.ts +32 -0
- package/dist/model/IndexModel.js +52 -0
- package/dist/model/TableModel.d.ts +55 -0
- package/dist/model/TableModel.js +116 -0
- package/dist/model/index.js +5 -0
- package/dist/type/MySql.d.ts +2 -0
- package/dist/type/Spatial.d.ts +14 -0
- package/dist/type/Spatial.js +31 -0
- package/dist/type/index.js +3 -0
- package/dist/util/ColumnInfoUtil.d.ts +13 -0
- package/dist/util/ColumnInfoUtil.js +21 -0
- package/dist/util/DaoInfoUtil.d.ts +9 -0
- package/dist/util/DaoInfoUtil.js +15 -0
- package/dist/util/IndexInfoUtil.d.ts +9 -0
- package/dist/util/IndexInfoUtil.js +15 -0
- package/dist/util/TableInfoUtil.d.ts +13 -0
- package/dist/util/TableInfoUtil.js +26 -0
- package/dist/util/index.js +6 -0
- package/package.json +23 -24
- package/src/decorator/Column.d.ts +0 -2
- package/src/decorator/Column.js +0 -14
- package/src/decorator/Dao.d.ts +0 -2
- package/src/decorator/Dao.js +0 -16
- package/src/decorator/DataSourceQualifier.d.ts +0 -1
- package/src/decorator/DataSourceQualifier.js +0 -8
- package/src/decorator/Table.d.ts +0 -2
- package/src/decorator/Table.js +0 -19
- package/src/decorator/TableIndex.d.ts +0 -2
- package/src/decorator/TableIndex.js +0 -7
- package/src/decorator/index.d.ts +0 -5
- package/src/decorator/index.js +0 -6
- package/src/index.d.ts +0 -5
- package/src/index.js +0 -6
- package/src/model/ColumnModel.d.ts +0 -34
- package/src/model/ColumnModel.js +0 -57
- package/src/model/IndexModel.d.ts +0 -29
- package/src/model/IndexModel.js +0 -50
- package/src/model/TableModel.d.ts +0 -51
- package/src/model/TableModel.js +0 -113
- package/src/model/index.d.ts +0 -3
- package/src/model/index.js +0 -4
- package/src/type/MySql.d.ts +0 -1
- package/src/type/MySql.js +0 -2
- package/src/type/Spatial.d.ts +0 -11
- package/src/type/Spatial.js +0 -31
- package/src/type/index.d.ts +0 -2
- package/src/type/index.js +0 -3
- package/src/util/ColumnInfoUtil.d.ts +0 -9
- package/src/util/ColumnInfoUtil.js +0 -19
- package/src/util/DaoInfoUtil.d.ts +0 -6
- package/src/util/DaoInfoUtil.js +0 -11
- package/src/util/IndexInfoUtil.d.ts +0 -5
- package/src/util/IndexInfoUtil.js +0 -12
- package/src/util/TableInfoUtil.d.ts +0 -9
- package/src/util/TableInfoUtil.js +0 -23
- package/src/util/index.d.ts +0 -4
- package/src/util/index.js +0 -5
package/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# `@eggjs/dal-decorator`
|
|
2
2
|
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
|
5
|
+
[![npm download][download-image]][download-url]
|
|
6
|
+
[](https://nodejs.org/en/download/)
|
|
7
|
+
|
|
8
|
+
[npm-image]: https://img.shields.io/npm/v/@eggjs/dal-decorator.svg?style=flat-square
|
|
9
|
+
[npm-url]: https://npmjs.org/package/@eggjs/dal-decorator
|
|
10
|
+
[snyk-image]: https://snyk.io/test/npm/@eggjs/dal-decorator/badge.svg?style=flat-square
|
|
11
|
+
[snyk-url]: https://snyk.io/test/npm/@eggjs/dal-decorator
|
|
12
|
+
[download-image]: https://img.shields.io/npm/dm/@eggjs/dal-decorator.svg?style=flat-square
|
|
13
|
+
[download-url]: https://npmjs.org/package/@eggjs/dal-decorator
|
|
14
|
+
|
|
3
15
|
## Usage
|
|
4
16
|
|
|
5
|
-
Please read [@eggjs/tegg-dal-plugin](../../plugin/dal
|
|
17
|
+
Please read [@eggjs/tegg-dal-plugin](../../plugin/dal/README.md)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ColumnInfoUtil } from "../util/ColumnInfoUtil.js";
|
|
2
|
+
import "../util/index.js";
|
|
3
|
+
import assert from "node:assert";
|
|
4
|
+
|
|
5
|
+
//#region src/decorator/Column.ts
|
|
6
|
+
function Column(type, params) {
|
|
7
|
+
return function(target, propertyKey) {
|
|
8
|
+
assert(typeof propertyKey === "string", `[Column/${target.name}] expect column name be typeof string, but now is ${String(propertyKey)}`);
|
|
9
|
+
const tableClazz = target.constructor;
|
|
10
|
+
const columnName = propertyKey;
|
|
11
|
+
ColumnInfoUtil.addColumnType(tableClazz, columnName, type);
|
|
12
|
+
if (params) ColumnInfoUtil.addColumnInfo(tableClazz, columnName, params);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Column };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DaoInfoUtil } from "../util/DaoInfoUtil.js";
|
|
2
|
+
import "../util/index.js";
|
|
3
|
+
import { AccessLevel, ObjectInitType } from "@eggjs/tegg-types";
|
|
4
|
+
import { Prototype, PrototypeUtil } from "@eggjs/core-decorator";
|
|
5
|
+
import { StackUtil } from "@eggjs/tegg-common-util";
|
|
6
|
+
|
|
7
|
+
//#region src/decorator/Dao.ts
|
|
8
|
+
function Dao() {
|
|
9
|
+
return function(constructor) {
|
|
10
|
+
DaoInfoUtil.setIsDao(constructor);
|
|
11
|
+
Prototype({
|
|
12
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
13
|
+
initType: ObjectInitType.SINGLETON
|
|
14
|
+
})(constructor);
|
|
15
|
+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Dao };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataSourceQualifierAttribute } from "@eggjs/tegg-types";
|
|
2
|
+
import { QualifierUtil } from "@eggjs/core-decorator";
|
|
3
|
+
|
|
4
|
+
//#region src/decorator/DataSourceQualifier.ts
|
|
5
|
+
function DataSourceQualifier(dataSourceName) {
|
|
6
|
+
return function(target, propertyKey, parameterIndex) {
|
|
7
|
+
QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, DataSourceQualifierAttribute, dataSourceName);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DataSourceQualifier };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TableInfoUtil } from "../util/TableInfoUtil.js";
|
|
2
|
+
import "../util/index.js";
|
|
3
|
+
import { AccessLevel, ObjectInitType } from "@eggjs/tegg-types";
|
|
4
|
+
import { Prototype, PrototypeUtil } from "@eggjs/core-decorator";
|
|
5
|
+
import { StackUtil } from "@eggjs/tegg-common-util";
|
|
6
|
+
|
|
7
|
+
//#region src/decorator/Table.ts
|
|
8
|
+
function Table(params) {
|
|
9
|
+
return function(constructor) {
|
|
10
|
+
TableInfoUtil.setIsTable(constructor);
|
|
11
|
+
if (params) TableInfoUtil.setTableParams(constructor, params);
|
|
12
|
+
Prototype({
|
|
13
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
14
|
+
initType: ObjectInitType.ALWAYS_NEW
|
|
15
|
+
})(constructor);
|
|
16
|
+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Table };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IndexInfoUtil } from "../util/IndexInfoUtil.js";
|
|
2
|
+
import "../util/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/decorator/TableIndex.ts
|
|
5
|
+
function Index(params) {
|
|
6
|
+
return function(constructor) {
|
|
7
|
+
IndexInfoUtil.addIndex(constructor, params);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Index };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Column } from "./decorator/Column.js";
|
|
2
|
+
import { Dao } from "./decorator/Dao.js";
|
|
3
|
+
import { DataSourceQualifier } from "./decorator/DataSourceQualifier.js";
|
|
4
|
+
import { Table } from "./decorator/Table.js";
|
|
5
|
+
import { Index } from "./decorator/TableIndex.js";
|
|
6
|
+
import { ColumnModel } from "./model/ColumnModel.js";
|
|
7
|
+
import { IndexKey, IndexModel } from "./model/IndexModel.js";
|
|
8
|
+
import { TableModel } from "./model/TableModel.js";
|
|
9
|
+
import { DeleteResult, InsertResult, UpdateResult } from "./type/MySql.js";
|
|
10
|
+
import { SpatialHelper } from "./type/Spatial.js";
|
|
11
|
+
import { ColumnInfoMap, ColumnInfoUtil, ColumnTypeMap } from "./util/ColumnInfoUtil.js";
|
|
12
|
+
import { DaoInfoUtil } from "./util/DaoInfoUtil.js";
|
|
13
|
+
import { IndexInfoUtil } from "./util/IndexInfoUtil.js";
|
|
14
|
+
import { TABLE_CLAZZ_LIST, TableInfoUtil } from "./util/TableInfoUtil.js";
|
|
15
|
+
export * from "@eggjs/tegg-types/dal";
|
|
16
|
+
export { Column, ColumnInfoMap, ColumnInfoUtil, ColumnModel, ColumnTypeMap, Dao, DaoInfoUtil, DataSourceQualifier, DeleteResult, Index, IndexInfoUtil, IndexKey, IndexModel, InsertResult, SpatialHelper, TABLE_CLAZZ_LIST, Table, TableInfoUtil, TableModel, UpdateResult };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ColumnInfoUtil } from "./util/ColumnInfoUtil.js";
|
|
2
|
+
import { DaoInfoUtil } from "./util/DaoInfoUtil.js";
|
|
3
|
+
import { IndexInfoUtil } from "./util/IndexInfoUtil.js";
|
|
4
|
+
import { TABLE_CLAZZ_LIST, TableInfoUtil } from "./util/TableInfoUtil.js";
|
|
5
|
+
import "./util/index.js";
|
|
6
|
+
import { Column } from "./decorator/Column.js";
|
|
7
|
+
import { Dao } from "./decorator/Dao.js";
|
|
8
|
+
import { DataSourceQualifier } from "./decorator/DataSourceQualifier.js";
|
|
9
|
+
import { Table } from "./decorator/Table.js";
|
|
10
|
+
import { Index } from "./decorator/TableIndex.js";
|
|
11
|
+
import "./decorator/index.js";
|
|
12
|
+
import { ColumnModel } from "./model/ColumnModel.js";
|
|
13
|
+
import { IndexModel } from "./model/IndexModel.js";
|
|
14
|
+
import { TableModel } from "./model/TableModel.js";
|
|
15
|
+
import "./model/index.js";
|
|
16
|
+
import { SpatialHelper } from "./type/Spatial.js";
|
|
17
|
+
import "./type/index.js";
|
|
18
|
+
|
|
19
|
+
export * from "@eggjs/tegg-types/dal"
|
|
20
|
+
|
|
21
|
+
export { Column, ColumnInfoUtil, ColumnModel, Dao, DaoInfoUtil, DataSourceQualifier, Index, IndexInfoUtil, IndexModel, SpatialHelper, TABLE_CLAZZ_LIST, Table, TableInfoUtil, TableModel };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ColumnFormat, ColumnParams, ColumnTypeParams } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/model/ColumnModel.d.ts
|
|
4
|
+
declare class ColumnModel {
|
|
5
|
+
columnName: string;
|
|
6
|
+
propertyName: string;
|
|
7
|
+
type: ColumnTypeParams;
|
|
8
|
+
canNull: boolean;
|
|
9
|
+
default?: string;
|
|
10
|
+
comment?: string;
|
|
11
|
+
visible?: boolean;
|
|
12
|
+
autoIncrement?: boolean;
|
|
13
|
+
uniqueKey?: boolean;
|
|
14
|
+
primaryKey?: boolean;
|
|
15
|
+
collate?: string;
|
|
16
|
+
columnFormat?: ColumnFormat;
|
|
17
|
+
engineAttribute?: string;
|
|
18
|
+
secondaryEngineAttribute?: string;
|
|
19
|
+
constructor(params: {
|
|
20
|
+
columnName: string;
|
|
21
|
+
propertyName: string;
|
|
22
|
+
type: ColumnTypeParams;
|
|
23
|
+
canNull: boolean;
|
|
24
|
+
default?: string;
|
|
25
|
+
comment?: string;
|
|
26
|
+
visible?: boolean;
|
|
27
|
+
autoIncrement?: boolean;
|
|
28
|
+
uniqueKey?: boolean;
|
|
29
|
+
primaryKey?: boolean;
|
|
30
|
+
collate?: string;
|
|
31
|
+
columnFormat?: ColumnFormat;
|
|
32
|
+
engineAttribute?: string;
|
|
33
|
+
secondaryEngineAttribute?: string;
|
|
34
|
+
});
|
|
35
|
+
static build(property: string, type: ColumnTypeParams, params?: ColumnParams): ColumnModel;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ColumnModel };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import snakecase from "lodash.snakecase";
|
|
2
|
+
|
|
3
|
+
//#region src/model/ColumnModel.ts
|
|
4
|
+
var ColumnModel = class ColumnModel {
|
|
5
|
+
columnName;
|
|
6
|
+
propertyName;
|
|
7
|
+
type;
|
|
8
|
+
canNull;
|
|
9
|
+
default;
|
|
10
|
+
comment;
|
|
11
|
+
visible;
|
|
12
|
+
autoIncrement;
|
|
13
|
+
uniqueKey;
|
|
14
|
+
primaryKey;
|
|
15
|
+
collate;
|
|
16
|
+
columnFormat;
|
|
17
|
+
engineAttribute;
|
|
18
|
+
secondaryEngineAttribute;
|
|
19
|
+
constructor(params) {
|
|
20
|
+
this.columnName = params.columnName;
|
|
21
|
+
this.propertyName = params.propertyName;
|
|
22
|
+
this.type = params.type;
|
|
23
|
+
this.canNull = params.canNull;
|
|
24
|
+
this.default = params.default;
|
|
25
|
+
this.comment = params.comment;
|
|
26
|
+
this.visible = params.visible;
|
|
27
|
+
this.autoIncrement = params.autoIncrement;
|
|
28
|
+
this.uniqueKey = params.uniqueKey;
|
|
29
|
+
this.primaryKey = params.primaryKey;
|
|
30
|
+
this.collate = params.collate;
|
|
31
|
+
this.columnFormat = params.columnFormat;
|
|
32
|
+
this.engineAttribute = params.engineAttribute;
|
|
33
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
34
|
+
}
|
|
35
|
+
static build(property, type, params) {
|
|
36
|
+
const columnName = params?.name ?? snakecase(property);
|
|
37
|
+
let canNull = params?.canNull ?? false;
|
|
38
|
+
if (params?.primaryKey) canNull = false;
|
|
39
|
+
return new ColumnModel({
|
|
40
|
+
columnName,
|
|
41
|
+
propertyName: property,
|
|
42
|
+
type,
|
|
43
|
+
canNull,
|
|
44
|
+
default: params?.default,
|
|
45
|
+
comment: params?.comment,
|
|
46
|
+
visible: params?.visible,
|
|
47
|
+
autoIncrement: params?.autoIncrement,
|
|
48
|
+
uniqueKey: params?.uniqueKey,
|
|
49
|
+
primaryKey: params?.primaryKey,
|
|
50
|
+
collate: params?.collate,
|
|
51
|
+
columnFormat: params?.columnFormat,
|
|
52
|
+
engineAttribute: params?.engineAttribute,
|
|
53
|
+
secondaryEngineAttribute: params?.secondaryEngineAttribute
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ColumnModel };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ColumnModel } from "./ColumnModel.js";
|
|
2
|
+
import { EggProtoImplClass, IndexParams, IndexStoreType, IndexType } from "@eggjs/tegg-types";
|
|
3
|
+
|
|
4
|
+
//#region src/model/IndexModel.d.ts
|
|
5
|
+
interface IndexKey {
|
|
6
|
+
columnName: string;
|
|
7
|
+
propertyName: string;
|
|
8
|
+
}
|
|
9
|
+
declare class IndexModel {
|
|
10
|
+
name: string;
|
|
11
|
+
keys: IndexKey[];
|
|
12
|
+
type: IndexType;
|
|
13
|
+
storeType?: IndexStoreType;
|
|
14
|
+
comment?: string;
|
|
15
|
+
engineAttribute?: string;
|
|
16
|
+
secondaryEngineAttribute?: string;
|
|
17
|
+
parser?: string;
|
|
18
|
+
constructor(params: {
|
|
19
|
+
name: string;
|
|
20
|
+
keys: IndexKey[];
|
|
21
|
+
type: IndexType;
|
|
22
|
+
storeType?: IndexStoreType;
|
|
23
|
+
comment?: string;
|
|
24
|
+
engineAttribute?: string;
|
|
25
|
+
secondaryEngineAttribute?: string;
|
|
26
|
+
parser?: string;
|
|
27
|
+
});
|
|
28
|
+
static buildIndexName(keys: string[], type: IndexType): string;
|
|
29
|
+
static build(params: IndexParams, columns: ColumnModel[], clazz: EggProtoImplClass<unknown>): IndexModel;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { IndexKey, IndexModel };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import "./ColumnModel.js";
|
|
2
|
+
import { IndexType } from "@eggjs/tegg-types";
|
|
3
|
+
|
|
4
|
+
//#region src/model/IndexModel.ts
|
|
5
|
+
var IndexModel = class IndexModel {
|
|
6
|
+
name;
|
|
7
|
+
keys;
|
|
8
|
+
type;
|
|
9
|
+
storeType;
|
|
10
|
+
comment;
|
|
11
|
+
engineAttribute;
|
|
12
|
+
secondaryEngineAttribute;
|
|
13
|
+
parser;
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this.name = params.name;
|
|
16
|
+
this.keys = params.keys;
|
|
17
|
+
this.type = params.type;
|
|
18
|
+
this.storeType = params.storeType;
|
|
19
|
+
this.comment = params.comment;
|
|
20
|
+
this.engineAttribute = params.engineAttribute;
|
|
21
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
22
|
+
this.parser = params.parser;
|
|
23
|
+
}
|
|
24
|
+
static buildIndexName(keys, type) {
|
|
25
|
+
return (type === IndexType.UNIQUE ? "uk_" : "idx_") + keys.join("_");
|
|
26
|
+
}
|
|
27
|
+
static build(params, columns, clazz) {
|
|
28
|
+
const type = params.type ?? IndexType.INDEX;
|
|
29
|
+
const keys = params.keys.map((t) => {
|
|
30
|
+
const column = columns.find((c) => c.propertyName === t);
|
|
31
|
+
if (!column) throw new Error(`Table ${clazz.name} index configuration error: has no property named "${t}"`);
|
|
32
|
+
return {
|
|
33
|
+
propertyName: column.propertyName,
|
|
34
|
+
columnName: column.columnName
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const name = params.name ?? IndexModel.buildIndexName(keys.map((t) => t.columnName), type);
|
|
38
|
+
return new IndexModel({
|
|
39
|
+
name,
|
|
40
|
+
keys,
|
|
41
|
+
type,
|
|
42
|
+
storeType: params.storeType,
|
|
43
|
+
comment: params.comment,
|
|
44
|
+
engineAttribute: params.engineAttribute,
|
|
45
|
+
secondaryEngineAttribute: params.secondaryEngineAttribute,
|
|
46
|
+
parser: params.parser
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { IndexModel };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ColumnModel } from "./ColumnModel.js";
|
|
2
|
+
import { IndexModel } from "./IndexModel.js";
|
|
3
|
+
import { CompressionType, EggProtoImplClass, InsertMethod, RowFormat } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/model/TableModel.d.ts
|
|
6
|
+
declare class TableModel<T = object> {
|
|
7
|
+
clazz: EggProtoImplClass<T>;
|
|
8
|
+
name: string;
|
|
9
|
+
columns: Array<ColumnModel>;
|
|
10
|
+
indices: Array<IndexModel>;
|
|
11
|
+
dataSourceName: string;
|
|
12
|
+
comment?: string;
|
|
13
|
+
autoExtendSize?: number;
|
|
14
|
+
autoIncrement?: number;
|
|
15
|
+
avgRowLength?: number;
|
|
16
|
+
characterSet?: string;
|
|
17
|
+
collate?: string;
|
|
18
|
+
compression?: CompressionType;
|
|
19
|
+
encryption?: boolean;
|
|
20
|
+
engine?: string;
|
|
21
|
+
engineAttribute?: string;
|
|
22
|
+
insertMethod?: InsertMethod;
|
|
23
|
+
keyBlockSize?: number;
|
|
24
|
+
maxRows?: number;
|
|
25
|
+
minRows?: number;
|
|
26
|
+
rowFormat?: RowFormat;
|
|
27
|
+
secondaryEngineAttribute?: string;
|
|
28
|
+
constructor(params: {
|
|
29
|
+
clazz: EggProtoImplClass<T>;
|
|
30
|
+
name: string;
|
|
31
|
+
dataSourceName: string;
|
|
32
|
+
columns: Array<ColumnModel>;
|
|
33
|
+
indices: Array<IndexModel>;
|
|
34
|
+
comment?: string;
|
|
35
|
+
autoExtendSize?: number;
|
|
36
|
+
autoIncrement?: number;
|
|
37
|
+
avgRowLength?: number;
|
|
38
|
+
characterSet?: string;
|
|
39
|
+
collate?: string;
|
|
40
|
+
compression?: CompressionType;
|
|
41
|
+
encryption?: boolean;
|
|
42
|
+
engine?: string;
|
|
43
|
+
engineAttribute?: string;
|
|
44
|
+
insertMethod?: InsertMethod;
|
|
45
|
+
keyBlockSize?: number;
|
|
46
|
+
maxRows?: number;
|
|
47
|
+
minRows?: number;
|
|
48
|
+
rowFormat?: RowFormat;
|
|
49
|
+
secondaryEngineAttribute?: string;
|
|
50
|
+
});
|
|
51
|
+
getPrimary(): IndexModel | undefined;
|
|
52
|
+
static build<T>(clazz: EggProtoImplClass<T>): TableModel<T>;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { TableModel };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ColumnInfoUtil } from "../util/ColumnInfoUtil.js";
|
|
2
|
+
import { IndexInfoUtil } from "../util/IndexInfoUtil.js";
|
|
3
|
+
import { TableInfoUtil } from "../util/TableInfoUtil.js";
|
|
4
|
+
import "../util/index.js";
|
|
5
|
+
import { ColumnModel } from "./ColumnModel.js";
|
|
6
|
+
import { IndexModel } from "./IndexModel.js";
|
|
7
|
+
import assert from "node:assert";
|
|
8
|
+
import { IndexType } from "@eggjs/tegg-types";
|
|
9
|
+
import snakecase from "lodash.snakecase";
|
|
10
|
+
import pluralize from "pluralize";
|
|
11
|
+
|
|
12
|
+
//#region src/model/TableModel.ts
|
|
13
|
+
var TableModel = class TableModel {
|
|
14
|
+
clazz;
|
|
15
|
+
name;
|
|
16
|
+
columns;
|
|
17
|
+
indices;
|
|
18
|
+
dataSourceName;
|
|
19
|
+
comment;
|
|
20
|
+
autoExtendSize;
|
|
21
|
+
autoIncrement;
|
|
22
|
+
avgRowLength;
|
|
23
|
+
characterSet;
|
|
24
|
+
collate;
|
|
25
|
+
compression;
|
|
26
|
+
encryption;
|
|
27
|
+
engine;
|
|
28
|
+
engineAttribute;
|
|
29
|
+
insertMethod;
|
|
30
|
+
keyBlockSize;
|
|
31
|
+
maxRows;
|
|
32
|
+
minRows;
|
|
33
|
+
rowFormat;
|
|
34
|
+
secondaryEngineAttribute;
|
|
35
|
+
constructor(params) {
|
|
36
|
+
this.clazz = params.clazz;
|
|
37
|
+
this.name = params.name;
|
|
38
|
+
this.dataSourceName = params.dataSourceName;
|
|
39
|
+
this.columns = params.columns;
|
|
40
|
+
this.indices = params.indices;
|
|
41
|
+
this.comment = params.comment;
|
|
42
|
+
this.autoExtendSize = params.autoExtendSize;
|
|
43
|
+
this.autoIncrement = params.autoIncrement;
|
|
44
|
+
this.avgRowLength = params.avgRowLength;
|
|
45
|
+
this.characterSet = params.characterSet;
|
|
46
|
+
this.collate = params.collate;
|
|
47
|
+
this.compression = params.compression;
|
|
48
|
+
this.encryption = params.encryption;
|
|
49
|
+
this.engine = params.engine;
|
|
50
|
+
this.engineAttribute = params.engineAttribute;
|
|
51
|
+
this.insertMethod = params.insertMethod;
|
|
52
|
+
this.keyBlockSize = params.keyBlockSize;
|
|
53
|
+
this.maxRows = params.maxRows;
|
|
54
|
+
this.minRows = params.minRows;
|
|
55
|
+
this.rowFormat = params.rowFormat;
|
|
56
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
57
|
+
}
|
|
58
|
+
getPrimary() {
|
|
59
|
+
const index = this.indices.find((t) => t.type === IndexType.PRIMARY);
|
|
60
|
+
if (index) return index;
|
|
61
|
+
const primaryColumn = this.columns.filter((t) => t.primaryKey === true);
|
|
62
|
+
return new IndexModel({
|
|
63
|
+
name: "PRIMARY",
|
|
64
|
+
type: IndexType.PRIMARY,
|
|
65
|
+
keys: primaryColumn.map((t) => {
|
|
66
|
+
return {
|
|
67
|
+
columnName: t.columnName,
|
|
68
|
+
propertyName: t.propertyName
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
static build(clazz) {
|
|
74
|
+
const params = TableInfoUtil.getTableParams(clazz);
|
|
75
|
+
const name = params?.name ?? snakecase(pluralize(clazz.name));
|
|
76
|
+
const columnInfoMap = ColumnInfoUtil.getColumnInfoMap(clazz);
|
|
77
|
+
const columnTypeMap = ColumnInfoUtil.getColumnTypeMap(clazz);
|
|
78
|
+
const dataSourceName = params?.dataSourceName ?? "default";
|
|
79
|
+
assert(TableInfoUtil.getIsTable(clazz), `${name} is not Table`);
|
|
80
|
+
assert(columnTypeMap, `${name} has no columns`);
|
|
81
|
+
const columns = [];
|
|
82
|
+
const indices = [];
|
|
83
|
+
for (const [property, columnType] of columnTypeMap?.entries() ?? []) {
|
|
84
|
+
const columnParam = columnInfoMap?.get(property);
|
|
85
|
+
columns.push(ColumnModel.build(property, columnType, columnParam));
|
|
86
|
+
}
|
|
87
|
+
const indexList = IndexInfoUtil.getIndexList(clazz);
|
|
88
|
+
for (const index of indexList) indices.push(IndexModel.build(index, columns, clazz));
|
|
89
|
+
return new TableModel({
|
|
90
|
+
clazz,
|
|
91
|
+
name,
|
|
92
|
+
columns,
|
|
93
|
+
indices,
|
|
94
|
+
dataSourceName,
|
|
95
|
+
comment: params?.comment,
|
|
96
|
+
autoExtendSize: params?.autoExtendSize,
|
|
97
|
+
autoIncrement: params?.autoIncrement,
|
|
98
|
+
avgRowLength: params?.avgRowLength,
|
|
99
|
+
characterSet: params?.characterSet,
|
|
100
|
+
collate: params?.collate,
|
|
101
|
+
compression: params?.compression,
|
|
102
|
+
encryption: params?.encryption,
|
|
103
|
+
engine: params?.engine,
|
|
104
|
+
engineAttribute: params?.engineAttribute,
|
|
105
|
+
insertMethod: params?.insertMethod,
|
|
106
|
+
keyBlockSize: params?.keyBlockSize,
|
|
107
|
+
maxRows: params?.maxRows,
|
|
108
|
+
minRows: params?.minRows,
|
|
109
|
+
rowFormat: params?.rowFormat,
|
|
110
|
+
secondaryEngineAttribute: params?.secondaryEngineAttribute
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { TableModel };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ColumnType, Geometry, GeometryCollection } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/type/Spatial.d.ts
|
|
4
|
+
declare class SpatialHelper {
|
|
5
|
+
static isPoint(t: Geometry): boolean;
|
|
6
|
+
static isLine(t: Geometry): boolean;
|
|
7
|
+
static isPolygon(t: Geometry): boolean;
|
|
8
|
+
static getGeometryType(t: Geometry): ColumnType.POINT | ColumnType.LINESTRING | ColumnType.POLYGON;
|
|
9
|
+
static isMultiPoint(t: GeometryCollection): boolean;
|
|
10
|
+
static isMultiLine(t: GeometryCollection): boolean;
|
|
11
|
+
static isMultiPolygon(t: GeometryCollection): boolean;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SpatialHelper };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ColumnType } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/type/Spatial.ts
|
|
4
|
+
var SpatialHelper = class SpatialHelper {
|
|
5
|
+
static isPoint(t) {
|
|
6
|
+
return typeof Reflect.get(t, "x") === "number" && typeof Reflect.get(t, "y") === "number";
|
|
7
|
+
}
|
|
8
|
+
static isLine(t) {
|
|
9
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPoint(t[0]);
|
|
10
|
+
}
|
|
11
|
+
static isPolygon(t) {
|
|
12
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isLine(t[0]);
|
|
13
|
+
}
|
|
14
|
+
static getGeometryType(t) {
|
|
15
|
+
if (SpatialHelper.isPoint(t)) return ColumnType.POINT;
|
|
16
|
+
else if (SpatialHelper.isLine(t)) return ColumnType.LINESTRING;
|
|
17
|
+
return ColumnType.POLYGON;
|
|
18
|
+
}
|
|
19
|
+
static isMultiPoint(t) {
|
|
20
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPoint(t[0]);
|
|
21
|
+
}
|
|
22
|
+
static isMultiLine(t) {
|
|
23
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isLine(t[0]);
|
|
24
|
+
}
|
|
25
|
+
static isMultiPolygon(t) {
|
|
26
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPolygon(t[0]);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { SpatialHelper };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ColumnParams, ColumnTypeParams, EggProtoImplClass } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/util/ColumnInfoUtil.d.ts
|
|
4
|
+
type ColumnInfoMap = Map<string, ColumnParams>;
|
|
5
|
+
type ColumnTypeMap = Map<string, ColumnTypeParams>;
|
|
6
|
+
declare class ColumnInfoUtil {
|
|
7
|
+
static addColumnInfo(clazz: EggProtoImplClass, property: string, column: ColumnInfoUtil): void;
|
|
8
|
+
static addColumnType(clazz: EggProtoImplClass, property: string, type: ColumnTypeParams): void;
|
|
9
|
+
static getColumnInfoMap(clazz: EggProtoImplClass): ColumnInfoMap | undefined;
|
|
10
|
+
static getColumnTypeMap(clazz: EggProtoImplClass): ColumnTypeMap | undefined;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ColumnInfoMap, ColumnInfoUtil, ColumnTypeMap };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DAL_COLUMN_INFO_MAP, DAL_COLUMN_TYPE_MAP } from "@eggjs/tegg-types";
|
|
2
|
+
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
3
|
+
|
|
4
|
+
//#region src/util/ColumnInfoUtil.ts
|
|
5
|
+
var ColumnInfoUtil = class {
|
|
6
|
+
static addColumnInfo(clazz, property, column) {
|
|
7
|
+
MetadataUtil.initOwnMapMetaData(DAL_COLUMN_INFO_MAP, clazz, /* @__PURE__ */ new Map()).set(property, column);
|
|
8
|
+
}
|
|
9
|
+
static addColumnType(clazz, property, type) {
|
|
10
|
+
MetadataUtil.initOwnMapMetaData(DAL_COLUMN_TYPE_MAP, clazz, /* @__PURE__ */ new Map()).set(property, type);
|
|
11
|
+
}
|
|
12
|
+
static getColumnInfoMap(clazz) {
|
|
13
|
+
return MetadataUtil.getMetaData(DAL_COLUMN_INFO_MAP, clazz);
|
|
14
|
+
}
|
|
15
|
+
static getColumnTypeMap(clazz) {
|
|
16
|
+
return MetadataUtil.getMetaData(DAL_COLUMN_TYPE_MAP, clazz);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ColumnInfoUtil };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseDaoType, EggProtoImplClass } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/util/DaoInfoUtil.d.ts
|
|
4
|
+
declare class DaoInfoUtil {
|
|
5
|
+
static setIsDao(clazz: EggProtoImplClass): void;
|
|
6
|
+
static getIsDao(clazz: EggProtoImplClass): clazz is BaseDaoType;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DaoInfoUtil };
|