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
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrudProQuick = void 0;
|
|
4
|
+
const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
5
|
+
const fixSoftDelete_1 = require("./fixSoftDelete");
|
|
6
|
+
const CrudResult_1 = require("../../libs/crud-pro/models/CrudResult");
|
|
7
|
+
const DEFAULT_MAX_LIMIT = 10 * 10000;
|
|
8
|
+
/**
|
|
9
|
+
* 快捷 CRUD 操作封装器
|
|
10
|
+
*
|
|
11
|
+
* 在 CrudPro 之上封装便捷方法,提供简洁的 API 进行单表 CRUD 操作。
|
|
12
|
+
* 内部使用工厂函数模式,每次操作都会获取新的 CrudPro 实例,因此**可以安全复用**。
|
|
13
|
+
*
|
|
14
|
+
* **使用限制:**
|
|
15
|
+
* - CrudProQuick 可以安全复用(内部每次获取新 CrudPro)
|
|
16
|
+
* - 必须通过 CurdProService.getQuickCrud() 获取实例
|
|
17
|
+
* - sqlTable 必填(构造时或每次调用时传入)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // 通过 CurdProService 获取实例
|
|
21
|
+
* const quick = curdProService.getQuickCrud('mydb', SqlDbType.mysql, 't_user');
|
|
22
|
+
*
|
|
23
|
+
* // 查询列表
|
|
24
|
+
* const result = await quick.findList({ condition: { status: 1 } });
|
|
25
|
+
* console.log(result.rows, result.count);
|
|
26
|
+
*
|
|
27
|
+
* // 插入数据
|
|
28
|
+
* const insertResult = await quick.insert({ data: { name: '张三', age: 20 } });
|
|
29
|
+
* console.log(insertResult.affectedRows, insertResult.insertId);
|
|
30
|
+
*
|
|
31
|
+
* // 可以安全复用
|
|
32
|
+
* const updateResult = await quick.update({ condition: { id: 1 }, data: { age: 21 } });
|
|
33
|
+
*/
|
|
34
|
+
class CrudProQuick {
|
|
35
|
+
/**
|
|
36
|
+
* 构造函数(工厂函数模式)
|
|
37
|
+
* @param args 工厂函数参数
|
|
38
|
+
*/
|
|
39
|
+
constructor(args) {
|
|
40
|
+
this.baseCfgModel = {
|
|
41
|
+
maxLimit: DEFAULT_MAX_LIMIT,
|
|
42
|
+
};
|
|
43
|
+
this.sqlDatabase = args.sqlDatabase;
|
|
44
|
+
this.sqlDbType = args.sqlDbType;
|
|
45
|
+
this.sqlTable = args.sqlTable;
|
|
46
|
+
this.crudProFactory = args.crudProFactory;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 设置基础配置模型,合并到实例的 baseCfgModel 中,后续所有 CRUD 操作都会携带这些配置
|
|
50
|
+
* 例如可以统一设置 maxLimit、enableSoftDelete 等公共参数,避免每次调用都重复传入
|
|
51
|
+
* @param baseCfgModel 要合并的配置项
|
|
52
|
+
*/
|
|
53
|
+
setBaseCfgModel(baseCfgModel) {
|
|
54
|
+
Object.assign(this.baseCfgModel, baseCfgModel);
|
|
55
|
+
}
|
|
56
|
+
async executeCrudByCfg(reqJson, cfgModel2) {
|
|
57
|
+
const cfgModel = { ...this.baseCfgModel };
|
|
58
|
+
Object.assign(cfgModel, cfgModel2);
|
|
59
|
+
cfgModel.method = 'CrudProQuickAnonymous';
|
|
60
|
+
cfgModel.updateCfg = {};
|
|
61
|
+
cfgModel.sqlDatabase = this.sqlDatabase;
|
|
62
|
+
cfgModel.sqlDbType = this.sqlDbType;
|
|
63
|
+
if (!cfgModel.sqlTable) {
|
|
64
|
+
cfgModel.sqlTable = this.sqlTable;
|
|
65
|
+
}
|
|
66
|
+
if (!cfgModel.sqlTable) {
|
|
67
|
+
throw new Error('[CrudProQuick] sqlTable not found');
|
|
68
|
+
}
|
|
69
|
+
// 创建 CrudPro 实例并设置 visitor
|
|
70
|
+
const crudPro = this.crudProFactory();
|
|
71
|
+
// 应用软删除动作。
|
|
72
|
+
(0, fixSoftDelete_1.fixSoftDelete)(cfgModel.sqlSimpleName, cfgModel, reqJson, crudPro.getVisitor());
|
|
73
|
+
return await crudPro.executeCrudByCfg(reqJson, cfgModel);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 查询单条记录
|
|
77
|
+
* @param reqJson 请求参数
|
|
78
|
+
* @param sqlTable 数据库表名称
|
|
79
|
+
* @returns CrudQueryOneResult 包含 row、found 和 getRawContext()
|
|
80
|
+
*/
|
|
81
|
+
async findOne(reqJson, sqlTable) {
|
|
82
|
+
const cfgModel = {
|
|
83
|
+
sqlTable,
|
|
84
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
85
|
+
};
|
|
86
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
87
|
+
const row = ctx.getOneObj();
|
|
88
|
+
return new CrudResult_1.CrudQueryOneResult({ row, rawContext: ctx, debugInfo: this.buildDebugInfo(sqlTable, reqJson.condition) });
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 查询唯一单条记录(期望结果为 0 条或 1 条)
|
|
92
|
+
*
|
|
93
|
+
* 与 findOne 不同,此方法会校验查询结果的唯一性:
|
|
94
|
+
* - 如果查到 0 条:返回 row = null
|
|
95
|
+
* - 如果查到 1 条:正常返回
|
|
96
|
+
* - 如果查到多条:抛出异常,包含详细的定位信息
|
|
97
|
+
*
|
|
98
|
+
* @param reqJson 请求参数
|
|
99
|
+
* @param sqlTable 数据库表名称
|
|
100
|
+
* @returns CrudQueryOneResult 包含 row、found 和 getRawContext()
|
|
101
|
+
* @throws Error 如果查询到多条记录
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // 根据唯一索引查询单条
|
|
105
|
+
* const result = await quick.findUniqueOne({ condition: { email: 'user@example.com' } });
|
|
106
|
+
* if (result.found) {
|
|
107
|
+
* console.log(result.row);
|
|
108
|
+
* }
|
|
109
|
+
*/
|
|
110
|
+
async findUniqueOne(reqJson, sqlTable) {
|
|
111
|
+
const effectiveTable = sqlTable || this.sqlTable;
|
|
112
|
+
// 使用 maxLimit: 2 查询,判断是否有多条
|
|
113
|
+
const cfgModel = {
|
|
114
|
+
sqlTable: effectiveTable,
|
|
115
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
116
|
+
maxLimit: 2,
|
|
117
|
+
};
|
|
118
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
119
|
+
const rows = ctx.getResRows();
|
|
120
|
+
if (rows.length > 1) {
|
|
121
|
+
const debugInfo = this.buildDebugInfo(effectiveTable, reqJson.condition);
|
|
122
|
+
const errorMsg = this.formatUniqueError(rows.length, debugInfo);
|
|
123
|
+
throw new Error(errorMsg);
|
|
124
|
+
}
|
|
125
|
+
return new CrudResult_1.CrudQueryOneResult({
|
|
126
|
+
row: rows[0] || null,
|
|
127
|
+
rawContext: ctx,
|
|
128
|
+
debugInfo: this.buildDebugInfo(effectiveTable, reqJson.condition),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 构建辅助定位信息
|
|
133
|
+
*/
|
|
134
|
+
buildDebugInfo(sqlTable, condition) {
|
|
135
|
+
const info = {
|
|
136
|
+
sqlDatabase: this.sqlDatabase,
|
|
137
|
+
sqlTable: sqlTable || this.sqlTable || 'unknown',
|
|
138
|
+
};
|
|
139
|
+
if (condition) {
|
|
140
|
+
info.condition = condition;
|
|
141
|
+
}
|
|
142
|
+
return info;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 格式化唯一性错误消息
|
|
146
|
+
*/
|
|
147
|
+
formatUniqueError(foundCount, debugInfo) {
|
|
148
|
+
const parts = [
|
|
149
|
+
`[CrudProQuick] findUniqueOne 期望唯一一条记录,但查询到 ${foundCount} 条`,
|
|
150
|
+
];
|
|
151
|
+
if (debugInfo.sqlDatabase) {
|
|
152
|
+
parts.push(`数据库: ${debugInfo.sqlDatabase}`);
|
|
153
|
+
}
|
|
154
|
+
if (debugInfo.sqlTable) {
|
|
155
|
+
parts.push(`表: ${debugInfo.sqlTable}`);
|
|
156
|
+
}
|
|
157
|
+
if (debugInfo.condition) {
|
|
158
|
+
try {
|
|
159
|
+
parts.push(`条件: ${JSON.stringify(debugInfo.condition)}`);
|
|
160
|
+
}
|
|
161
|
+
catch (_a) {
|
|
162
|
+
parts.push(`条件: [无法序列化]`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return parts.join(' | ');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 查询数据列表
|
|
169
|
+
* @param reqJson 请求参数
|
|
170
|
+
* @param sqlTable 数据库表名称
|
|
171
|
+
* @returns CrudQueryListResult 包含 rows、count 和 getRawContext()
|
|
172
|
+
*/
|
|
173
|
+
async findList(reqJson, sqlTable) {
|
|
174
|
+
const cfgModel = {
|
|
175
|
+
sqlTable,
|
|
176
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
177
|
+
};
|
|
178
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
179
|
+
const rows = ctx.getResRows();
|
|
180
|
+
return new CrudResult_1.CrudQueryListResult({ rows, rawContext: ctx });
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 分页查询数据列表
|
|
184
|
+
* 内部使用 SIMPLE_QUERY_PAGE 模式,reqJson 中可传入 pageNo、pageSize 控制分页
|
|
185
|
+
* @param reqJson 请求参数,支持 condition(查询条件)、pageNo、pageSize 等
|
|
186
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
187
|
+
* @returns CrudQueryPageResult 包含 rows、totalCount、count 和 getRawContext()
|
|
188
|
+
*/
|
|
189
|
+
async findPage(reqJson, sqlTable) {
|
|
190
|
+
const cfgModel = {
|
|
191
|
+
sqlTable,
|
|
192
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE,
|
|
193
|
+
};
|
|
194
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
195
|
+
const pageResult = ctx.getResModelForQueryPage();
|
|
196
|
+
return new CrudResult_1.CrudQueryPageResult({
|
|
197
|
+
rows: pageResult.rows,
|
|
198
|
+
totalCount: pageResult.total_count,
|
|
199
|
+
rawContext: ctx,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 判断满足条件的记录是否存在
|
|
204
|
+
* 内部使用 SIMPLE_QUERY_EXIST 模式,通过 SELECT EXISTS 子查询实现,找到首条匹配即返回,比 COUNT(*) 更高效
|
|
205
|
+
* @param reqJson 请求参数,通过 condition 指定查询条件
|
|
206
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
207
|
+
* @returns CrudExistResult 包含 exists 和 getRawContext()
|
|
208
|
+
*/
|
|
209
|
+
async isExist(reqJson, sqlTable) {
|
|
210
|
+
const cfgModel = {
|
|
211
|
+
sqlTable,
|
|
212
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_EXIST,
|
|
213
|
+
};
|
|
214
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
215
|
+
const exists = ctx.getResModel().is_exist;
|
|
216
|
+
return new CrudResult_1.CrudExistResult({ exists, rawContext: ctx });
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 查询满足条件的记录总数
|
|
220
|
+
* 内部使用 SIMPLE_QUERY_COUNT 模式,仅返回 count 结果
|
|
221
|
+
* @param reqJson 请求参数,通过 condition 指定查询条件
|
|
222
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
223
|
+
* @returns CrudCountResult 包含 count 和 getRawContext()
|
|
224
|
+
*/
|
|
225
|
+
async findCount(reqJson, sqlTable) {
|
|
226
|
+
const cfgModel = {
|
|
227
|
+
sqlTable,
|
|
228
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT,
|
|
229
|
+
};
|
|
230
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
231
|
+
const count = ctx.getResModel().total_count || 0;
|
|
232
|
+
return new CrudResult_1.CrudCountResult({ count, rawContext: ctx });
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 插入一条数据记录
|
|
236
|
+
* 内部使用 SIMPLE_INSERT 模式,通过 reqJson.data 传入要插入的字段和值
|
|
237
|
+
* @param reqJson 请求参数,data 字段中包含要插入的键值对
|
|
238
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
239
|
+
* @returns CrudWriteResult 包含 affectedRows、insertId 和 getRawContext()
|
|
240
|
+
*/
|
|
241
|
+
async insert(reqJson, sqlTable) {
|
|
242
|
+
const cfgModel = {
|
|
243
|
+
sqlTable,
|
|
244
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT,
|
|
245
|
+
};
|
|
246
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
247
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
248
|
+
return new CrudResult_1.CrudWriteResult({
|
|
249
|
+
affectedRows: affected.affectedRows,
|
|
250
|
+
insertId: affected.insertId,
|
|
251
|
+
rawContext: ctx,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 批量插入数据记录
|
|
256
|
+
* 内部使用 SIMPLE_BATCH_INSERT 模式,单条 SQL 插入多行数据,效率远高于循环单条插入
|
|
257
|
+
*
|
|
258
|
+
* @param reqJson 请求参数,data 为对象数组 [{name:'a'},{name:'b'}]
|
|
259
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
260
|
+
* @returns CrudWriteResult 包含 affectedRows、insertId 和 getRawContext()
|
|
261
|
+
*
|
|
262
|
+
* 注意事项:
|
|
263
|
+
* - affectedRows: 返回实际插入的行数,所有数据库均正确返回
|
|
264
|
+
* - insertId: 仅返回第一条记录的自增ID,后续记录的ID需通过 insertId + index 推算
|
|
265
|
+
* - MySQL: 返回第一条的 insertId
|
|
266
|
+
* - PostgreSQL: RETURNING * 返回所有行,但仅取第一条的 id
|
|
267
|
+
* - SQL Server: OUTPUT 返回所有行,但仅取第一条的 id
|
|
268
|
+
*/
|
|
269
|
+
async batchInsert(reqJson, sqlTable) {
|
|
270
|
+
const cfgModel = {
|
|
271
|
+
sqlTable,
|
|
272
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_BATCH_INSERT,
|
|
273
|
+
};
|
|
274
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
275
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
276
|
+
return new CrudResult_1.CrudWriteResult({
|
|
277
|
+
affectedRows: affected.affectedRows,
|
|
278
|
+
insertId: affected.insertId,
|
|
279
|
+
rawContext: ctx,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* 更新数据记录
|
|
284
|
+
* 内部使用 SIMPLE_UPDATE 模式,通过 reqJson.data 传入要更新的字段和值,通过 reqJson.condition 指定更新条件
|
|
285
|
+
* @param reqJson 请求参数,data 为更新内容,condition 为更新条件
|
|
286
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
287
|
+
* @returns CrudWriteResult 包含 affectedRows 和 getRawContext()
|
|
288
|
+
*/
|
|
289
|
+
async update(reqJson, sqlTable) {
|
|
290
|
+
const cfgModel = {
|
|
291
|
+
sqlTable,
|
|
292
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
|
|
293
|
+
};
|
|
294
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
295
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
296
|
+
return new CrudResult_1.CrudWriteResult({
|
|
297
|
+
affectedRows: affected.affectedRows,
|
|
298
|
+
insertId: affected.insertId,
|
|
299
|
+
rawContext: ctx,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* 插入或更新数据记录(upsert)
|
|
304
|
+
* 内部使用 SIMPLE_INSERT_OR_UPDATE 模式,若记录已存在则更新,不存在则插入
|
|
305
|
+
* @param reqJson 请求参数,data 为要插入/更新的内容,condition 为判断条件
|
|
306
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
307
|
+
* @returns CrudUpsertResult 包含 affected、insertAffected、updateAffected、isExist 和 getRawContext()
|
|
308
|
+
*/
|
|
309
|
+
async insertOrUpdate(reqJson, sqlTable) {
|
|
310
|
+
var _a;
|
|
311
|
+
const cfgModel = {
|
|
312
|
+
sqlTable,
|
|
313
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE,
|
|
314
|
+
};
|
|
315
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
316
|
+
const resModel = ctx.getResModel();
|
|
317
|
+
return new CrudResult_1.CrudUpsertResult({
|
|
318
|
+
affected: resModel.affected,
|
|
319
|
+
insertAffected: resModel.insert_affected,
|
|
320
|
+
updateAffected: resModel.update_affected,
|
|
321
|
+
isExist: (_a = resModel.is_exist) !== null && _a !== void 0 ? _a : false,
|
|
322
|
+
rawContext: ctx,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* 使用数据库原生 upsert 语法插入或更新(ON DUPLICATE KEY UPDATE / ON CONFLICT / MERGE)
|
|
327
|
+
* 内部使用 SIMPLE_INSERT_ON_DUPLICATE_UPDATE 模式,单条 SQL 完成 upsert,效率更高
|
|
328
|
+
*
|
|
329
|
+
* 数据库差异:
|
|
330
|
+
* - MySQL: ON DUPLICATE KEY UPDATE(依赖唯一索引/主键)
|
|
331
|
+
* - PostgreSQL: ON CONFLICT (...) DO UPDATE(需配置 uniqueColumn)
|
|
332
|
+
* - SQL Server: IF EXISTS ... ELSE ...(需配置 uniqueColumn,仅支持单列)
|
|
333
|
+
*
|
|
334
|
+
* @param reqJson 请求参数,data 为要插入/更新的内容
|
|
335
|
+
* @param uniqueColumn 唯一列名(PostgreSQL/SQL Server 必需),PostgreSQL 支持多列,SQL Server 仅支持单列
|
|
336
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
337
|
+
* @returns CrudWriteResult 包含 affectedRows、insertId 和 getRawContext()
|
|
338
|
+
*/
|
|
339
|
+
async insertOnDuplicateUpdate(reqJson, uniqueColumn, sqlTable) {
|
|
340
|
+
const cfgModel = {
|
|
341
|
+
sqlTable,
|
|
342
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE,
|
|
343
|
+
uniqueColumn,
|
|
344
|
+
};
|
|
345
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
346
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
347
|
+
return new CrudResult_1.CrudWriteResult({
|
|
348
|
+
affectedRows: affected.affectedRows,
|
|
349
|
+
insertId: affected.insertId,
|
|
350
|
+
rawContext: ctx,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 删除数据记录
|
|
355
|
+
* 内部使用 SIMPLE_DELETE 模式,通过 reqJson.condition 指定删除条件
|
|
356
|
+
* 注意:如果启用了软删除,实际执行的是更新操作而非物理删除
|
|
357
|
+
* @param reqJson 请求参数,condition 为删除条件
|
|
358
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
359
|
+
* @returns CrudWriteResult 包含 affectedRows 和 getRawContext()
|
|
360
|
+
*/
|
|
361
|
+
async delete(reqJson, sqlTable) {
|
|
362
|
+
const cfgModel = {
|
|
363
|
+
sqlTable,
|
|
364
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_DELETE,
|
|
365
|
+
};
|
|
366
|
+
const ctx = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
367
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
368
|
+
return new CrudResult_1.CrudWriteResult({
|
|
369
|
+
affectedRows: affected.affectedRows,
|
|
370
|
+
insertId: affected.insertId,
|
|
371
|
+
rawContext: ctx,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 恢复软删除的记录
|
|
376
|
+
* 将 deleted_at 字段重置为 0,deleted_by 重置为空字符串
|
|
377
|
+
*
|
|
378
|
+
* @param reqJson 请求参数,通过 condition 指定要恢复的记录
|
|
379
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
380
|
+
* @returns CrudWriteResult 包含 affectedRows 和 getRawContext()
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* // 恢复指定 ID 的记录
|
|
384
|
+
* await quick.restore({ condition: { id: 1 } });
|
|
385
|
+
*
|
|
386
|
+
* // 恢复多条记录(使用 $in 操作符)
|
|
387
|
+
* await quick.restore({ condition: { id: { $in: [1, 2, 3] } } });
|
|
388
|
+
*
|
|
389
|
+
* // 按条件批量恢复记录
|
|
390
|
+
* await quick.restore({ condition: { status: 'deleted' } });
|
|
391
|
+
*/
|
|
392
|
+
async restore(reqJson, sqlTable) {
|
|
393
|
+
const effectiveTable = sqlTable || this.sqlTable;
|
|
394
|
+
if (!reqJson.condition || Object.keys(reqJson.condition).length === 0) {
|
|
395
|
+
throw new Error('[CrudProQuick] restore 操作必须指定恢复条件');
|
|
396
|
+
}
|
|
397
|
+
// 构建恢复数据:重置软删除字段
|
|
398
|
+
const restoreReqJson = {
|
|
399
|
+
...reqJson,
|
|
400
|
+
data: {
|
|
401
|
+
...reqJson.data,
|
|
402
|
+
deleted_at: 0,
|
|
403
|
+
deleted_by: '',
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
const cfgModel = {
|
|
407
|
+
sqlTable: effectiveTable,
|
|
408
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
|
|
409
|
+
};
|
|
410
|
+
const ctx = await this.executeCrudByCfg(restoreReqJson, cfgModel);
|
|
411
|
+
const affected = ctx.getResModel().affected || { affectedRows: 0 };
|
|
412
|
+
return new CrudResult_1.CrudWriteResult({
|
|
413
|
+
affectedRows: affected.affectedRows,
|
|
414
|
+
insertId: affected.insertId,
|
|
415
|
+
rawContext: ctx,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* 根据主键 ID 查询单条记录
|
|
420
|
+
*
|
|
421
|
+
* 等价于 `findUniqueOne({ condition: { id } })`,但更简洁。
|
|
422
|
+
* 使用 findUniqueOne 确保结果唯一性,如果查询到多条记录会抛出异常。
|
|
423
|
+
*
|
|
424
|
+
* @param id 主键值
|
|
425
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
426
|
+
* @returns CrudQueryOneResult 包含 row、found 和 getRawContext()
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* // 根据 ID 查询单条
|
|
430
|
+
* const result = await quick.findOneById(1);
|
|
431
|
+
* if (result.found) {
|
|
432
|
+
* console.log(result.row);
|
|
433
|
+
* }
|
|
434
|
+
*
|
|
435
|
+
* // 指定表名
|
|
436
|
+
* const result = await quick.findOneById('ORD001', 't_order');
|
|
437
|
+
*/
|
|
438
|
+
async findOneById(id, sqlTable) {
|
|
439
|
+
return this.findUniqueOne({ condition: { id } }, sqlTable);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 根据主键 ID 列表查询多条记录
|
|
443
|
+
*
|
|
444
|
+
* 等价于 `findList({ condition: { id: { $in: ids } } })`,但更简洁。
|
|
445
|
+
*
|
|
446
|
+
* @param ids 主键值数组
|
|
447
|
+
* @param sqlTable 数据库表名,若构造实例时已设置全局 sqlTable 则可省略
|
|
448
|
+
* @returns CrudQueryListResult 包含 rows、count 和 getRawContext()
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* // 根据 ID 列表查询
|
|
452
|
+
* const result = await quick.findListByIds([1, 2, 3]);
|
|
453
|
+
* console.log(result.rows, result.count);
|
|
454
|
+
*
|
|
455
|
+
* // 指定表名
|
|
456
|
+
* const result = await quick.findListByIds(['ORD001', 'ORD002'], 't_order');
|
|
457
|
+
*/
|
|
458
|
+
async findListByIds(ids, sqlTable) {
|
|
459
|
+
return this.findList({ condition: { id: { $in: ids } } }, sqlTable);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* 执行自定义 SQL 语句(经 CrudPro 框架封装处理)
|
|
463
|
+
* 与 executeNativeSQL 不同,此方法执行的 SQL 会经过框架的参数绑定等安全处理
|
|
464
|
+
* @param executeSql 要执行的 SQL 语句,支持参数占位符
|
|
465
|
+
* @param args SQL 参数数组,与占位符一一对应
|
|
466
|
+
* @returns 返回未被包装的数据库原始结果(根据 resPicker 配置返回不同类型,无 {code, data, message} 包装层)
|
|
467
|
+
*/
|
|
468
|
+
async executeSQL(executeSql, args) {
|
|
469
|
+
const sqlCfgModel = {
|
|
470
|
+
executeSql: executeSql,
|
|
471
|
+
executeSqlArgs: args,
|
|
472
|
+
sqlDatabase: this.sqlDatabase,
|
|
473
|
+
sqlDbType: this.sqlDbType,
|
|
474
|
+
maxLimit: this.baseCfgModel.maxLimit || DEFAULT_MAX_LIMIT,
|
|
475
|
+
};
|
|
476
|
+
return await this.crudProFactory().executeSQL(sqlCfgModel);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* 执行数据库的原生SQL语句,不做任何封装
|
|
480
|
+
*
|
|
481
|
+
* 返回值结构取决于 SQL 类型和数据库类型:
|
|
482
|
+
*
|
|
483
|
+
* **SELECT 查询**: 返回行数据数组
|
|
484
|
+
*
|
|
485
|
+
* **INSERT/UPDATE/DELETE**: 返回数据库驱动的原始结果
|
|
486
|
+
* - MySQL: `NativeSqlResultMySQL` - 包含 insertId、affectedRows、changedRows 等
|
|
487
|
+
* - PostgreSQL: 空数组(pg 驱动返回 rows 为空)
|
|
488
|
+
* - SQL Server: 空数组(mssql 驱动返回 recordset 为空)
|
|
489
|
+
*
|
|
490
|
+
* **注意**:
|
|
491
|
+
* - 使用 `?` 作为占位符,框架会自动转换为对应数据库的占位符
|
|
492
|
+
* - PostgreSQL/SQL Server 会将 `?` 转换为 `$1, $2, ...` 或 `@fatcms_ms1, @fatcms_ms2, ...`
|
|
493
|
+
*
|
|
494
|
+
* @typeParam T 行数据的类型,默认 Record<string, any>。
|
|
495
|
+
* 影响的是 ExecuteSQLRowsResult 和 ExecuteSQLSingleResult 中的行类型
|
|
496
|
+
*
|
|
497
|
+
* @param executeNativeSql 原生 SQL 语句,使用 `?` 作为参数占位符
|
|
498
|
+
* @param args 参数数组,与 SQL 中的 `?` 一一对应
|
|
499
|
+
* @returns 根据 SQL 类型返回对应结果(ExecuteSQLResult 联合类型)
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* // SELECT 查询 - 使用自定义行类型,返回 ExecuteSQLRowsResult
|
|
503
|
+
* const rows = await crudProQuick.executeNativeSQL<{id: number, name: string}>(
|
|
504
|
+
* 'SELECT id, name FROM user WHERE age > ?',
|
|
505
|
+
* [18]
|
|
506
|
+
* );
|
|
507
|
+
* // rows 类型为 ExecuteSQLResult<{id: number, name: string}>
|
|
508
|
+
* // 实际运行时如果是 SELECT 查询,返回的是 ExecuteSQLRowsResult<{id: number, name: string}>
|
|
509
|
+
*
|
|
510
|
+
* // INSERT - MySQL
|
|
511
|
+
* const result = await crudProQuick.executeNativeSQL(
|
|
512
|
+
* 'INSERT INTO user (name, age) VALUES (?, ?)',
|
|
513
|
+
* ['张三', 20]
|
|
514
|
+
* );
|
|
515
|
+
* // result 类型为 ExecuteSQLResult,实际运行时返回 ExecuteSQLUpdateResult
|
|
516
|
+
*/
|
|
517
|
+
async executeNativeSQL(executeNativeSql, args) {
|
|
518
|
+
const sqlCfgModel = {
|
|
519
|
+
isNativeSQL: true,
|
|
520
|
+
executeSql: executeNativeSql,
|
|
521
|
+
executeSqlArgs: args,
|
|
522
|
+
sqlDatabase: this.sqlDatabase,
|
|
523
|
+
sqlDbType: this.sqlDbType,
|
|
524
|
+
maxLimit: this.baseCfgModel.maxLimit || DEFAULT_MAX_LIMIT,
|
|
525
|
+
};
|
|
526
|
+
return await this.crudProFactory().executeSQL(sqlCfgModel);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
exports.CrudProQuick = CrudProQuick;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { KeysOfSimpleSQL } from "../../libs/crud-pro/models/keys";
|
|
2
|
+
import { IRequestModel, IVisitor } from "../../libs/crud-pro/interfaces";
|
|
3
|
+
import { IRequestCfgModel2 } from "./models";
|
|
4
|
+
/**
|
|
5
|
+
* 软删除需要的用户信息(最小子集)
|
|
6
|
+
*/
|
|
7
|
+
interface ISoftDeleteUserInfo {
|
|
8
|
+
accountId: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 获取当前用户信息的函数类型
|
|
12
|
+
*/
|
|
13
|
+
declare type GetCurrentUserFunc = () => ISoftDeleteUserInfo | null | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 软删除处理函数
|
|
16
|
+
*
|
|
17
|
+
* 当 cfgModel.enableSoftDelete === true 时,自动处理软删除逻辑:
|
|
18
|
+
*
|
|
19
|
+
* 1. INSERT 操作:自动设置 deleted_at = 0
|
|
20
|
+
* 2. DELETE 操作:转为 UPDATE,设置 deleted_at = 时间戳, deleted_by = 当前用户
|
|
21
|
+
* 3. QUERY 操作:自动添加 deleted_at = 0 条件
|
|
22
|
+
*
|
|
23
|
+
* @param oldSqlSimpleName 原始 SQL 类型
|
|
24
|
+
* @param cfgModel 配置模型
|
|
25
|
+
* @param params 请求参数(会被修改)
|
|
26
|
+
* @param visitor 获取当前用户信息的函数(用于软删除时记录删除人)
|
|
27
|
+
*/
|
|
28
|
+
declare function fixSoftDelete(oldSqlSimpleName: KeysOfSimpleSQL, cfgModel: IRequestCfgModel2, params: IRequestModel, visitor?: IVisitor): void;
|
|
29
|
+
export { fixSoftDelete, };
|
|
30
|
+
export type { ISoftDeleteUserInfo, GetCurrentUserFunc };
|
|
@@ -14,10 +14,9 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
|
14
14
|
* @param oldSqlSimpleName 原始 SQL 类型
|
|
15
15
|
* @param cfgModel 配置模型
|
|
16
16
|
* @param params 请求参数(会被修改)
|
|
17
|
-
* @param
|
|
17
|
+
* @param visitor 获取当前用户信息的函数(用于软删除时记录删除人)
|
|
18
18
|
*/
|
|
19
|
-
function fixSoftDelete(oldSqlSimpleName, cfgModel, params,
|
|
20
|
-
var _a;
|
|
19
|
+
function fixSoftDelete(oldSqlSimpleName, cfgModel, params, visitor) {
|
|
21
20
|
// 没有开启软删除,不做处理,直接物理删除
|
|
22
21
|
if (cfgModel.enableSoftDelete !== true) {
|
|
23
22
|
return;
|
|
@@ -36,15 +35,13 @@ function fixSoftDelete(oldSqlSimpleName, cfgModel, params, ctx) {
|
|
|
36
35
|
if (!params.condition || Object.keys(params.condition).length === 0) {
|
|
37
36
|
throw new Error('执行删除操作,必须指定删除条件');
|
|
38
37
|
}
|
|
39
|
-
// 获取当前用户信息
|
|
40
|
-
const sessionInfo = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.userSession) === null || _a === void 0 ? void 0 : _a.getSessionInfo();
|
|
41
38
|
// 在原有 data 对象上添加软删除字段
|
|
42
39
|
if (!params.data) {
|
|
43
40
|
params.data = {};
|
|
44
41
|
}
|
|
45
42
|
const dataObj = params.data;
|
|
46
43
|
dataObj.deleted_at = Date.now();
|
|
47
|
-
dataObj.deleted_by = (
|
|
44
|
+
dataObj.deleted_by = (visitor === null || visitor === void 0 ? void 0 : visitor.accountId) || '';
|
|
48
45
|
// 改为执行 UPDATE 操作
|
|
49
46
|
cfgModel.sqlSimpleName = keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE;
|
|
50
47
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 快捷 CRUD 操作模块
|
|
3
|
+
*
|
|
4
|
+
* 在 CrudPro 之上封装便捷方法,提供简洁的 API 进行单表 CRUD 操作。
|
|
5
|
+
* 内部使用工厂函数模式,每次操作都会获取新的 CrudPro 实例,因此**可以安全复用**。
|
|
6
|
+
*
|
|
7
|
+
* **与 CrudPro 的关系:**
|
|
8
|
+
* - CrudPro 是有状态执行器,禁止复用
|
|
9
|
+
* - CrudProQuick 内部每次调用工厂函数获取新 CrudPro,可以安全复用
|
|
10
|
+
*
|
|
11
|
+
* **使用方式:**
|
|
12
|
+
* 必须通过 CurdProService.getQuickCrud() 获取实例,不要直接构造。
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // 通过 CurdProService 获取实例
|
|
16
|
+
* const quick = curdProService.getQuickCrud('mydb', SqlDbType.mysql, 't_user');
|
|
17
|
+
*
|
|
18
|
+
* // 设置公共配置
|
|
19
|
+
* quick.setBaseCfgModel({
|
|
20
|
+
* enableSoftDelete: true,
|
|
21
|
+
* enableStandardUpdateCfg: true,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // 查询列表(新 API)
|
|
25
|
+
* const result = await quick.findList({ condition: { status: 1 } });
|
|
26
|
+
* console.log(result.rows, result.count);
|
|
27
|
+
*
|
|
28
|
+
* // 插入数据(新 API)
|
|
29
|
+
* const insertResult = await quick.insert({ data: { name: '张三', age: 20 } });
|
|
30
|
+
* console.log(insertResult.affectedRows, insertResult.insertId);
|
|
31
|
+
*/
|
|
32
|
+
export { CrudProQuick } from './CrudProQuick';
|
|
33
|
+
export type { ICrudProQuickFactory } from './CrudProQuick';
|
|
34
|
+
export type { IRequestCfgModel2, ICommonStandardColumns } from './models';
|
|
35
|
+
export { fixSoftDelete } from './fixSoftDelete';
|
|
36
|
+
export { CrudWriteResult, CrudQueryOneResult, CrudQueryListResult, CrudQueryPageResult, CrudExistResult, CrudCountResult, CrudUpsertResult, } from '../../libs/crud-pro/models/CrudResult';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 快捷 CRUD 操作模块
|
|
4
|
+
*
|
|
5
|
+
* 在 CrudPro 之上封装便捷方法,提供简洁的 API 进行单表 CRUD 操作。
|
|
6
|
+
* 内部使用工厂函数模式,每次操作都会获取新的 CrudPro 实例,因此**可以安全复用**。
|
|
7
|
+
*
|
|
8
|
+
* **与 CrudPro 的关系:**
|
|
9
|
+
* - CrudPro 是有状态执行器,禁止复用
|
|
10
|
+
* - CrudProQuick 内部每次调用工厂函数获取新 CrudPro,可以安全复用
|
|
11
|
+
*
|
|
12
|
+
* **使用方式:**
|
|
13
|
+
* 必须通过 CurdProService.getQuickCrud() 获取实例,不要直接构造。
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // 通过 CurdProService 获取实例
|
|
17
|
+
* const quick = curdProService.getQuickCrud('mydb', SqlDbType.mysql, 't_user');
|
|
18
|
+
*
|
|
19
|
+
* // 设置公共配置
|
|
20
|
+
* quick.setBaseCfgModel({
|
|
21
|
+
* enableSoftDelete: true,
|
|
22
|
+
* enableStandardUpdateCfg: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // 查询列表(新 API)
|
|
26
|
+
* const result = await quick.findList({ condition: { status: 1 } });
|
|
27
|
+
* console.log(result.rows, result.count);
|
|
28
|
+
*
|
|
29
|
+
* // 插入数据(新 API)
|
|
30
|
+
* const insertResult = await quick.insert({ data: { name: '张三', age: 20 } });
|
|
31
|
+
* console.log(insertResult.affectedRows, insertResult.insertId);
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.CrudUpsertResult = exports.CrudCountResult = exports.CrudExistResult = exports.CrudQueryPageResult = exports.CrudQueryListResult = exports.CrudQueryOneResult = exports.CrudWriteResult = exports.fixSoftDelete = exports.CrudProQuick = void 0;
|
|
35
|
+
// 核心类
|
|
36
|
+
var CrudProQuick_1 = require("./CrudProQuick");
|
|
37
|
+
Object.defineProperty(exports, "CrudProQuick", { enumerable: true, get: function () { return CrudProQuick_1.CrudProQuick; } });
|
|
38
|
+
// 工具函数
|
|
39
|
+
var fixSoftDelete_1 = require("./fixSoftDelete");
|
|
40
|
+
Object.defineProperty(exports, "fixSoftDelete", { enumerable: true, get: function () { return fixSoftDelete_1.fixSoftDelete; } });
|
|
41
|
+
// 重新导出结果类型
|
|
42
|
+
var CrudResult_1 = require("../../libs/crud-pro/models/CrudResult");
|
|
43
|
+
Object.defineProperty(exports, "CrudWriteResult", { enumerable: true, get: function () { return CrudResult_1.CrudWriteResult; } });
|
|
44
|
+
Object.defineProperty(exports, "CrudQueryOneResult", { enumerable: true, get: function () { return CrudResult_1.CrudQueryOneResult; } });
|
|
45
|
+
Object.defineProperty(exports, "CrudQueryListResult", { enumerable: true, get: function () { return CrudResult_1.CrudQueryListResult; } });
|
|
46
|
+
Object.defineProperty(exports, "CrudQueryPageResult", { enumerable: true, get: function () { return CrudResult_1.CrudQueryPageResult; } });
|
|
47
|
+
Object.defineProperty(exports, "CrudExistResult", { enumerable: true, get: function () { return CrudResult_1.CrudExistResult; } });
|
|
48
|
+
Object.defineProperty(exports, "CrudCountResult", { enumerable: true, get: function () { return CrudResult_1.CrudCountResult; } });
|
|
49
|
+
Object.defineProperty(exports, "CrudUpsertResult", { enumerable: true, get: function () { return CrudResult_1.CrudUpsertResult; } });
|