midway-fatcms 0.0.1-beta.4 → 0.0.1-beta.41
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/.eslintrc.json +14 -0
- package/.prettierrc.js +4 -0
- package/README.md +7 -0
- package/dist/config/config.default.js +58 -15
- package/dist/config/seed/aeskey.txt +1 -1
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +33 -9
- package/dist/controller/base/BaseApiController.d.ts +7 -1
- package/dist/controller/base/BaseApiController.js +32 -6
- package/dist/controller/gateway/AsyncTaskController.d.ts +20 -0
- package/dist/controller/gateway/AsyncTaskController.js +181 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
- package/dist/controller/gateway/DocGatewayController.js +14 -9
- package/dist/controller/gateway/FileController.d.ts +3 -2
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.d.ts +0 -1
- package/dist/controller/gateway/StaticController.js +40 -39
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/home.controller.js +4 -3
- package/dist/controller/manage/AnyApiMangeApi.js +2 -2
- package/dist/controller/manage/AppLogMangeApi.js +2 -2
- package/dist/controller/manage/AppMangeApi.js +2 -2
- package/dist/controller/manage/AppPageMangeApi.js +2 -2
- package/dist/controller/manage/AppSchemaHistoryApi.js +2 -2
- package/dist/controller/manage/CrudMethodsMangeApi.js +2 -2
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +86 -83
- package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
- package/dist/controller/manage/DataDictManageApi.js +1 -1
- package/dist/controller/manage/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +38 -34
- package/dist/controller/manage/DocLibManageApi.js +2 -2
- package/dist/controller/manage/DocManageApi.js +2 -2
- package/dist/controller/manage/FileManageApi.js +1 -1
- package/dist/controller/manage/LowCodeTplManageApi.js +2 -2
- package/dist/controller/manage/MenuManageApi.js +2 -2
- package/dist/controller/manage/ProxyApiMangeApi.js +2 -2
- package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
- package/dist/controller/manage/SuperAdminManageApi.js +12 -8
- package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
- package/dist/controller/manage/SysConfigMangeApi.js +8 -6
- package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
- package/dist/controller/manage/SystemInfoManageApi.js +7 -1
- package/dist/controller/manage/UserAccountManageApi.d.ts +2 -2
- package/dist/controller/manage/UserAccountManageApi.js +7 -2
- package/dist/controller/manage/WorkbenchMangeApi.js +3 -3
- package/dist/controller/myinfo/AuthController.d.ts +0 -4
- package/dist/controller/myinfo/AuthController.js +1 -54
- package/dist/controller/render/AppRenderController.js +12 -5
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +5 -5
- package/dist/index.d.ts +35 -4
- package/dist/index.js +35 -4
- package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
- package/dist/libs/crud-pro/CrudPro.js +5 -0
- package/dist/libs/crud-pro/defaultConfigs.js +2 -0
- package/dist/libs/crud-pro/interfaces.d.ts +7 -1
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +12 -5
- package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
- package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
- package/dist/libs/crud-pro/models/ResModel.js +2 -0
- package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/Transaction.d.ts +1 -0
- package/dist/libs/crud-pro/models/Transaction.js +7 -0
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +27 -15
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +17 -19
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.js +15 -3
- package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +32 -7
- package/dist/libs/crud-pro/sql.txt +120 -120
- package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
- package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
- package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +3 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +22 -0
- package/dist/libs/global-config/global-config.d.ts +45 -0
- package/dist/libs/global-config/global-config.js +33 -0
- package/dist/libs/utils/base64.d.ts +9 -0
- package/dist/libs/utils/base64.js +42 -0
- package/dist/libs/utils/errorToString.d.ts +2 -0
- package/dist/libs/utils/errorToString.js +57 -0
- package/dist/libs/utils/fatcms-request.js +2 -2
- package/dist/libs/utils/functions.d.ts +2 -1
- package/dist/libs/utils/functions.js +6 -1
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +30 -10
- package/dist/middleware/permission.middleware.js +1 -1
- package/dist/models/AsyncTaskModel.d.ts +74 -0
- package/dist/models/AsyncTaskModel.js +31 -0
- package/dist/models/RedisKeys.d.ts +14 -0
- package/dist/models/RedisKeys.js +17 -0
- package/dist/models/SystemEntities.d.ts +8 -1
- package/dist/models/SystemEntities.js +7 -0
- package/dist/models/SystemTables.d.ts +1 -3
- package/dist/models/SystemTables.js +2 -4
- package/dist/models/bizmodels.d.ts +28 -0
- package/dist/models/bizmodels.js +6 -1
- package/dist/schedule/anonymousContext.d.ts +14 -0
- package/dist/schedule/anonymousContext.js +59 -0
- package/dist/schedule/index.d.ts +4 -3
- package/dist/schedule/index.js +8 -67
- package/dist/schedule/runSchedule.d.ts +12 -0
- package/dist/schedule/runSchedule.js +68 -0
- package/dist/schedule/scheduleNames.d.ts +13 -0
- package/dist/schedule/scheduleNames.js +17 -0
- package/dist/service/AuthService.js +8 -5
- package/dist/service/EnumInfoService.js +9 -5
- package/dist/service/FileCenterService.js +13 -9
- package/dist/service/SysConfigService.d.ts +1 -1
- package/dist/service/SysConfigService.js +4 -2
- package/dist/service/UserAccountService.js +10 -6
- package/dist/service/UserSessionService.d.ts +21 -0
- package/dist/service/UserSessionService.js +73 -2
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +20 -27
- package/dist/service/WorkbenchService.d.ts +33 -0
- package/dist/service/WorkbenchService.js +70 -12
- package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
- package/dist/service/anyapi/AnyApiService.js +4 -2
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +50 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +287 -0
- package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
- package/dist/service/asyncTask/AsyncTaskService.js +34 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.d.ts +10 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.js +2 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.d.ts +7 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +216 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.d.ts +36 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +139 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.d.ts +46 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +121 -0
- package/dist/service/base/BaseService.d.ts +12 -0
- package/dist/service/base/BaseService.js +22 -0
- package/dist/service/base/RedisCacheService.d.ts +7 -0
- package/dist/service/base/RedisCacheService.js +7 -0
- package/dist/service/crudstd/CrudStdService.d.ts +8 -1
- package/dist/service/crudstd/CrudStdService.js +63 -6
- package/dist/service/curd/CrudProQuick.d.ts +44 -0
- package/dist/service/curd/CrudProQuick.js +147 -0
- package/dist/service/curd/CurdMixByAccountService.d.ts +4 -4
- package/dist/service/curd/CurdMixByAccountService.js +12 -6
- package/dist/service/curd/CurdMixByDictService.d.ts +4 -4
- package/dist/service/curd/CurdMixByDictService.js +10 -7
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +13 -4
- package/dist/service/curd/CurdMixByLinkToCustomService.js +73 -24
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +3 -3
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +3 -3
- package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
- package/dist/service/curd/CurdMixService.d.ts +13 -3
- package/dist/service/curd/CurdMixService.js +26 -2
- package/dist/service/curd/CurdMixUtils.d.ts +27 -4
- package/dist/service/curd/CurdMixUtils.js +115 -41
- package/dist/service/curd/CurdProService.d.ts +3 -10
- package/dist/service/curd/CurdProService.js +36 -148
- package/dist/service/curd/fixCfgModel.d.ts +3 -0
- package/dist/service/curd/fixCfgModel.js +107 -0
- package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
- package/dist/service/proxyapi/ProxyApiService.d.ts +1 -0
- package/dist/service/proxyapi/ProxyApiService.js +43 -9
- package/dist/views/404_app.html +31 -31
- package/dist/views/404_workbench.html +34 -34
- package/package.json +28 -24
- package/tsconfig.json +32 -0
- package/dist/controller/medstatistic/MedAdminController.d.ts +0 -35
- package/dist/controller/medstatistic/MedAdminController.js +0 -205
- package/dist/controller/medstatistic/MedClientController.d.ts +0 -28
- package/dist/controller/medstatistic/MedClientController.js +0 -188
- package/dist/controller/medstatistic/MedMessageService.d.ts +0 -19
- package/dist/controller/medstatistic/MedMessageService.js +0 -95
- package/dist/controller/medstatistic/MedScoreService.d.ts +0 -21
- package/dist/controller/medstatistic/MedScoreService.js +0 -107
- package/dist/controller/medstatistic/constants.d.ts +0 -32
- package/dist/controller/medstatistic/constants.js +0 -43
- package/src/config/config.default.ts +0 -172
- package/src/config/seed/aeskey.txt +0 -1
- package/src/config/utils.ts +0 -23
- package/src/configuration.ts +0 -83
- package/src/controller/base/BaseApiController.ts +0 -145
- package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
- package/src/controller/gateway/CrudMtdGatewayController.ts +0 -107
- package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
- package/src/controller/gateway/DocGatewayController.ts +0 -165
- package/src/controller/gateway/FileController.ts +0 -110
- package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
- package/src/controller/gateway/PublicApiController.ts +0 -145
- package/src/controller/gateway/StaticController.ts +0 -328
- package/src/controller/helpers.controller.ts +0 -161
- package/src/controller/home.controller.ts +0 -71
- package/src/controller/manage/AnyApiMangeApi.ts +0 -66
- package/src/controller/manage/AppLogMangeApi.ts +0 -53
- package/src/controller/manage/AppMangeApi.ts +0 -53
- package/src/controller/manage/AppPageMangeApi.ts +0 -52
- package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
- package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
- package/src/controller/manage/CrudStandardDesignApi.ts +0 -353
- package/src/controller/manage/DataDictManageApi.ts +0 -78
- package/src/controller/manage/DeployManageApi.ts +0 -179
- package/src/controller/manage/DocLibManageApi.ts +0 -69
- package/src/controller/manage/DocManageApi.ts +0 -99
- package/src/controller/manage/FileManageApi.ts +0 -45
- package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
- package/src/controller/manage/MenuManageApi.ts +0 -63
- package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
- package/src/controller/manage/SuperAdminManageApi.ts +0 -138
- package/src/controller/manage/SysConfigMangeApi.ts +0 -95
- package/src/controller/manage/SystemInfoManageApi.ts +0 -48
- package/src/controller/manage/UserAccountManageApi.ts +0 -88
- package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
- package/src/controller/medstatistic/MedAdminController.ts +0 -221
- package/src/controller/medstatistic/MedClientController.ts +0 -188
- package/src/controller/medstatistic/MedMessageService.ts +0 -89
- package/src/controller/medstatistic/MedScoreService.ts +0 -108
- package/src/controller/medstatistic/constants.ts +0 -63
- package/src/controller/myinfo/AuthController.ts +0 -174
- package/src/controller/myinfo/MyInfoController.ts +0 -32
- package/src/controller/render/AppRenderController.ts +0 -76
- package/src/controller/test.controller.ts +0 -37
- package/src/filter/default.filter.ts +0 -13
- package/src/filter/notfound.filter.ts +0 -10
- package/src/index.ts +0 -71
- package/src/interface.ts +0 -31
- package/src/libs/crud-pro/CrudPro.ts +0 -158
- package/src/libs/crud-pro/defaultConfigs.ts +0 -13
- package/src/libs/crud-pro/exceptions.ts +0 -124
- package/src/libs/crud-pro/interfaces.ts +0 -183
- package/src/libs/crud-pro/models/ExecuteContext.ts +0 -111
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -86
- package/src/libs/crud-pro/models/FuncContext.ts +0 -21
- package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
- package/src/libs/crud-pro/models/RequestModel.ts +0 -141
- package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
- package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
- package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
- package/src/libs/crud-pro/models/Transaction.ts +0 -74
- package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
- package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -107
- package/src/libs/crud-pro/models/keys.ts +0 -159
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -75
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -279
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -373
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -202
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -397
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -98
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -59
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
- package/src/libs/crud-pro/sql.txt +0 -120
- package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
- package/src/libs/crud-pro/utils/DatabaseName.ts +0 -40
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
- package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
- package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
- package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
- package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -167
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
- package/src/libs/utils/common-dto.ts +0 -52
- package/src/libs/utils/crypto-utils.ts +0 -52
- package/src/libs/utils/fatcms-request.ts +0 -115
- package/src/libs/utils/functions.ts +0 -67
- package/src/libs/utils/ordernum-utils.ts +0 -18
- package/src/libs/utils/parseConfig.ts +0 -62
- package/src/libs/utils/parseCreateSql.ts +0 -91
- package/src/libs/utils/render-utils.ts +0 -184
- package/src/middleware/forbidden.middleware.ts +0 -71
- package/src/middleware/global.middleware.ts +0 -278
- package/src/middleware/permission.middleware.ts +0 -81
- package/src/middleware/tx.middleware.ts +0 -30
- package/src/models/SystemEntities.ts +0 -115
- package/src/models/SystemPerm.ts +0 -105
- package/src/models/SystemTables.ts +0 -30
- package/src/models/bizmodels.ts +0 -89
- package/src/models/contextLogger.ts +0 -132
- package/src/models/devops.ts +0 -17
- package/src/models/userSession.ts +0 -216
- package/src/schedule/index.ts +0 -73
- package/src/service/AuthService.ts +0 -270
- package/src/service/EnumInfoService.ts +0 -129
- package/src/service/FileCenterService.ts +0 -394
- package/src/service/SysConfigService.ts +0 -34
- package/src/service/UserAccountService.ts +0 -100
- package/src/service/UserSessionService.ts +0 -81
- package/src/service/VisitStatService.ts +0 -179
- package/src/service/WorkbenchService.ts +0 -160
- package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
- package/src/service/anyapi/AnyApiService.ts +0 -184
- package/src/service/base/ApiBaseService.ts +0 -42
- package/src/service/base/ApiRateLimiter.ts +0 -59
- package/src/service/base/BaseService.ts +0 -74
- package/src/service/base/RedisCacheService.ts +0 -38
- package/src/service/crudstd/CrudStdActionService.ts +0 -27
- package/src/service/crudstd/CrudStdConstant.ts +0 -62
- package/src/service/crudstd/CrudStdRelationService.ts +0 -78
- package/src/service/crudstd/CrudStdService.ts +0 -188
- package/src/service/curd/CurdMixByAccountService.ts +0 -83
- package/src/service/curd/CurdMixByDictService.ts +0 -113
- package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -167
- package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
- package/src/service/curd/CurdMixByWorkbenchService.ts +0 -68
- package/src/service/curd/CurdMixService.ts +0 -65
- package/src/service/curd/CurdMixUtils.ts +0 -248
- package/src/service/curd/CurdProService.ts +0 -379
- package/src/service/proxyapi/ProxyApiLoadService.ts +0 -165
- package/src/service/proxyapi/ProxyApiService.ts +0 -262
- package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
- package/src/service/proxyapi/RouteHandler.ts +0 -8
- package/src/service/proxyapi/RouteTrie.ts +0 -74
- package/src/service/proxyapi/WeightedRandom.ts +0 -37
- package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
- package/src/views/404_app.html +0 -31
- package/src/views/404_workbench.html +0 -34
- package/src/views/static/favicon.ico +0 -0
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import * as _ from 'lodash';
|
|
2
|
-
import { ILimitOffset, IOrderByItem, IRequestModel, IVisitor } from '../interfaces';
|
|
3
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
|
-
import { CommonException, Exceptions } from '../exceptions';
|
|
5
|
-
import {DEFAULT_LIMIT} from "../defaultConfigs";
|
|
6
|
-
|
|
7
|
-
class RequestModel {
|
|
8
|
-
visitor: IVisitor;
|
|
9
|
-
|
|
10
|
-
method: string;
|
|
11
|
-
columns?: string[]; // "columns": "id,name,age,sex,addr",
|
|
12
|
-
condition?: Record<string, any>;
|
|
13
|
-
data?: Record<string, any>;
|
|
14
|
-
limit: number;
|
|
15
|
-
offset: number;
|
|
16
|
-
orderBys?: IOrderByItem[];
|
|
17
|
-
|
|
18
|
-
constructor(req: IRequestModel, visitor: IVisitor) {
|
|
19
|
-
Object.assign(this, req);
|
|
20
|
-
this.visitor = visitor;
|
|
21
|
-
this.columns = MixinUtils.parseColumns(req.columns);
|
|
22
|
-
this.orderBys = this.parseOrderBys(req.orderBy);
|
|
23
|
-
const limitOffset = this.parseOffsetList(req);
|
|
24
|
-
this.limit = limitOffset.limit;
|
|
25
|
-
this.offset = limitOffset.offset;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private parseOrderBys(orderByStr: any): IOrderByItem[] {
|
|
29
|
-
if (MixinUtils.isEmpty(orderByStr)) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (Array.isArray(orderByStr)) {
|
|
34
|
-
return orderByStr
|
|
35
|
-
.map(obj => {
|
|
36
|
-
if (typeof obj === 'string') {
|
|
37
|
-
return { fieldName: obj, orderType: 'asc' };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { fieldName, orderType = 'asc' } = obj;
|
|
41
|
-
if (fieldName) {
|
|
42
|
-
return { fieldName, orderType };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
})
|
|
47
|
-
.filter(o => {
|
|
48
|
-
return !!o;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const orderByResult: IOrderByItem[] = [];
|
|
53
|
-
const orderByArray = orderByStr
|
|
54
|
-
.split(',')
|
|
55
|
-
.map(s => {
|
|
56
|
-
return s.trim();
|
|
57
|
-
})
|
|
58
|
-
.filter(s => !!s);
|
|
59
|
-
|
|
60
|
-
if (MixinUtils.isEmpty(orderByArray)) {
|
|
61
|
-
return orderByResult;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < orderByArray.length; i++) {
|
|
65
|
-
const orderByItem = orderByArray[i];
|
|
66
|
-
let orderType = 'asc'; //默认升序
|
|
67
|
-
let fieldName = orderByItem;
|
|
68
|
-
|
|
69
|
-
if (orderByItem.endsWith('+')) {
|
|
70
|
-
// 升序
|
|
71
|
-
fieldName = orderByItem.substring(0, orderByItem.length - 1);
|
|
72
|
-
orderType = 'asc'; //升序
|
|
73
|
-
} else if (orderByItem.endsWith('-')) {
|
|
74
|
-
//降序
|
|
75
|
-
fieldName = orderByItem.substring(0, orderByItem.length - 1);
|
|
76
|
-
orderType = 'desc'; //降序
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
fieldName = fieldName.trim();
|
|
80
|
-
|
|
81
|
-
if (MixinUtils.isEmpty(fieldName) || !MixinUtils.isValidFieldName(fieldName)) {
|
|
82
|
-
throw new CommonException(Exceptions.REQUEST_MODEL_PARSE_ORDER_BY_FAILED, orderByItem);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
orderByResult.push({ fieldName, orderType });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return orderByResult;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private parseOffsetList(req: IRequestModel): ILimitOffset {
|
|
92
|
-
const { limit, offset, pageSize, pageNo } = req;
|
|
93
|
-
|
|
94
|
-
const limitOffset: ILimitOffset = {
|
|
95
|
-
limit: DEFAULT_LIMIT,
|
|
96
|
-
offset: 0,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
if (typeof limit === 'number') {
|
|
100
|
-
limitOffset.limit = limit;
|
|
101
|
-
}
|
|
102
|
-
if (typeof offset === 'number') {
|
|
103
|
-
limitOffset.offset = offset;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof pageNo === 'number' && typeof pageSize === 'number' && pageNo > 0 && pageSize > 0) {
|
|
107
|
-
limitOffset.limit = pageSize;
|
|
108
|
-
limitOffset.offset = (pageNo - 1) * pageSize;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return limitOffset;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* 获取对象数据类型
|
|
116
|
-
* @param attrName
|
|
117
|
-
*/
|
|
118
|
-
getCondOrDataJsonObject(attrName: string): any {
|
|
119
|
-
if (attrName.startsWith('data') || attrName.startsWith('condition')) {
|
|
120
|
-
const jsonObject = _.get(this, attrName);
|
|
121
|
-
if (!jsonObject) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
if (typeof jsonObject !== 'object' && !Array.isArray(jsonObject)) {
|
|
125
|
-
throw new CommonException(Exceptions.RUN_GET_COND_OR_DATA_JSONOBJECT, attrName);
|
|
126
|
-
}
|
|
127
|
-
return jsonObject;
|
|
128
|
-
}
|
|
129
|
-
throw new CommonException(Exceptions.RUN_GET_COND_OR_DATA_JSONOBJECT, attrName);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 获取基本数据类型
|
|
134
|
-
* @param attrName
|
|
135
|
-
*/
|
|
136
|
-
getJsonObjectValue(attrName: string): any {
|
|
137
|
-
return _.get(this, attrName);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { RequestModel };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RequestCfgModel } from './RequestCfgModel';
|
|
2
|
-
import { RequestModel } from './RequestModel';
|
|
3
|
-
import { SqlCfgModel } from './SqlCfgModel';
|
|
4
|
-
import { ExecuteContext } from './ExecuteContext';
|
|
5
|
-
import { IFuncCfgModel, IRequestCfgModel, ITableMeta } from '../interfaces';
|
|
6
|
-
import { FuncContext } from './FuncContext';
|
|
7
|
-
|
|
8
|
-
export interface ICurdProServiceHub {
|
|
9
|
-
getExecuteContext(): ExecuteContext;
|
|
10
|
-
|
|
11
|
-
validateByAllow(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
12
|
-
|
|
13
|
-
validateByReject(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
14
|
-
|
|
15
|
-
validateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
16
|
-
|
|
17
|
-
validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): void;
|
|
18
|
-
|
|
19
|
-
updateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
20
|
-
|
|
21
|
-
getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel>;
|
|
22
|
-
|
|
23
|
-
generateSQLList(exeCtx: ExecuteContext): Promise<void>;
|
|
24
|
-
|
|
25
|
-
executeSqlCfgModels(exeCtx: ExecuteContext): Promise<void>;
|
|
26
|
-
|
|
27
|
-
convertOriginToExecuteSql(sqlCfgModel: SqlCfgModel): Promise<void>;
|
|
28
|
-
|
|
29
|
-
executeFuncCfg(tmpFunCfg: IFuncCfgModel, exeFunCtx: FuncContext): string;
|
|
30
|
-
|
|
31
|
-
getTableMeta(sqlCfgModel: SqlCfgModel): Promise<ITableMeta>;
|
|
32
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ColumnRelation, IFuncCfgModel, ISqlCfgModel } from '../interfaces';
|
|
2
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
3
|
-
import { KeyOfCrudTypes, KeysOfSqlResPicker, SqlDbType} from './keys';
|
|
4
|
-
import { parseJsonObject } from '../../utils/functions';
|
|
5
|
-
|
|
6
|
-
const { isEmpty } = MixinUtils;
|
|
7
|
-
|
|
8
|
-
class SqlCfgModel {
|
|
9
|
-
columns: string[]; // "columns": "id,name,age,sex,addr",
|
|
10
|
-
columnsRelation?: ColumnRelation[]; //只能关联基本信息:如枚举值
|
|
11
|
-
sqlTable: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
12
|
-
sqlSchema?: string; // 可以为空
|
|
13
|
-
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
14
|
-
sqlDdType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
15
|
-
maxLimit: number; // 最大一次性返回的数量
|
|
16
|
-
resName: string;
|
|
17
|
-
resPicker: KeysOfSqlResPicker;
|
|
18
|
-
originSql: string; // 有特殊占位符的SQL, 原始的SQL constructor(resName: string, originSql: string) {}
|
|
19
|
-
validate: IFuncCfgModel; //执行前,进行校验,校验不通过就抛出异常. 校验函数可以返回 boolean或直接抛出异常
|
|
20
|
-
executeWhen: IFuncCfgModel; //满足表达式的结果,才能执行。 默认:true 校验函数必须返回 booleansetResPicker(resPicker: string) {}
|
|
21
|
-
executeSql: string; // 可以运行的SQL
|
|
22
|
-
executeSqlArgs: any[]; //可以运行的SQL的参数setExecuteWhen(executeWhenFunCfg: IFuncCfgModel) {}
|
|
23
|
-
crudType: KeyOfCrudTypes = null;
|
|
24
|
-
|
|
25
|
-
constructor(json: Partial<ISqlCfgModel>) {
|
|
26
|
-
Object.assign(this, json);
|
|
27
|
-
this.columns = MixinUtils.parseColumns(json.columns);
|
|
28
|
-
this.executeWhen = parseJsonObject(json.executeWhen);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public getCrudType(): KeyOfCrudTypes {
|
|
32
|
-
if (!this.crudType) {
|
|
33
|
-
const sql = this.executeSql.trim().toUpperCase();
|
|
34
|
-
if (isEmpty(sql)) {
|
|
35
|
-
this.crudType = KeyOfCrudTypes.EMPTY_SQL;
|
|
36
|
-
} else if (sql.startsWith(KeyOfCrudTypes.SELECT)) {
|
|
37
|
-
this.crudType = KeyOfCrudTypes.SELECT;
|
|
38
|
-
} else if (sql.startsWith(KeyOfCrudTypes.UPDATE)) {
|
|
39
|
-
this.crudType = KeyOfCrudTypes.UPDATE;
|
|
40
|
-
} else if (sql.startsWith(KeyOfCrudTypes.DELETE)) {
|
|
41
|
-
this.crudType = KeyOfCrudTypes.DELETE;
|
|
42
|
-
} else if (sql.startsWith(KeyOfCrudTypes.INSERT)) {
|
|
43
|
-
this.crudType = KeyOfCrudTypes.INSERT;
|
|
44
|
-
} else {
|
|
45
|
-
this.crudType = KeyOfCrudTypes.NOT_CRUD;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this.crudType;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { SqlCfgModel };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {IConnectionPool, IPoolConnectionClient} from '../interfaces';
|
|
2
|
-
import {SqlDbType} from "./keys";
|
|
3
|
-
import {TransactionMySQL} from "./TransactionMySQL";
|
|
4
|
-
import {TransactionPostgres} from "./TransactionPostgres";
|
|
5
|
-
import {TransactionSqlServer} from "./TransactionSqlServer";
|
|
6
|
-
|
|
7
|
-
class Transaction {
|
|
8
|
-
|
|
9
|
-
private transactionMySQL : TransactionMySQL = new TransactionMySQL();
|
|
10
|
-
private transactionPostgres : TransactionPostgres = new TransactionPostgres();
|
|
11
|
-
private transactionSqlServer : TransactionSqlServer = new TransactionSqlServer();
|
|
12
|
-
|
|
13
|
-
private getTxObj(pool: IConnectionPool): TransactionMySQL | TransactionPostgres | TransactionSqlServer {
|
|
14
|
-
if (pool.dbType === SqlDbType.postgres) {
|
|
15
|
-
return this.transactionPostgres;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (pool.dbType === SqlDbType.sqlserver) {
|
|
19
|
-
return this.transactionSqlServer;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!pool.dbType || pool.dbType === SqlDbType.mysql) {
|
|
23
|
-
return this.transactionMySQL;
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 获取链接对象
|
|
30
|
-
* @param pool
|
|
31
|
-
*/
|
|
32
|
-
public async getTxConnection(pool: IConnectionPool): Promise<IPoolConnectionClient> {
|
|
33
|
-
const txObj = this.getTxObj(pool);
|
|
34
|
-
return txObj.getTxConnection(pool);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 开始事务
|
|
39
|
-
*/
|
|
40
|
-
public beginTx() {
|
|
41
|
-
this.transactionMySQL.beginTx();
|
|
42
|
-
this.transactionPostgres.beginTx();
|
|
43
|
-
this.transactionSqlServer.beginTx();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 提交事务
|
|
48
|
-
*/
|
|
49
|
-
public async commitTx() {
|
|
50
|
-
await this.transactionMySQL.commitTx();
|
|
51
|
-
await this.transactionPostgres.commitTx();
|
|
52
|
-
await this.transactionSqlServer.commitTx();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 事务回滚
|
|
57
|
-
*/
|
|
58
|
-
public async rollbackTx() {
|
|
59
|
-
await this.transactionMySQL.rollbackTx();
|
|
60
|
-
await this.transactionPostgres.rollbackTx();
|
|
61
|
-
await this.transactionSqlServer.rollbackTx();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 释放连接
|
|
66
|
-
*/
|
|
67
|
-
public async releaseTx() {
|
|
68
|
-
await this.transactionMySQL.releaseTx();
|
|
69
|
-
await this.transactionPostgres.releaseTx();
|
|
70
|
-
await this.transactionSqlServer.releaseTx();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { Transaction };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { PoolConnection, Pool } from 'mysql2/promise';
|
|
2
|
-
import { IConnectionPool } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
class TransactionMySQL {
|
|
5
|
-
private isBeginTransaction = false;
|
|
6
|
-
private connectionMap: Record<string, PoolConnection> = {};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 获取链接对象
|
|
10
|
-
* @param pool
|
|
11
|
-
*/
|
|
12
|
-
public async getTxConnection(pool: IConnectionPool): Promise<PoolConnection> {
|
|
13
|
-
let connection = this.connectionMap[pool.poolName];
|
|
14
|
-
if (!connection) {
|
|
15
|
-
const poolInstance: Pool = pool.poolInstance as any;
|
|
16
|
-
connection = await poolInstance.getConnection();
|
|
17
|
-
this.connectionMap[pool.poolName] = connection;
|
|
18
|
-
// 开启了事务
|
|
19
|
-
if (this.isBeginTransaction) {
|
|
20
|
-
await connection.beginTransaction();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return connection;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 开始事务
|
|
28
|
-
*/
|
|
29
|
-
public beginTx() {
|
|
30
|
-
this.isBeginTransaction = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 提交事务
|
|
35
|
-
*/
|
|
36
|
-
public async commitTx() {
|
|
37
|
-
if (!this.isBeginTransaction) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const connections = Object.values(this.connectionMap);
|
|
41
|
-
for (let i = 0; i < connections.length; i++) {
|
|
42
|
-
const connection = connections[i];
|
|
43
|
-
await connection.commit();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 事务回滚
|
|
49
|
-
*/
|
|
50
|
-
public async rollbackTx() {
|
|
51
|
-
if (!this.isBeginTransaction) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const connections = Object.values(this.connectionMap);
|
|
55
|
-
for (let i = 0; i < connections.length; i++) {
|
|
56
|
-
const connection = connections[i];
|
|
57
|
-
await connection.rollback();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 释放连接
|
|
63
|
-
*/
|
|
64
|
-
public async releaseTx() {
|
|
65
|
-
// 不管有没有开启事务,都要释放连接。
|
|
66
|
-
const connections = Object.values(this.connectionMap);
|
|
67
|
-
for (let i = 0; i < connections.length; i++) {
|
|
68
|
-
const connection = connections[i];
|
|
69
|
-
try {
|
|
70
|
-
await connection.release();
|
|
71
|
-
} catch (e) {
|
|
72
|
-
console.error(e);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
this.connectionMap = {};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { TransactionMySQL };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { PoolClient, Pool } from 'pg';
|
|
2
|
-
import { IConnectionPool } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
async function beginTransaction(connection: PoolClient) {
|
|
5
|
-
return await connection.query('BEGIN');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async function commit(connection: PoolClient) {
|
|
9
|
-
return await connection.query('COMMIT');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function rollback(connection:PoolClient ) {
|
|
13
|
-
return await connection.query('ROLLBACK');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class TransactionPostgres {
|
|
17
|
-
private isBeginTransaction = false;
|
|
18
|
-
private connectionMap: Record<string, PoolClient> = {};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 获取链接对象
|
|
22
|
-
* @param pool
|
|
23
|
-
*/
|
|
24
|
-
public async getTxConnection(pool: IConnectionPool): Promise<PoolClient> {
|
|
25
|
-
let connection = this.connectionMap[pool.poolName];
|
|
26
|
-
if (!connection) {
|
|
27
|
-
const poolInstance: Pool = pool.poolInstance as any;
|
|
28
|
-
connection = await poolInstance.connect();
|
|
29
|
-
this.connectionMap[pool.poolName] = connection;
|
|
30
|
-
// 开启了事务
|
|
31
|
-
if (this.isBeginTransaction) {
|
|
32
|
-
await beginTransaction(connection);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return connection;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 开始事务
|
|
40
|
-
*/
|
|
41
|
-
public beginTx() {
|
|
42
|
-
this.isBeginTransaction = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 提交事务
|
|
47
|
-
*/
|
|
48
|
-
public async commitTx() {
|
|
49
|
-
if (!this.isBeginTransaction) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const connections = Object.values(this.connectionMap);
|
|
53
|
-
for (let i = 0; i < connections.length; i++) {
|
|
54
|
-
const connection = connections[i];
|
|
55
|
-
await commit(connection);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 事务回滚
|
|
61
|
-
*/
|
|
62
|
-
public async rollbackTx() {
|
|
63
|
-
if (!this.isBeginTransaction) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const connections = Object.values(this.connectionMap);
|
|
67
|
-
for (let i = 0; i < connections.length; i++) {
|
|
68
|
-
const connection = connections[i];
|
|
69
|
-
await rollback(connection);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 释放连接
|
|
75
|
-
*/
|
|
76
|
-
public async releaseTx() {
|
|
77
|
-
// 不管有没有开启事务,都要释放连接。
|
|
78
|
-
const connections = Object.values(this.connectionMap);
|
|
79
|
-
for (let i = 0; i < connections.length; i++) {
|
|
80
|
-
const connection = connections[i];
|
|
81
|
-
try {
|
|
82
|
-
await connection.release();
|
|
83
|
-
} catch (e) {
|
|
84
|
-
console.error(e);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this.connectionMap = {};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { TransactionPostgres };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ConnectionPool, Request, Transaction } from 'mssql';
|
|
2
|
-
import { IConnectionPool, IPoolConnectionClient } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface ISqlServerConnection extends IPoolConnectionClient {
|
|
6
|
-
originConnection: ConnectionPool
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TransactionSqlServer {
|
|
12
|
-
private isBeginTransaction = false;
|
|
13
|
-
private connectionMap: Record<string, ISqlServerConnection> = {};
|
|
14
|
-
private transactionMap: Record<string, Transaction> = {};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 获取链接对象
|
|
18
|
-
* @param pool
|
|
19
|
-
*/
|
|
20
|
-
public async getTxConnection(pool: IConnectionPool): Promise<ISqlServerConnection> {
|
|
21
|
-
let connection = this.connectionMap[pool.poolName];
|
|
22
|
-
if (!connection) {
|
|
23
|
-
connection = await this.connectAndCreateConnection(pool);
|
|
24
|
-
this.connectionMap[pool.poolName] = connection;
|
|
25
|
-
|
|
26
|
-
// 开启了事务
|
|
27
|
-
if (this.isBeginTransaction) {
|
|
28
|
-
await this.beginTransaction(pool.poolName);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return connection;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private async connectAndCreateConnection(pool: IConnectionPool) : Promise<ISqlServerConnection> {
|
|
35
|
-
const poolInstance: ConnectionPool = pool.poolInstance as any;
|
|
36
|
-
const originConnection = await poolInstance.connect();
|
|
37
|
-
return {
|
|
38
|
-
originConnection,
|
|
39
|
-
query: (sql:string, values: any) : Promise<any> =>{
|
|
40
|
-
const request = new Request(originConnection);
|
|
41
|
-
if (Array.isArray(values)) {
|
|
42
|
-
for (let i = 0; i < values.length; i++) {
|
|
43
|
-
const index = i+1;
|
|
44
|
-
const value = values[i];
|
|
45
|
-
request.input(`fatcms_ms${index}`, value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return request.query(sql);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 开始事务
|
|
55
|
-
*/
|
|
56
|
-
public beginTx() {
|
|
57
|
-
this.isBeginTransaction = true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 提交事务
|
|
62
|
-
*/
|
|
63
|
-
public async commitTx() {
|
|
64
|
-
if (!this.isBeginTransaction) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const transactions = Object.values(this.transactionMap);
|
|
68
|
-
for (let i = 0; i < transactions.length; i++) {
|
|
69
|
-
const tmpTx = transactions[i];
|
|
70
|
-
await tmpTx.commit();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 事务回滚
|
|
76
|
-
*/
|
|
77
|
-
public async rollbackTx() {
|
|
78
|
-
if (!this.isBeginTransaction) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const transactions = Object.values(this.transactionMap);
|
|
82
|
-
for (let i = 0; i < transactions.length; i++) {
|
|
83
|
-
const tmpTx = transactions[i];
|
|
84
|
-
await tmpTx.rollback();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 释放连接
|
|
90
|
-
*/
|
|
91
|
-
public async releaseTx() {
|
|
92
|
-
this.connectionMap = {};
|
|
93
|
-
this.transactionMap = {};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
private async beginTransaction(poolName: string) {
|
|
98
|
-
const connection = this.connectionMap[poolName];
|
|
99
|
-
const originConnection: ConnectionPool = connection.originConnection;
|
|
100
|
-
const tmpTx = new Transaction(originConnection);
|
|
101
|
-
this.transactionMap[poolName] = tmpTx;
|
|
102
|
-
return await tmpTx.begin()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export { TransactionSqlServer };
|