@eggjs/dal-decorator 4.0.0-beta.7 → 4.0.0-beta.8
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/dist/index.d.ts +175 -15
- package/dist/index.js +358 -17
- package/package.json +4 -4
- package/dist/decorator/Column.d.ts +0 -6
- package/dist/decorator/Column.js +0 -17
- package/dist/decorator/Dao.d.ts +0 -6
- package/dist/decorator/Dao.js +0 -20
- package/dist/decorator/DataSourceQualifier.d.ts +0 -4
- package/dist/decorator/DataSourceQualifier.js +0 -12
- package/dist/decorator/Table.d.ts +0 -6
- package/dist/decorator/Table.js +0 -21
- package/dist/decorator/TableIndex.d.ts +0 -6
- package/dist/decorator/TableIndex.js +0 -12
- package/dist/decorator/index.js +0 -7
- package/dist/model/ColumnModel.d.ts +0 -38
- package/dist/model/ColumnModel.js +0 -59
- package/dist/model/IndexModel.d.ts +0 -32
- package/dist/model/IndexModel.js +0 -52
- package/dist/model/TableModel.d.ts +0 -55
- package/dist/model/TableModel.js +0 -116
- package/dist/model/index.js +0 -5
- package/dist/type/MySql.d.ts +0 -2
- package/dist/type/Spatial.d.ts +0 -14
- package/dist/type/Spatial.js +0 -31
- package/dist/type/index.js +0 -3
- package/dist/util/ColumnInfoUtil.d.ts +0 -13
- package/dist/util/ColumnInfoUtil.js +0 -21
- package/dist/util/DaoInfoUtil.d.ts +0 -9
- package/dist/util/DaoInfoUtil.js +0 -15
- package/dist/util/IndexInfoUtil.d.ts +0 -9
- package/dist/util/IndexInfoUtil.js +0 -15
- package/dist/util/TableInfoUtil.d.ts +0 -13
- package/dist/util/TableInfoUtil.js +0 -26
- package/dist/util/index.js +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,176 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
1
|
+
import { BaseDaoType, ColumnFormat, ColumnParams, ColumnType, ColumnTypeParams, CompressionType, EggProtoImplClass, Geometry, GeometryCollection, IndexParams, IndexStoreType, IndexType, InsertMethod, RowFormat, TableParams } from "@eggjs/tegg-types";
|
|
2
|
+
import { DeleteResult, InsertResult, UpdateResult } from "@eggjs/rds";
|
|
15
3
|
export * from "@eggjs/tegg-types/dal";
|
|
16
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/decorator/Column.d.ts
|
|
6
|
+
declare function Column(type: ColumnTypeParams, params?: ColumnParams): (target: any, propertyKey: PropertyKey) => void;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/decorator/Dao.d.ts
|
|
9
|
+
declare function Dao(): (constructor: EggProtoImplClass) => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/decorator/DataSourceQualifier.d.ts
|
|
12
|
+
declare function DataSourceQualifier(dataSourceName: string): (target: any, propertyKey: PropertyKey, parameterIndex?: number) => void;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/decorator/Table.d.ts
|
|
15
|
+
declare function Table(params?: TableParams): (constructor: EggProtoImplClass) => void;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/decorator/TableIndex.d.ts
|
|
18
|
+
declare function Index(params: IndexParams): (constructor: EggProtoImplClass) => void;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/model/ColumnModel.d.ts
|
|
21
|
+
declare class ColumnModel {
|
|
22
|
+
columnName: string;
|
|
23
|
+
propertyName: string;
|
|
24
|
+
type: ColumnTypeParams;
|
|
25
|
+
canNull: boolean;
|
|
26
|
+
default?: string;
|
|
27
|
+
comment?: string;
|
|
28
|
+
visible?: boolean;
|
|
29
|
+
autoIncrement?: boolean;
|
|
30
|
+
uniqueKey?: boolean;
|
|
31
|
+
primaryKey?: boolean;
|
|
32
|
+
collate?: string;
|
|
33
|
+
columnFormat?: ColumnFormat;
|
|
34
|
+
engineAttribute?: string;
|
|
35
|
+
secondaryEngineAttribute?: string;
|
|
36
|
+
constructor(params: {
|
|
37
|
+
columnName: string;
|
|
38
|
+
propertyName: string;
|
|
39
|
+
type: ColumnTypeParams;
|
|
40
|
+
canNull: boolean;
|
|
41
|
+
default?: string;
|
|
42
|
+
comment?: string;
|
|
43
|
+
visible?: boolean;
|
|
44
|
+
autoIncrement?: boolean;
|
|
45
|
+
uniqueKey?: boolean;
|
|
46
|
+
primaryKey?: boolean;
|
|
47
|
+
collate?: string;
|
|
48
|
+
columnFormat?: ColumnFormat;
|
|
49
|
+
engineAttribute?: string;
|
|
50
|
+
secondaryEngineAttribute?: string;
|
|
51
|
+
});
|
|
52
|
+
static build(property: string, type: ColumnTypeParams, params?: ColumnParams): ColumnModel;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/model/IndexModel.d.ts
|
|
56
|
+
interface IndexKey {
|
|
57
|
+
columnName: string;
|
|
58
|
+
propertyName: string;
|
|
59
|
+
}
|
|
60
|
+
declare class IndexModel {
|
|
61
|
+
name: string;
|
|
62
|
+
keys: IndexKey[];
|
|
63
|
+
type: IndexType;
|
|
64
|
+
storeType?: IndexStoreType;
|
|
65
|
+
comment?: string;
|
|
66
|
+
engineAttribute?: string;
|
|
67
|
+
secondaryEngineAttribute?: string;
|
|
68
|
+
parser?: string;
|
|
69
|
+
constructor(params: {
|
|
70
|
+
name: string;
|
|
71
|
+
keys: IndexKey[];
|
|
72
|
+
type: IndexType;
|
|
73
|
+
storeType?: IndexStoreType;
|
|
74
|
+
comment?: string;
|
|
75
|
+
engineAttribute?: string;
|
|
76
|
+
secondaryEngineAttribute?: string;
|
|
77
|
+
parser?: string;
|
|
78
|
+
});
|
|
79
|
+
static buildIndexName(keys: string[], type: IndexType): string;
|
|
80
|
+
static build(params: IndexParams, columns: ColumnModel[], clazz: EggProtoImplClass<unknown>): IndexModel;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/model/TableModel.d.ts
|
|
84
|
+
declare class TableModel<T = object> {
|
|
85
|
+
clazz: EggProtoImplClass<T>;
|
|
86
|
+
name: string;
|
|
87
|
+
columns: Array<ColumnModel>;
|
|
88
|
+
indices: Array<IndexModel>;
|
|
89
|
+
dataSourceName: string;
|
|
90
|
+
comment?: string;
|
|
91
|
+
autoExtendSize?: number;
|
|
92
|
+
autoIncrement?: number;
|
|
93
|
+
avgRowLength?: number;
|
|
94
|
+
characterSet?: string;
|
|
95
|
+
collate?: string;
|
|
96
|
+
compression?: CompressionType;
|
|
97
|
+
encryption?: boolean;
|
|
98
|
+
engine?: string;
|
|
99
|
+
engineAttribute?: string;
|
|
100
|
+
insertMethod?: InsertMethod;
|
|
101
|
+
keyBlockSize?: number;
|
|
102
|
+
maxRows?: number;
|
|
103
|
+
minRows?: number;
|
|
104
|
+
rowFormat?: RowFormat;
|
|
105
|
+
secondaryEngineAttribute?: string;
|
|
106
|
+
constructor(params: {
|
|
107
|
+
clazz: EggProtoImplClass<T>;
|
|
108
|
+
name: string;
|
|
109
|
+
dataSourceName: string;
|
|
110
|
+
columns: Array<ColumnModel>;
|
|
111
|
+
indices: Array<IndexModel>;
|
|
112
|
+
comment?: string;
|
|
113
|
+
autoExtendSize?: number;
|
|
114
|
+
autoIncrement?: number;
|
|
115
|
+
avgRowLength?: number;
|
|
116
|
+
characterSet?: string;
|
|
117
|
+
collate?: string;
|
|
118
|
+
compression?: CompressionType;
|
|
119
|
+
encryption?: boolean;
|
|
120
|
+
engine?: string;
|
|
121
|
+
engineAttribute?: string;
|
|
122
|
+
insertMethod?: InsertMethod;
|
|
123
|
+
keyBlockSize?: number;
|
|
124
|
+
maxRows?: number;
|
|
125
|
+
minRows?: number;
|
|
126
|
+
rowFormat?: RowFormat;
|
|
127
|
+
secondaryEngineAttribute?: string;
|
|
128
|
+
});
|
|
129
|
+
getPrimary(): IndexModel | undefined;
|
|
130
|
+
static build<T>(clazz: EggProtoImplClass<T>): TableModel<T>;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/type/Spatial.d.ts
|
|
134
|
+
declare class SpatialHelper {
|
|
135
|
+
static isPoint(t: Geometry): boolean;
|
|
136
|
+
static isLine(t: Geometry): boolean;
|
|
137
|
+
static isPolygon(t: Geometry): boolean;
|
|
138
|
+
static getGeometryType(t: Geometry): ColumnType.POINT | ColumnType.LINESTRING | ColumnType.POLYGON;
|
|
139
|
+
static isMultiPoint(t: GeometryCollection): boolean;
|
|
140
|
+
static isMultiLine(t: GeometryCollection): boolean;
|
|
141
|
+
static isMultiPolygon(t: GeometryCollection): boolean;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/util/ColumnInfoUtil.d.ts
|
|
145
|
+
type ColumnInfoMap = Map<string, ColumnParams>;
|
|
146
|
+
type ColumnTypeMap = Map<string, ColumnTypeParams>;
|
|
147
|
+
declare class ColumnInfoUtil {
|
|
148
|
+
static addColumnInfo(clazz: EggProtoImplClass, property: string, column: ColumnInfoUtil): void;
|
|
149
|
+
static addColumnType(clazz: EggProtoImplClass, property: string, type: ColumnTypeParams): void;
|
|
150
|
+
static getColumnInfoMap(clazz: EggProtoImplClass): ColumnInfoMap | undefined;
|
|
151
|
+
static getColumnTypeMap(clazz: EggProtoImplClass): ColumnTypeMap | undefined;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/util/DaoInfoUtil.d.ts
|
|
155
|
+
declare class DaoInfoUtil {
|
|
156
|
+
static setIsDao(clazz: EggProtoImplClass): void;
|
|
157
|
+
static getIsDao(clazz: EggProtoImplClass): clazz is BaseDaoType;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/util/IndexInfoUtil.d.ts
|
|
161
|
+
declare class IndexInfoUtil {
|
|
162
|
+
static addIndex(clazz: EggProtoImplClass, index: IndexParams): void;
|
|
163
|
+
static getIndexList(clazz: EggProtoImplClass): Array<IndexParams>;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/util/TableInfoUtil.d.ts
|
|
167
|
+
declare const TABLE_CLAZZ_LIST: Array<EggProtoImplClass>;
|
|
168
|
+
declare class TableInfoUtil {
|
|
169
|
+
static setIsTable(clazz: EggProtoImplClass): void;
|
|
170
|
+
static getClazzList(): EggProtoImplClass[];
|
|
171
|
+
static getIsTable(clazz: EggProtoImplClass): boolean;
|
|
172
|
+
static setTableParams(clazz: EggProtoImplClass, params: TableParams): void;
|
|
173
|
+
static getTableParams(clazz: EggProtoImplClass): TableParams | undefined;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { Column, ColumnInfoMap, ColumnInfoUtil, ColumnModel, ColumnTypeMap, Dao, DaoInfoUtil, DataSourceQualifier, type DeleteResult, Index, IndexInfoUtil, IndexKey, IndexModel, type InsertResult, SpatialHelper, TABLE_CLAZZ_LIST, Table, TableInfoUtil, TableModel, type UpdateResult };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,362 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import "
|
|
6
|
-
import
|
|
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";
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { AccessLevel, ColumnType, DAL_COLUMN_INFO_MAP, DAL_COLUMN_TYPE_MAP, DAL_INDEX_LIST, DAL_IS_DAO, DAL_IS_TABLE, DAL_TABLE_PARAMS, DataSourceQualifierAttribute, IndexType, ObjectInitType } from "@eggjs/tegg-types";
|
|
3
|
+
import { MetadataUtil, Prototype, PrototypeUtil, QualifierUtil } from "@eggjs/core-decorator";
|
|
4
|
+
import { StackUtil } from "@eggjs/tegg-common-util";
|
|
5
|
+
import snakecase from "lodash.snakecase";
|
|
6
|
+
import pluralize from "pluralize";
|
|
18
7
|
|
|
19
8
|
export * from "@eggjs/tegg-types/dal"
|
|
20
9
|
|
|
10
|
+
//#region src/util/ColumnInfoUtil.ts
|
|
11
|
+
var ColumnInfoUtil = class {
|
|
12
|
+
static addColumnInfo(clazz, property, column) {
|
|
13
|
+
MetadataUtil.initOwnMapMetaData(DAL_COLUMN_INFO_MAP, clazz, /* @__PURE__ */ new Map()).set(property, column);
|
|
14
|
+
}
|
|
15
|
+
static addColumnType(clazz, property, type) {
|
|
16
|
+
MetadataUtil.initOwnMapMetaData(DAL_COLUMN_TYPE_MAP, clazz, /* @__PURE__ */ new Map()).set(property, type);
|
|
17
|
+
}
|
|
18
|
+
static getColumnInfoMap(clazz) {
|
|
19
|
+
return MetadataUtil.getMetaData(DAL_COLUMN_INFO_MAP, clazz);
|
|
20
|
+
}
|
|
21
|
+
static getColumnTypeMap(clazz) {
|
|
22
|
+
return MetadataUtil.getMetaData(DAL_COLUMN_TYPE_MAP, clazz);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/util/DaoInfoUtil.ts
|
|
28
|
+
var DaoInfoUtil = class {
|
|
29
|
+
static setIsDao(clazz) {
|
|
30
|
+
MetadataUtil.defineMetaData(DAL_IS_DAO, true, clazz);
|
|
31
|
+
}
|
|
32
|
+
static getIsDao(clazz) {
|
|
33
|
+
return MetadataUtil.getOwnMetaData(DAL_IS_DAO, clazz) === true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/util/IndexInfoUtil.ts
|
|
39
|
+
var IndexInfoUtil = class {
|
|
40
|
+
static addIndex(clazz, index) {
|
|
41
|
+
MetadataUtil.initOwnArrayMetaData(DAL_INDEX_LIST, clazz, []).push(index);
|
|
42
|
+
}
|
|
43
|
+
static getIndexList(clazz) {
|
|
44
|
+
return MetadataUtil.getMetaData(DAL_INDEX_LIST, clazz) || [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/util/TableInfoUtil.ts
|
|
50
|
+
const TABLE_CLAZZ_LIST = [];
|
|
51
|
+
var TableInfoUtil = class {
|
|
52
|
+
static setIsTable(clazz) {
|
|
53
|
+
TABLE_CLAZZ_LIST.push(clazz);
|
|
54
|
+
MetadataUtil.defineMetaData(DAL_IS_TABLE, true, clazz);
|
|
55
|
+
}
|
|
56
|
+
static getClazzList() {
|
|
57
|
+
return TABLE_CLAZZ_LIST;
|
|
58
|
+
}
|
|
59
|
+
static getIsTable(clazz) {
|
|
60
|
+
return MetadataUtil.getMetaData(DAL_IS_TABLE, clazz) === true;
|
|
61
|
+
}
|
|
62
|
+
static setTableParams(clazz, params) {
|
|
63
|
+
MetadataUtil.defineMetaData(DAL_TABLE_PARAMS, params, clazz);
|
|
64
|
+
}
|
|
65
|
+
static getTableParams(clazz) {
|
|
66
|
+
return MetadataUtil.getMetaData(DAL_TABLE_PARAMS, clazz);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/decorator/Column.ts
|
|
72
|
+
function Column(type, params) {
|
|
73
|
+
return function(target, propertyKey) {
|
|
74
|
+
assert(typeof propertyKey === "string", `[Column/${target.name}] expect column name be typeof string, but now is ${String(propertyKey)}`);
|
|
75
|
+
const tableClazz = target.constructor;
|
|
76
|
+
const columnName = propertyKey;
|
|
77
|
+
ColumnInfoUtil.addColumnType(tableClazz, columnName, type);
|
|
78
|
+
if (params) ColumnInfoUtil.addColumnInfo(tableClazz, columnName, params);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/decorator/Dao.ts
|
|
84
|
+
function Dao() {
|
|
85
|
+
return function(constructor) {
|
|
86
|
+
DaoInfoUtil.setIsDao(constructor);
|
|
87
|
+
Prototype({
|
|
88
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
89
|
+
initType: ObjectInitType.SINGLETON
|
|
90
|
+
})(constructor);
|
|
91
|
+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/decorator/DataSourceQualifier.ts
|
|
97
|
+
function DataSourceQualifier(dataSourceName) {
|
|
98
|
+
return function(target, propertyKey, parameterIndex) {
|
|
99
|
+
QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, DataSourceQualifierAttribute, dataSourceName);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/decorator/Table.ts
|
|
105
|
+
function Table(params) {
|
|
106
|
+
return function(constructor) {
|
|
107
|
+
TableInfoUtil.setIsTable(constructor);
|
|
108
|
+
if (params) TableInfoUtil.setTableParams(constructor, params);
|
|
109
|
+
Prototype({
|
|
110
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
111
|
+
initType: ObjectInitType.ALWAYS_NEW
|
|
112
|
+
})(constructor);
|
|
113
|
+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/decorator/TableIndex.ts
|
|
119
|
+
function Index(params) {
|
|
120
|
+
return function(constructor) {
|
|
121
|
+
IndexInfoUtil.addIndex(constructor, params);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/model/ColumnModel.ts
|
|
127
|
+
var ColumnModel = class ColumnModel {
|
|
128
|
+
columnName;
|
|
129
|
+
propertyName;
|
|
130
|
+
type;
|
|
131
|
+
canNull;
|
|
132
|
+
default;
|
|
133
|
+
comment;
|
|
134
|
+
visible;
|
|
135
|
+
autoIncrement;
|
|
136
|
+
uniqueKey;
|
|
137
|
+
primaryKey;
|
|
138
|
+
collate;
|
|
139
|
+
columnFormat;
|
|
140
|
+
engineAttribute;
|
|
141
|
+
secondaryEngineAttribute;
|
|
142
|
+
constructor(params) {
|
|
143
|
+
this.columnName = params.columnName;
|
|
144
|
+
this.propertyName = params.propertyName;
|
|
145
|
+
this.type = params.type;
|
|
146
|
+
this.canNull = params.canNull;
|
|
147
|
+
this.default = params.default;
|
|
148
|
+
this.comment = params.comment;
|
|
149
|
+
this.visible = params.visible;
|
|
150
|
+
this.autoIncrement = params.autoIncrement;
|
|
151
|
+
this.uniqueKey = params.uniqueKey;
|
|
152
|
+
this.primaryKey = params.primaryKey;
|
|
153
|
+
this.collate = params.collate;
|
|
154
|
+
this.columnFormat = params.columnFormat;
|
|
155
|
+
this.engineAttribute = params.engineAttribute;
|
|
156
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
157
|
+
}
|
|
158
|
+
static build(property, type, params) {
|
|
159
|
+
const columnName = params?.name ?? snakecase(property);
|
|
160
|
+
let canNull = params?.canNull ?? false;
|
|
161
|
+
if (params?.primaryKey) canNull = false;
|
|
162
|
+
return new ColumnModel({
|
|
163
|
+
columnName,
|
|
164
|
+
propertyName: property,
|
|
165
|
+
type,
|
|
166
|
+
canNull,
|
|
167
|
+
default: params?.default,
|
|
168
|
+
comment: params?.comment,
|
|
169
|
+
visible: params?.visible,
|
|
170
|
+
autoIncrement: params?.autoIncrement,
|
|
171
|
+
uniqueKey: params?.uniqueKey,
|
|
172
|
+
primaryKey: params?.primaryKey,
|
|
173
|
+
collate: params?.collate,
|
|
174
|
+
columnFormat: params?.columnFormat,
|
|
175
|
+
engineAttribute: params?.engineAttribute,
|
|
176
|
+
secondaryEngineAttribute: params?.secondaryEngineAttribute
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/model/IndexModel.ts
|
|
183
|
+
var IndexModel = class IndexModel {
|
|
184
|
+
name;
|
|
185
|
+
keys;
|
|
186
|
+
type;
|
|
187
|
+
storeType;
|
|
188
|
+
comment;
|
|
189
|
+
engineAttribute;
|
|
190
|
+
secondaryEngineAttribute;
|
|
191
|
+
parser;
|
|
192
|
+
constructor(params) {
|
|
193
|
+
this.name = params.name;
|
|
194
|
+
this.keys = params.keys;
|
|
195
|
+
this.type = params.type;
|
|
196
|
+
this.storeType = params.storeType;
|
|
197
|
+
this.comment = params.comment;
|
|
198
|
+
this.engineAttribute = params.engineAttribute;
|
|
199
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
200
|
+
this.parser = params.parser;
|
|
201
|
+
}
|
|
202
|
+
static buildIndexName(keys, type) {
|
|
203
|
+
return (type === IndexType.UNIQUE ? "uk_" : "idx_") + keys.join("_");
|
|
204
|
+
}
|
|
205
|
+
static build(params, columns, clazz) {
|
|
206
|
+
const type = params.type ?? IndexType.INDEX;
|
|
207
|
+
const keys = params.keys.map((t) => {
|
|
208
|
+
const column = columns.find((c) => c.propertyName === t);
|
|
209
|
+
if (!column) throw new Error(`Table ${clazz.name} index configuration error: has no property named "${t}"`);
|
|
210
|
+
return {
|
|
211
|
+
propertyName: column.propertyName,
|
|
212
|
+
columnName: column.columnName
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
const name = params.name ?? IndexModel.buildIndexName(keys.map((t) => t.columnName), type);
|
|
216
|
+
return new IndexModel({
|
|
217
|
+
name,
|
|
218
|
+
keys,
|
|
219
|
+
type,
|
|
220
|
+
storeType: params.storeType,
|
|
221
|
+
comment: params.comment,
|
|
222
|
+
engineAttribute: params.engineAttribute,
|
|
223
|
+
secondaryEngineAttribute: params.secondaryEngineAttribute,
|
|
224
|
+
parser: params.parser
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/model/TableModel.ts
|
|
231
|
+
var TableModel = class TableModel {
|
|
232
|
+
clazz;
|
|
233
|
+
name;
|
|
234
|
+
columns;
|
|
235
|
+
indices;
|
|
236
|
+
dataSourceName;
|
|
237
|
+
comment;
|
|
238
|
+
autoExtendSize;
|
|
239
|
+
autoIncrement;
|
|
240
|
+
avgRowLength;
|
|
241
|
+
characterSet;
|
|
242
|
+
collate;
|
|
243
|
+
compression;
|
|
244
|
+
encryption;
|
|
245
|
+
engine;
|
|
246
|
+
engineAttribute;
|
|
247
|
+
insertMethod;
|
|
248
|
+
keyBlockSize;
|
|
249
|
+
maxRows;
|
|
250
|
+
minRows;
|
|
251
|
+
rowFormat;
|
|
252
|
+
secondaryEngineAttribute;
|
|
253
|
+
constructor(params) {
|
|
254
|
+
this.clazz = params.clazz;
|
|
255
|
+
this.name = params.name;
|
|
256
|
+
this.dataSourceName = params.dataSourceName;
|
|
257
|
+
this.columns = params.columns;
|
|
258
|
+
this.indices = params.indices;
|
|
259
|
+
this.comment = params.comment;
|
|
260
|
+
this.autoExtendSize = params.autoExtendSize;
|
|
261
|
+
this.autoIncrement = params.autoIncrement;
|
|
262
|
+
this.avgRowLength = params.avgRowLength;
|
|
263
|
+
this.characterSet = params.characterSet;
|
|
264
|
+
this.collate = params.collate;
|
|
265
|
+
this.compression = params.compression;
|
|
266
|
+
this.encryption = params.encryption;
|
|
267
|
+
this.engine = params.engine;
|
|
268
|
+
this.engineAttribute = params.engineAttribute;
|
|
269
|
+
this.insertMethod = params.insertMethod;
|
|
270
|
+
this.keyBlockSize = params.keyBlockSize;
|
|
271
|
+
this.maxRows = params.maxRows;
|
|
272
|
+
this.minRows = params.minRows;
|
|
273
|
+
this.rowFormat = params.rowFormat;
|
|
274
|
+
this.secondaryEngineAttribute = params.secondaryEngineAttribute;
|
|
275
|
+
}
|
|
276
|
+
getPrimary() {
|
|
277
|
+
const index = this.indices.find((t) => t.type === IndexType.PRIMARY);
|
|
278
|
+
if (index) return index;
|
|
279
|
+
const primaryColumn = this.columns.filter((t) => t.primaryKey === true);
|
|
280
|
+
return new IndexModel({
|
|
281
|
+
name: "PRIMARY",
|
|
282
|
+
type: IndexType.PRIMARY,
|
|
283
|
+
keys: primaryColumn.map((t) => {
|
|
284
|
+
return {
|
|
285
|
+
columnName: t.columnName,
|
|
286
|
+
propertyName: t.propertyName
|
|
287
|
+
};
|
|
288
|
+
})
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
static build(clazz) {
|
|
292
|
+
const params = TableInfoUtil.getTableParams(clazz);
|
|
293
|
+
const name = params?.name ?? snakecase(pluralize(clazz.name));
|
|
294
|
+
const columnInfoMap = ColumnInfoUtil.getColumnInfoMap(clazz);
|
|
295
|
+
const columnTypeMap = ColumnInfoUtil.getColumnTypeMap(clazz);
|
|
296
|
+
const dataSourceName = params?.dataSourceName ?? "default";
|
|
297
|
+
assert(TableInfoUtil.getIsTable(clazz), `${name} is not Table`);
|
|
298
|
+
assert(columnTypeMap, `${name} has no columns`);
|
|
299
|
+
const columns = [];
|
|
300
|
+
const indices = [];
|
|
301
|
+
for (const [property, columnType] of columnTypeMap?.entries() ?? []) {
|
|
302
|
+
const columnParam = columnInfoMap?.get(property);
|
|
303
|
+
columns.push(ColumnModel.build(property, columnType, columnParam));
|
|
304
|
+
}
|
|
305
|
+
const indexList = IndexInfoUtil.getIndexList(clazz);
|
|
306
|
+
for (const index of indexList) indices.push(IndexModel.build(index, columns, clazz));
|
|
307
|
+
return new TableModel({
|
|
308
|
+
clazz,
|
|
309
|
+
name,
|
|
310
|
+
columns,
|
|
311
|
+
indices,
|
|
312
|
+
dataSourceName,
|
|
313
|
+
comment: params?.comment,
|
|
314
|
+
autoExtendSize: params?.autoExtendSize,
|
|
315
|
+
autoIncrement: params?.autoIncrement,
|
|
316
|
+
avgRowLength: params?.avgRowLength,
|
|
317
|
+
characterSet: params?.characterSet,
|
|
318
|
+
collate: params?.collate,
|
|
319
|
+
compression: params?.compression,
|
|
320
|
+
encryption: params?.encryption,
|
|
321
|
+
engine: params?.engine,
|
|
322
|
+
engineAttribute: params?.engineAttribute,
|
|
323
|
+
insertMethod: params?.insertMethod,
|
|
324
|
+
keyBlockSize: params?.keyBlockSize,
|
|
325
|
+
maxRows: params?.maxRows,
|
|
326
|
+
minRows: params?.minRows,
|
|
327
|
+
rowFormat: params?.rowFormat,
|
|
328
|
+
secondaryEngineAttribute: params?.secondaryEngineAttribute
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/type/Spatial.ts
|
|
335
|
+
var SpatialHelper = class SpatialHelper {
|
|
336
|
+
static isPoint(t) {
|
|
337
|
+
return typeof Reflect.get(t, "x") === "number" && typeof Reflect.get(t, "y") === "number";
|
|
338
|
+
}
|
|
339
|
+
static isLine(t) {
|
|
340
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPoint(t[0]);
|
|
341
|
+
}
|
|
342
|
+
static isPolygon(t) {
|
|
343
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isLine(t[0]);
|
|
344
|
+
}
|
|
345
|
+
static getGeometryType(t) {
|
|
346
|
+
if (SpatialHelper.isPoint(t)) return ColumnType.POINT;
|
|
347
|
+
else if (SpatialHelper.isLine(t)) return ColumnType.LINESTRING;
|
|
348
|
+
return ColumnType.POLYGON;
|
|
349
|
+
}
|
|
350
|
+
static isMultiPoint(t) {
|
|
351
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPoint(t[0]);
|
|
352
|
+
}
|
|
353
|
+
static isMultiLine(t) {
|
|
354
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isLine(t[0]);
|
|
355
|
+
}
|
|
356
|
+
static isMultiPolygon(t) {
|
|
357
|
+
return Array.isArray(t) && t[0] && SpatialHelper.isPolygon(t[0]);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
//#endregion
|
|
21
362
|
export { Column, ColumnInfoUtil, ColumnModel, Dao, DaoInfoUtil, DataSourceQualifier, Index, IndexInfoUtil, IndexModel, SpatialHelper, TABLE_CLAZZ_LIST, Table, TableInfoUtil, TableModel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/dal-decorator",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "tegg dal decorator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@eggjs/rds": "^1.3.0",
|
|
36
36
|
"lodash.snakecase": "^4.1.1",
|
|
37
37
|
"pluralize": "^8.0.0",
|
|
38
|
-
"@eggjs/
|
|
39
|
-
"@eggjs/
|
|
40
|
-
"@eggjs/tegg-
|
|
38
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.8",
|
|
39
|
+
"@eggjs/core-decorator": "4.0.0-beta.8",
|
|
40
|
+
"@eggjs/tegg-types": "4.0.0-beta.8"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
package/dist/decorator/Column.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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 };
|
package/dist/decorator/Dao.d.ts
DELETED
package/dist/decorator/Dao.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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 };
|
|
@@ -1,12 +0,0 @@
|
|
|
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 };
|
package/dist/decorator/Table.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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 };
|
|
@@ -1,12 +0,0 @@
|
|
|
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/decorator/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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 };
|
|
@@ -1,59 +0,0 @@
|
|
|
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 };
|
|
@@ -1,32 +0,0 @@
|
|
|
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 };
|
package/dist/model/IndexModel.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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 };
|
|
@@ -1,55 +0,0 @@
|
|
|
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 };
|
package/dist/model/TableModel.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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 };
|
package/dist/model/index.js
DELETED
package/dist/type/MySql.d.ts
DELETED
package/dist/type/Spatial.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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 };
|
package/dist/type/Spatial.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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 };
|
package/dist/type/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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 };
|
|
@@ -1,21 +0,0 @@
|
|
|
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 };
|
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
package/dist/util/DaoInfoUtil.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DAL_IS_DAO } from "@eggjs/tegg-types";
|
|
2
|
-
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
3
|
-
|
|
4
|
-
//#region src/util/DaoInfoUtil.ts
|
|
5
|
-
var DaoInfoUtil = class {
|
|
6
|
-
static setIsDao(clazz) {
|
|
7
|
-
MetadataUtil.defineMetaData(DAL_IS_DAO, true, clazz);
|
|
8
|
-
}
|
|
9
|
-
static getIsDao(clazz) {
|
|
10
|
-
return MetadataUtil.getOwnMetaData(DAL_IS_DAO, clazz) === true;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { DaoInfoUtil };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EggProtoImplClass, IndexParams } from "@eggjs/tegg-types";
|
|
2
|
-
|
|
3
|
-
//#region src/util/IndexInfoUtil.d.ts
|
|
4
|
-
declare class IndexInfoUtil {
|
|
5
|
-
static addIndex(clazz: EggProtoImplClass, index: IndexParams): void;
|
|
6
|
-
static getIndexList(clazz: EggProtoImplClass): Array<IndexParams>;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { IndexInfoUtil };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DAL_INDEX_LIST } from "@eggjs/tegg-types";
|
|
2
|
-
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
3
|
-
|
|
4
|
-
//#region src/util/IndexInfoUtil.ts
|
|
5
|
-
var IndexInfoUtil = class {
|
|
6
|
-
static addIndex(clazz, index) {
|
|
7
|
-
MetadataUtil.initOwnArrayMetaData(DAL_INDEX_LIST, clazz, []).push(index);
|
|
8
|
-
}
|
|
9
|
-
static getIndexList(clazz) {
|
|
10
|
-
return MetadataUtil.getMetaData(DAL_INDEX_LIST, clazz) || [];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { IndexInfoUtil };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { EggProtoImplClass, TableParams } from "@eggjs/tegg-types";
|
|
2
|
-
|
|
3
|
-
//#region src/util/TableInfoUtil.d.ts
|
|
4
|
-
declare const TABLE_CLAZZ_LIST: Array<EggProtoImplClass>;
|
|
5
|
-
declare class TableInfoUtil {
|
|
6
|
-
static setIsTable(clazz: EggProtoImplClass): void;
|
|
7
|
-
static getClazzList(): EggProtoImplClass[];
|
|
8
|
-
static getIsTable(clazz: EggProtoImplClass): boolean;
|
|
9
|
-
static setTableParams(clazz: EggProtoImplClass, params: TableParams): void;
|
|
10
|
-
static getTableParams(clazz: EggProtoImplClass): TableParams | undefined;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { TABLE_CLAZZ_LIST, TableInfoUtil };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { DAL_IS_TABLE, DAL_TABLE_PARAMS } from "@eggjs/tegg-types";
|
|
2
|
-
import { MetadataUtil } from "@eggjs/core-decorator";
|
|
3
|
-
|
|
4
|
-
//#region src/util/TableInfoUtil.ts
|
|
5
|
-
const TABLE_CLAZZ_LIST = [];
|
|
6
|
-
var TableInfoUtil = class {
|
|
7
|
-
static setIsTable(clazz) {
|
|
8
|
-
TABLE_CLAZZ_LIST.push(clazz);
|
|
9
|
-
MetadataUtil.defineMetaData(DAL_IS_TABLE, true, clazz);
|
|
10
|
-
}
|
|
11
|
-
static getClazzList() {
|
|
12
|
-
return TABLE_CLAZZ_LIST;
|
|
13
|
-
}
|
|
14
|
-
static getIsTable(clazz) {
|
|
15
|
-
return MetadataUtil.getMetaData(DAL_IS_TABLE, clazz) === true;
|
|
16
|
-
}
|
|
17
|
-
static setTableParams(clazz, params) {
|
|
18
|
-
MetadataUtil.defineMetaData(DAL_TABLE_PARAMS, params, clazz);
|
|
19
|
-
}
|
|
20
|
-
static getTableParams(clazz) {
|
|
21
|
-
return MetadataUtil.getMetaData(DAL_TABLE_PARAMS, clazz);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export { TABLE_CLAZZ_LIST, TableInfoUtil };
|
package/dist/util/index.js
DELETED