midway-fatcms 0.0.7 → 0.0.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/.qoder/skills/midway-fatcms/01-quick-start.md +231 -0
- package/.qoder/skills/midway-fatcms/02-crud-quick.md +337 -0
- package/.qoder/skills/midway-fatcms/03-crud-sharding.md +488 -0
- package/.qoder/skills/midway-fatcms/04-condition-operators.md +93 -0
- package/.qoder/skills/midway-fatcms/05-configuration.md +290 -0
- package/.qoder/skills/midway-fatcms/06-builtin-functions.md +241 -0
- package/.qoder/skills/midway-fatcms/07-examples.md +500 -0
- package/.qoder/skills/midway-fatcms/SKILL.md +96 -0
- package/README.md +9 -9
- package/dist/controller/base/BaseApiController.d.ts +1 -2
- package/dist/controller/base/BaseApiController.js +0 -4
- package/dist/controller/gateway/DocGatewayController.js +1 -1
- package/dist/controller/manage/FlowConfigManageApi.js +4 -2
- package/dist/controller/manage/SysConfigMangeApi.js +6 -1
- package/dist/controller/manage/UserAccountManageApi.js +7 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/libs/crud-pro/CrudPro.d.ts +23 -2
- package/dist/libs/crud-pro/CrudPro.js +53 -2
- package/dist/libs/crud-pro/interfaces.d.ts +82 -12
- package/dist/libs/crud-pro/models/CrudResult.d.ts +115 -0
- package/dist/libs/crud-pro/models/CrudResult.js +126 -0
- package/dist/libs/crud-pro/models/RequestModel.d.ts +2 -2
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +36 -2
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +8 -4
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +1 -2
- package/dist/libs/crud-pro-quick/CrudProQuick.d.ts +295 -0
- package/dist/libs/crud-pro-quick/CrudProQuick.js +529 -0
- package/dist/libs/crud-pro-quick/fixSoftDelete.d.ts +30 -0
- package/dist/{service/curd → libs/crud-pro-quick}/fixSoftDelete.js +3 -6
- package/dist/libs/crud-pro-quick/index.d.ts +36 -0
- package/dist/libs/crud-pro-quick/index.js +49 -0
- package/dist/libs/crud-pro-quick/models.d.ts +33 -0
- package/dist/libs/crud-pro-quick/models.js +2 -0
- package/dist/libs/crud-sharding/ShardingConfig.d.ts +15 -2
- package/dist/libs/crud-sharding/ShardingConfig.js +2 -2
- package/dist/libs/crud-sharding/ShardingCrudPro.d.ts +119 -274
- package/dist/libs/crud-sharding/ShardingCrudPro.js +544 -340
- package/dist/libs/crud-sharding/ShardingMerger.d.ts +10 -18
- package/dist/libs/crud-sharding/ShardingMerger.js +27 -44
- package/dist/libs/crud-sharding/ShardingResult.d.ts +33 -0
- package/dist/libs/crud-sharding/ShardingResult.js +16 -0
- package/dist/libs/crud-sharding/ShardingRouter.d.ts +1 -0
- package/dist/libs/crud-sharding/ShardingRouter.js +25 -6
- package/dist/libs/crud-sharding/ShardingTableCreator.d.ts +21 -4
- package/dist/libs/crud-sharding/ShardingTableCreator.js +193 -59
- package/dist/libs/crud-sharding/ShardingUtils.d.ts +48 -0
- package/dist/libs/crud-sharding/ShardingUtils.js +122 -1
- package/dist/libs/crud-sharding/TIME_COLUMN_CLEAN_SPEC.md +488 -0
- package/dist/libs/crud-sharding/index.d.ts +4 -3
- package/dist/libs/crud-sharding/index.js +14 -2
- package/dist/models/bizmodels.d.ts +2 -6
- package/dist/service/SysAppService.d.ts +2 -2
- package/dist/service/SysAppService.js +16 -5
- package/dist/service/SysConfigService.d.ts +1 -1
- package/dist/service/SysConfigService.js +7 -2
- package/dist/service/SysDictDataService.js +14 -4
- package/dist/service/SysMenuService.js +7 -2
- package/dist/service/curd/CurdMixService.d.ts +6 -4
- package/dist/service/curd/CurdMixService.js +16 -2
- package/dist/service/curd/CurdProService.d.ts +43 -27
- package/dist/service/curd/CurdProService.js +32 -33
- package/dist/service/flow/FlowConfigService.js +7 -2
- package/dist/service/flow/FlowInstanceCrudService.js +22 -19
- package/package.json +1 -1
- package/src/controller/base/BaseApiController.ts +0 -5
- package/src/controller/gateway/DocGatewayController.ts +1 -1
- package/src/controller/manage/CrudStandardDesignApi.ts +4 -3
- package/src/controller/manage/FlowConfigManageApi.ts +4 -2
- package/src/controller/manage/SysConfigMangeApi.ts +6 -1
- package/src/controller/manage/UserAccountManageApi.ts +7 -2
- package/src/index.ts +2 -2
- package/src/libs/crud-pro/CrudPro.ts +62 -4
- package/src/libs/crud-pro/interfaces.ts +110 -15
- package/src/libs/crud-pro/models/CrudResult.ts +178 -0
- package/src/libs/crud-pro/models/RequestModel.ts +2 -2
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +41 -2
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +11 -7
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +1 -2
- package/src/libs/crud-pro-quick/CrudProQuick.ts +594 -0
- package/src/{service/curd → libs/crud-pro-quick}/fixSoftDelete.ts +23 -13
- package/src/libs/crud-pro-quick/index.ts +52 -0
- package/src/libs/crud-pro-quick/models.ts +35 -0
- package/src/libs/crud-sharding/ShardingConfig.ts +18 -2
- package/src/libs/crud-sharding/ShardingCrudPro.ts +660 -390
- package/src/libs/crud-sharding/ShardingMerger.ts +35 -63
- package/src/libs/crud-sharding/ShardingResult.ts +29 -0
- package/src/libs/crud-sharding/ShardingRouter.ts +27 -6
- package/src/libs/crud-sharding/ShardingTableCreator.ts +214 -71
- package/src/libs/crud-sharding/ShardingUtils.ts +137 -0
- package/src/libs/crud-sharding/TIME_COLUMN_CLEAN_SPEC.md +488 -0
- package/src/libs/crud-sharding/index.ts +14 -3
- package/src/models/bizmodels.ts +4 -7
- package/src/service/SysAppService.ts +18 -7
- package/src/service/SysConfigService.ts +8 -3
- package/src/service/SysDictDataService.ts +14 -4
- package/src/service/SysMenuService.ts +7 -2
- package/src/service/crudstd/CrudStdService.ts +2 -2
- package/src/service/curd/CurdMixService.ts +26 -5
- package/src/service/curd/CurdProService.ts +58 -39
- package/src/service/flow/FlowConfigService.ts +7 -2
- package/src/service/flow/FlowInstanceCrudService.ts +23 -20
- package/.qoder/skills/midway-fatcms-crud/SKILL.md +0 -375
- package/.qoder/skills/midway-fatcms-crud/examples.md +0 -990
- package/.qoder/skills/midway-fatcms-crud/reference.md +0 -568
- package/dist/libs/crud-pro/README.md +0 -809
- package/dist/libs/crud-pro/README_FUNC.md +0 -193
- package/dist/libs/crud-sharding/ROUTING_LOGIC.md +0 -944
- package/dist/models/StandardColumns.d.ts +0 -71
- package/dist/models/StandardColumns.js +0 -28
- package/dist/service/curd/CrudProQuick.d.ts +0 -190
- package/dist/service/curd/CrudProQuick.js +0 -319
- package/dist/service/curd/README.md +0 -1100
- package/dist/service/curd/fixSoftDelete.d.ts +0 -20
- package/src/libs/crud-pro/README.md +0 -809
- package/src/libs/crud-pro/README_FUNC.md +0 -193
- package/src/libs/crud-sharding/ROUTING_LOGIC.md +0 -944
- package/src/models/StandardColumns.ts +0 -76
- package/src/service/curd/CrudProQuick.ts +0 -360
- package/src/service/curd/README.md +0 -1100
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CrudPro } from '../../libs/crud-pro/CrudPro';
|
|
2
2
|
import { IRequestModel, IRequestCfgModel } from '../../libs/crud-pro/interfaces';
|
|
3
|
+
import { ExecuteContext } from '../../libs/crud-pro/models/ExecuteContext';
|
|
3
4
|
import { ShardingCountCache } from './ShardingCountCache';
|
|
4
5
|
/**
|
|
5
6
|
* 分页查询结果
|
|
@@ -7,6 +8,14 @@ import { ShardingCountCache } from './ShardingCountCache';
|
|
|
7
8
|
export interface IShardingPageQueryResult {
|
|
8
9
|
rows: any[];
|
|
9
10
|
total_count: number;
|
|
11
|
+
lastCtx: ExecuteContext | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 列表查询结果
|
|
15
|
+
*/
|
|
16
|
+
export interface IShardingListQueryResult {
|
|
17
|
+
rows: any[];
|
|
18
|
+
lastCtx: ExecuteContext | null;
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
12
21
|
* 分表查询结果合并器
|
|
@@ -65,7 +74,7 @@ export declare class ShardingMerger {
|
|
|
65
74
|
* @param maxRows 最大返回行数(默认 10000,防止 OOM)
|
|
66
75
|
* @returns 数据列表
|
|
67
76
|
*/
|
|
68
|
-
mergeQuery(crudPro: CrudPro, tables: string[], reqJson: IRequestModel, cfgJson: IRequestCfgModel, maxRows?: number): Promise<
|
|
77
|
+
mergeQuery(crudPro: CrudPro, tables: string[], reqJson: IRequestModel, cfgJson: IRequestCfgModel, maxRows?: number): Promise<IShardingListQueryResult>;
|
|
69
78
|
/**
|
|
70
79
|
* 根据各表数量和分页偏移,直接定位目标表
|
|
71
80
|
*
|
|
@@ -95,23 +104,6 @@ export declare class ShardingMerger {
|
|
|
95
104
|
* 支持 COUNT 缓存:历史时间分表使用缓存,当前表实时查询
|
|
96
105
|
*/
|
|
97
106
|
private queryCountSafe;
|
|
98
|
-
/**
|
|
99
|
-
* 安全查询数据行(表不存在时返回空数组)
|
|
100
|
-
*/
|
|
101
|
-
private queryRowsSafe;
|
|
102
|
-
/**
|
|
103
|
-
* 安全查询数据行(支持表内偏移,表不存在时返回空数组)
|
|
104
|
-
*
|
|
105
|
-
* 用于分页定位后,直接从某张表指定偏移处取数据
|
|
106
|
-
*
|
|
107
|
-
* @param crudPro CrudPro 实例
|
|
108
|
-
* @param table 分表名
|
|
109
|
-
* @param reqJson 请求参数
|
|
110
|
-
* @param cfgJson 配置
|
|
111
|
-
* @param innerOffset 表内偏移(跳过前 N 条)
|
|
112
|
-
* @param innerLimit 取多少条
|
|
113
|
-
*/
|
|
114
|
-
private queryRowsSafeWithOffset;
|
|
115
107
|
/**
|
|
116
108
|
* 执行 COUNT 查询
|
|
117
109
|
*/
|
|
@@ -46,25 +46,36 @@ class ShardingMerger {
|
|
|
46
46
|
const { pageNo = 1, pageSize = 10 } = reqJson;
|
|
47
47
|
const offset = (pageNo - 1) * pageSize;
|
|
48
48
|
const targetEnd = offset + pageSize; // 需要取到第几条
|
|
49
|
-
// 1.
|
|
50
|
-
const
|
|
51
|
-
const
|
|
49
|
+
// 1. 串行查询所有分表的记录数
|
|
50
|
+
const counts = [];
|
|
51
|
+
for (const table of tables) {
|
|
52
|
+
const count = await this.queryCountSafe(crudPro, table, reqJson, cfgJson);
|
|
53
|
+
counts.push(count);
|
|
54
|
+
}
|
|
52
55
|
const totalCount = counts.reduce((sum, c) => sum + c, 0);
|
|
53
56
|
// 总数为0,直接返回
|
|
54
57
|
if (totalCount === 0) {
|
|
55
|
-
return { rows: [], total_count: 0 };
|
|
58
|
+
return { rows: [], total_count: 0, lastCtx: null };
|
|
56
59
|
}
|
|
57
60
|
// 2. 根据累计数量直接定位目标表
|
|
58
61
|
const targetTables = this.locateTargetTables(tables, counts, offset, targetEnd);
|
|
59
62
|
// 3. 只查询包含目标数据的分表
|
|
60
63
|
let allRows = [];
|
|
64
|
+
let lastCtx = null;
|
|
61
65
|
for (const target of targetTables) {
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
try {
|
|
67
|
+
const ctx = await this.executeQueryWithOffset(crudPro, target.table, reqJson, cfgJson, target.innerOffset, target.innerLimit);
|
|
68
|
+
lastCtx = ctx;
|
|
69
|
+
allRows = allRows.concat(ctx.getResRows() || []);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
// 表不存在或其他错误,跳过
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
return {
|
|
66
76
|
rows: allRows,
|
|
67
77
|
total_count: totalCount,
|
|
78
|
+
lastCtx,
|
|
68
79
|
};
|
|
69
80
|
}
|
|
70
81
|
/**
|
|
@@ -88,20 +99,27 @@ class ShardingMerger {
|
|
|
88
99
|
async mergeQuery(crudPro, tables, reqJson, cfgJson, maxRows = 10000) {
|
|
89
100
|
// 串行查询分表,按表顺序拼接,达到上限即停
|
|
90
101
|
let allRows = [];
|
|
102
|
+
let lastCtx = null;
|
|
91
103
|
for (const table of tables) {
|
|
92
104
|
const needMore = maxRows - allRows.length;
|
|
93
105
|
if (needMore <= 0) {
|
|
94
106
|
break;
|
|
95
107
|
}
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
try {
|
|
109
|
+
const ctx = await this.executeQuery(crudPro, table, reqJson, cfgJson, needMore);
|
|
110
|
+
lastCtx = ctx;
|
|
111
|
+
allRows = allRows.concat(ctx.getResRows() || []);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
// 表不存在或其他错误,跳过
|
|
115
|
+
}
|
|
98
116
|
// 达到上限后停止,不再查询后续表
|
|
99
117
|
if (allRows.length >= maxRows) {
|
|
100
118
|
allRows = allRows.slice(0, maxRows);
|
|
101
119
|
break;
|
|
102
120
|
}
|
|
103
121
|
}
|
|
104
|
-
return allRows;
|
|
122
|
+
return { rows: allRows, lastCtx };
|
|
105
123
|
}
|
|
106
124
|
// ============ 私有方法:分页定位 ============
|
|
107
125
|
/**
|
|
@@ -192,41 +210,6 @@ class ShardingMerger {
|
|
|
192
210
|
return 0;
|
|
193
211
|
}
|
|
194
212
|
}
|
|
195
|
-
/**
|
|
196
|
-
* 安全查询数据行(表不存在时返回空数组)
|
|
197
|
-
*/
|
|
198
|
-
async queryRowsSafe(crudPro, table, reqJson, cfgJson, limit) {
|
|
199
|
-
try {
|
|
200
|
-
const ctx = await this.executeQuery(crudPro, table, reqJson, cfgJson, limit);
|
|
201
|
-
return ctx.getResRows() || [];
|
|
202
|
-
}
|
|
203
|
-
catch (e) {
|
|
204
|
-
// 表不存在或其他错误,返回空数组
|
|
205
|
-
return [];
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* 安全查询数据行(支持表内偏移,表不存在时返回空数组)
|
|
210
|
-
*
|
|
211
|
-
* 用于分页定位后,直接从某张表指定偏移处取数据
|
|
212
|
-
*
|
|
213
|
-
* @param crudPro CrudPro 实例
|
|
214
|
-
* @param table 分表名
|
|
215
|
-
* @param reqJson 请求参数
|
|
216
|
-
* @param cfgJson 配置
|
|
217
|
-
* @param innerOffset 表内偏移(跳过前 N 条)
|
|
218
|
-
* @param innerLimit 取多少条
|
|
219
|
-
*/
|
|
220
|
-
async queryRowsSafeWithOffset(crudPro, table, reqJson, cfgJson, innerOffset, innerLimit) {
|
|
221
|
-
try {
|
|
222
|
-
const ctx = await this.executeQueryWithOffset(crudPro, table, reqJson, cfgJson, innerOffset, innerLimit);
|
|
223
|
-
return ctx.getResRows() || [];
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
// 表不存在或其他错误,返回空数组
|
|
227
|
-
return [];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
213
|
/**
|
|
231
214
|
* 执行 COUNT 查询
|
|
232
215
|
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ExecuteContext } from '../../libs/crud-pro/models/ExecuteContext';
|
|
2
|
+
import { CrudResultBase } from '../../libs/crud-pro/models/CrudResult';
|
|
3
|
+
/** 分表批量插入结果 */
|
|
4
|
+
declare class ShardingBatchInsertResult extends CrudResultBase {
|
|
5
|
+
readonly totalAffected: number;
|
|
6
|
+
readonly tableResults: Array<{
|
|
7
|
+
table: string;
|
|
8
|
+
affected: number;
|
|
9
|
+
rowCount: number;
|
|
10
|
+
}>;
|
|
11
|
+
readonly tableCount: number;
|
|
12
|
+
readonly success: boolean;
|
|
13
|
+
readonly errors: Array<{
|
|
14
|
+
table: string;
|
|
15
|
+
error: Error;
|
|
16
|
+
}>;
|
|
17
|
+
constructor(data: {
|
|
18
|
+
totalAffected: number;
|
|
19
|
+
tableResults: Array<{
|
|
20
|
+
table: string;
|
|
21
|
+
affected: number;
|
|
22
|
+
rowCount: number;
|
|
23
|
+
}>;
|
|
24
|
+
tableCount: number;
|
|
25
|
+
success: boolean;
|
|
26
|
+
errors: Array<{
|
|
27
|
+
table: string;
|
|
28
|
+
error: Error;
|
|
29
|
+
}>;
|
|
30
|
+
lastContext: ExecuteContext;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { ShardingBatchInsertResult };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShardingBatchInsertResult = void 0;
|
|
4
|
+
const CrudResult_1 = require("../../libs/crud-pro/models/CrudResult");
|
|
5
|
+
/** 分表批量插入结果 */
|
|
6
|
+
class ShardingBatchInsertResult extends CrudResult_1.CrudResultBase {
|
|
7
|
+
constructor(data) {
|
|
8
|
+
super(data.lastContext);
|
|
9
|
+
this.totalAffected = data.totalAffected;
|
|
10
|
+
this.tableResults = data.tableResults;
|
|
11
|
+
this.tableCount = data.tableCount;
|
|
12
|
+
this.success = data.success;
|
|
13
|
+
this.errors = data.errors;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ShardingBatchInsertResult = ShardingBatchInsertResult;
|
|
@@ -114,6 +114,8 @@ class ShardingRouter {
|
|
|
114
114
|
const suffix = (0, ShardingUtils_1.getTimeSuffix)(singleTimeValue, granularity);
|
|
115
115
|
return this.formatTableName(baseTable, suffix, config);
|
|
116
116
|
}
|
|
117
|
+
// 时间分表写操作必须包含时间字段
|
|
118
|
+
// 但查询操作允许回退到 recentTableCount
|
|
117
119
|
const recentCount = this.getRecentCountByGranularity(granularity, config);
|
|
118
120
|
return this.getRecentTables(baseTable, granularity, recentCount, config);
|
|
119
121
|
}
|
|
@@ -167,9 +169,10 @@ class ShardingRouter {
|
|
|
167
169
|
const recentTables = shardingTables.slice(-config.recentTableCount);
|
|
168
170
|
return this.intersectWithCondition(recentTables, config, condition);
|
|
169
171
|
}
|
|
170
|
-
// 未配置 recentTableCount
|
|
172
|
+
// 未配置 recentTableCount:所有表与条件取交集,最多取默认数量
|
|
171
173
|
const intersected = this.intersectWithCondition(shardingTables, config, condition);
|
|
172
|
-
|
|
174
|
+
const defaultCount = this.getDefaultRecentCount(config);
|
|
175
|
+
return intersected.slice(0, defaultCount);
|
|
173
176
|
}
|
|
174
177
|
intersectWithCondition(tables, config, condition) {
|
|
175
178
|
if (!condition) {
|
|
@@ -186,6 +189,7 @@ class ShardingRouter {
|
|
|
186
189
|
const targetTable = `${config.baseTable}_${suffix}`;
|
|
187
190
|
return tables.includes(targetTable) ? [targetTable] : [];
|
|
188
191
|
}
|
|
192
|
+
// condition 存在但不包含时间字段,返回所有表(按时间降序)
|
|
189
193
|
return this.sortTablesByTimeDesc(tables);
|
|
190
194
|
}
|
|
191
195
|
intersectTablesByTimeRange(tables, timeRange, config) {
|
|
@@ -317,6 +321,7 @@ class ShardingRouter {
|
|
|
317
321
|
}
|
|
318
322
|
return tables;
|
|
319
323
|
}
|
|
324
|
+
// ============ 格式化 ============
|
|
320
325
|
getRecentTables(baseTable, granularity, count, config) {
|
|
321
326
|
const tables = [];
|
|
322
327
|
const current = moment();
|
|
@@ -343,14 +348,28 @@ class ShardingRouter {
|
|
|
343
348
|
}
|
|
344
349
|
switch (granularity) {
|
|
345
350
|
case 'year':
|
|
346
|
-
return
|
|
351
|
+
return 2;
|
|
347
352
|
case 'month':
|
|
348
|
-
return
|
|
353
|
+
return 3;
|
|
349
354
|
case 'day':
|
|
350
355
|
return 7;
|
|
351
356
|
}
|
|
352
357
|
}
|
|
353
|
-
|
|
358
|
+
getDefaultRecentCount(config) {
|
|
359
|
+
if (config.recentTableCount !== undefined && config.recentTableCount > 0) {
|
|
360
|
+
return config.recentTableCount;
|
|
361
|
+
}
|
|
362
|
+
switch (config.type) {
|
|
363
|
+
case ShardingConfig_1.ShardingType.YEAR:
|
|
364
|
+
return 2;
|
|
365
|
+
case ShardingConfig_1.ShardingType.MONTH:
|
|
366
|
+
return 3;
|
|
367
|
+
case ShardingConfig_1.ShardingType.DAY:
|
|
368
|
+
return 7;
|
|
369
|
+
default:
|
|
370
|
+
return 3;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
354
373
|
calculateRangeIndex(value, count) {
|
|
355
374
|
if (typeof value === 'number') {
|
|
356
375
|
return Math.abs(value) % count;
|
|
@@ -368,7 +387,7 @@ class ShardingRouter {
|
|
|
368
387
|
}
|
|
369
388
|
return hash;
|
|
370
389
|
}
|
|
371
|
-
// ============
|
|
390
|
+
// ============ 表名格式化 ============
|
|
372
391
|
formatTableName(baseTable, suffix, config) {
|
|
373
392
|
const formattedSuffix = config.suffixFormatter ? config.suffixFormatter(suffix) : suffix;
|
|
374
393
|
return `${baseTable}_${formattedSuffix}`;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CrudPro } from '../../libs/crud-pro/CrudPro';
|
|
2
1
|
import { SqlDbType } from '../../libs/crud-pro/models/keys';
|
|
3
|
-
import { IShardingConfig, IShardingTableCreateOptions, IShardingTableCreateResult } from './ShardingConfig';
|
|
2
|
+
import { CrudProFactory, IShardingConfig, IShardingTableCreateOptions, IShardingTableCreateResult } from './ShardingConfig';
|
|
4
3
|
/**
|
|
5
4
|
* 分表自动创建器
|
|
6
5
|
*
|
|
@@ -14,9 +13,9 @@ import { IShardingConfig, IShardingTableCreateOptions, IShardingTableCreateResul
|
|
|
14
13
|
* });
|
|
15
14
|
*/
|
|
16
15
|
export declare class ShardingTableCreator {
|
|
17
|
-
private readonly
|
|
16
|
+
private readonly crudProFactory;
|
|
18
17
|
private readonly config;
|
|
19
|
-
constructor(
|
|
18
|
+
constructor(crudProFactory: CrudProFactory, config: IShardingConfig);
|
|
20
19
|
/**
|
|
21
20
|
* 校验表名格式,防止 SQL 注入
|
|
22
21
|
* 只允许合法的数据库标识符:以字母或下划线开头,后续只能包含字母数字下划线
|
|
@@ -34,6 +33,12 @@ export declare class ShardingTableCreator {
|
|
|
34
33
|
sqlDatabase: string;
|
|
35
34
|
sqlDbType: SqlDbType;
|
|
36
35
|
}, options?: IShardingTableCreateOptions): Promise<IShardingTableCreateResult>;
|
|
36
|
+
/**
|
|
37
|
+
* 检查表是否已存在
|
|
38
|
+
* 复用 CrudPro.getAllTableInfos 接口,使用缓存提升性能
|
|
39
|
+
* DDL 操作本身具有幂等性(CREATE TABLE IF NOT EXISTS),缓存短暂延迟可接受
|
|
40
|
+
*/
|
|
41
|
+
private checkTableExists;
|
|
37
42
|
/**
|
|
38
43
|
* 获取基表列信息
|
|
39
44
|
*/
|
|
@@ -102,6 +107,10 @@ export declare class ShardingTableCreator {
|
|
|
102
107
|
* 执行建表 SQL
|
|
103
108
|
*/
|
|
104
109
|
private executeCreateSql;
|
|
110
|
+
/**
|
|
111
|
+
* 判断是否为"已存在"类错误(表已存在、索引已存在等)
|
|
112
|
+
*/
|
|
113
|
+
private isDuplicateError;
|
|
105
114
|
/**
|
|
106
115
|
* 复制索引(可选功能)
|
|
107
116
|
*
|
|
@@ -109,6 +118,14 @@ export declare class ShardingTableCreator {
|
|
|
109
118
|
* 注意:主键索引已在建表时创建,此处只复制普通索引。
|
|
110
119
|
*/
|
|
111
120
|
private copyIndexes;
|
|
121
|
+
/**
|
|
122
|
+
* 获取目标表已存在的所有索引名
|
|
123
|
+
*/
|
|
124
|
+
private getExistingIndexNames;
|
|
125
|
+
/**
|
|
126
|
+
* 从 CREATE INDEX 语句中提取索引名
|
|
127
|
+
*/
|
|
128
|
+
private extractIndexName;
|
|
112
129
|
/**
|
|
113
130
|
* 在索引 SQL 中替换表名
|
|
114
131
|
*
|