@simplysm/sd-cli 10.0.4 → 10.0.21
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.cjs +1 -1
- package/dist/SdLinter.d.ts +5 -0
- package/dist/SdLinter.js.map +1 -0
- package/dist/SdLinter.mjs +37 -0
- package/dist/SdTsIncrementalBuilder.d.ts +16 -0
- package/dist/SdTsIncrementalBuilder.js.map +1 -0
- package/dist/SdTsIncrementalBuilder.mjs +54 -0
- package/dist/build-cluster.js.map +1 -1
- package/dist/build-cluster.mjs +124 -0
- package/dist/builders/SdCliClientBuilder.d.ts +13 -0
- package/dist/builders/SdCliClientBuilder.js.map +1 -0
- package/dist/builders/SdCliClientBuilder.mjs +167 -0
- package/dist/builders/SdCliJsLibLinter.d.ts +3 -7
- package/dist/builders/SdCliJsLibLinter.js.map +1 -1
- package/dist/builders/{SdCliJsLibLinter.js → SdCliJsLibLinter.mjs} +8 -17
- package/dist/builders/SdCliServerBuilder.d.ts +14 -0
- package/dist/builders/SdCliServerBuilder.js.map +1 -0
- package/dist/builders/SdCliServerBuilder.mjs +171 -0
- package/dist/builders/SdCliTsLibBuilder.d.ts +3 -10
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.mjs +75 -0
- package/dist/commons.d.ts +27 -2
- package/dist/entry/SdCliProject.d.ts +1 -0
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/entry/{SdCliProject.js → SdCliProject.mjs} +94 -10
- package/dist/sd-cli.js.map +1 -1
- package/dist/{sd-cli.js → sd-cli.mjs} +1 -0
- package/dist/sd-core-common/src/decorators/NotifyPropertyChange.d.ts +20 -0
- package/dist/sd-core-common/src/decorators/NotifyPropertyChange.js.map +1 -0
- package/dist/sd-core-common/src/decorators/NotifyPropertyChange.mjs +12 -0
- package/dist/sd-core-common/src/decorators/PropertyGetSetDecoratorBase.d.ts +43 -0
- package/dist/sd-core-common/src/decorators/PropertyGetSetDecoratorBase.js.map +1 -0
- package/dist/sd-core-common/src/decorators/PropertyGetSetDecoratorBase.mjs +54 -0
- package/dist/sd-core-common/src/decorators/PropertyValidate.d.ts +16 -0
- package/dist/sd-core-common/src/decorators/PropertyValidate.js.map +1 -0
- package/dist/sd-core-common/src/decorators/PropertyValidate.mjs +26 -0
- package/dist/sd-core-common/src/decorators/decorator-return-types.d.ts +14 -0
- package/dist/sd-core-common/src/decorators/decorator-return-types.js.map +1 -0
- package/dist/sd-core-common/src/decorators/decorator-return-types.mjs +2 -0
- package/dist/sd-core-common/src/errors/ArgumentError.d.ts +10 -0
- package/dist/sd-core-common/src/errors/ArgumentError.js.map +1 -0
- package/dist/sd-core-common/src/errors/ArgumentError.mjs +13 -0
- package/dist/sd-core-common/src/errors/NeverEntryError.d.ts +10 -0
- package/dist/sd-core-common/src/errors/NeverEntryError.js.map +1 -0
- package/dist/sd-core-common/src/errors/NeverEntryError.mjs +13 -0
- package/dist/sd-core-common/src/errors/NotImplementError.d.ts +10 -0
- package/dist/sd-core-common/src/errors/NotImplementError.js.map +1 -0
- package/dist/sd-core-common/src/errors/NotImplementError.mjs +13 -0
- package/dist/sd-core-common/src/errors/SdError.d.ts +23 -0
- package/dist/sd-core-common/src/errors/SdError.js.map +1 -0
- package/dist/sd-core-common/src/errors/SdError.mjs +40 -0
- package/dist/sd-core-common/src/errors/TimeoutError.d.ts +11 -0
- package/dist/sd-core-common/src/errors/TimeoutError.js.map +1 -0
- package/dist/sd-core-common/src/errors/TimeoutError.mjs +16 -0
- package/dist/sd-core-common/src/extensions/ArrayExtension.d.ts +147 -0
- package/dist/sd-core-common/src/extensions/ArrayExtension.js.map +1 -0
- package/dist/sd-core-common/src/extensions/ArrayExtension.mjs +448 -0
- package/dist/sd-core-common/src/extensions/MapExtension.d.ts +4 -0
- package/dist/sd-core-common/src/extensions/MapExtension.js.map +1 -0
- package/dist/sd-core-common/src/extensions/MapExtension.mjs +15 -0
- package/dist/sd-core-common/src/extensions/SetExtension.d.ts +3 -0
- package/dist/sd-core-common/src/extensions/SetExtension.js.map +1 -0
- package/dist/sd-core-common/src/extensions/SetExtension.mjs +10 -0
- package/dist/sd-core-common/src/index.d.ts +32 -0
- package/dist/sd-core-common/src/index.js.map +1 -0
- package/dist/sd-core-common/src/index.mjs +33 -0
- package/dist/sd-core-common/src/types/DateOnly.d.ts +135 -0
- package/dist/sd-core-common/src/types/DateOnly.js.map +1 -0
- package/dist/sd-core-common/src/types/DateOnly.mjs +220 -0
- package/dist/sd-core-common/src/types/DateTime.d.ts +42 -0
- package/dist/sd-core-common/src/types/DateTime.js.map +1 -0
- package/dist/sd-core-common/src/types/DateTime.mjs +156 -0
- package/dist/sd-core-common/src/types/DeepPartial.d.ts +3 -0
- package/dist/sd-core-common/src/types/DeepPartial.js.map +1 -0
- package/dist/sd-core-common/src/types/DeepPartial.mjs +2 -0
- package/dist/sd-core-common/src/types/ObjectSet.d.ts +4 -0
- package/dist/sd-core-common/src/types/ObjectSet.js.map +1 -0
- package/dist/sd-core-common/src/types/ObjectSet.mjs +18 -0
- package/dist/sd-core-common/src/types/Time.d.ts +27 -0
- package/dist/sd-core-common/src/types/Time.js.map +1 -0
- package/dist/sd-core-common/src/types/Time.mjs +108 -0
- package/dist/sd-core-common/src/types/Type.d.ts +7 -0
- package/dist/sd-core-common/src/types/Type.js.map +1 -0
- package/dist/sd-core-common/src/types/Type.mjs +2 -0
- package/dist/sd-core-common/src/types/UnwrappedType.d.ts +1 -0
- package/dist/sd-core-common/src/types/UnwrappedType.js.map +1 -0
- package/dist/sd-core-common/src/types/UnwrappedType.mjs +2 -0
- package/dist/sd-core-common/src/types/Uuid.d.ts +8 -0
- package/dist/sd-core-common/src/types/Uuid.js.map +1 -0
- package/dist/sd-core-common/src/types/Uuid.mjs +26 -0
- package/dist/sd-core-common/src/types/WrappedType.d.ts +1 -0
- package/dist/sd-core-common/src/types/WrappedType.js.map +1 -0
- package/dist/sd-core-common/src/types/WrappedType.mjs +2 -0
- package/dist/sd-core-common/src/utils/DateTimeFormatUtil.d.ts +12 -0
- package/dist/sd-core-common/src/utils/DateTimeFormatUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/DateTimeFormatUtil.mjs +67 -0
- package/dist/sd-core-common/src/utils/FunctionQueue.d.ts +8 -0
- package/dist/sd-core-common/src/utils/FunctionQueue.js.map +1 -0
- package/dist/sd-core-common/src/utils/FunctionQueue.mjs +46 -0
- package/dist/sd-core-common/src/utils/FunctionUtil.d.ts +6 -0
- package/dist/sd-core-common/src/utils/FunctionUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/FunctionUtil.mjs +31 -0
- package/dist/sd-core-common/src/utils/JsonConvert.d.ts +8 -0
- package/dist/sd-core-common/src/utils/JsonConvert.js.map +1 -0
- package/dist/sd-core-common/src/utils/JsonConvert.mjs +78 -0
- package/dist/sd-core-common/src/utils/MathUtil.d.ts +3 -0
- package/dist/sd-core-common/src/utils/MathUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/MathUtil.mjs +6 -0
- package/dist/sd-core-common/src/utils/NumberUtil.d.ts +6 -0
- package/dist/sd-core-common/src/utils/NumberUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/NumberUtil.mjs +32 -0
- package/dist/sd-core-common/src/utils/ObjectUtil.d.ts +80 -0
- package/dist/sd-core-common/src/utils/ObjectUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/ObjectUtil.mjs +452 -0
- package/dist/sd-core-common/src/utils/SdSyncEventEmitter.d.ts +6 -0
- package/dist/sd-core-common/src/utils/SdSyncEventEmitter.js.map +1 -0
- package/dist/sd-core-common/src/utils/SdSyncEventEmitter.mjs +27 -0
- package/dist/sd-core-common/src/utils/StringUtil.d.ts +8 -0
- package/dist/sd-core-common/src/utils/StringUtil.js.map +1 -0
- package/dist/sd-core-common/src/utils/StringUtil.mjs +77 -0
- package/dist/sd-core-common/src/utils/Wait.d.ts +4 -0
- package/dist/sd-core-common/src/utils/Wait.js.map +1 -0
- package/dist/sd-core-common/src/utils/Wait.mjs +23 -0
- package/dist/sd-core-node/src/index.d.ts +6 -0
- package/dist/sd-core-node/src/index.js.map +1 -0
- package/dist/sd-core-node/src/index.mjs +7 -0
- package/dist/sd-core-node/src/utils/FsUtil.d.ts +44 -0
- package/dist/sd-core-node/src/utils/FsUtil.js.map +1 -0
- package/dist/sd-core-node/src/utils/FsUtil.mjs +493 -0
- package/dist/sd-core-node/src/utils/Logger.d.ts +91 -0
- package/dist/sd-core-node/src/utils/Logger.js.map +1 -0
- package/dist/sd-core-node/src/utils/Logger.mjs +185 -0
- package/dist/sd-core-node/src/utils/PathUtil.d.ts +6 -0
- package/dist/sd-core-node/src/utils/PathUtil.js.map +1 -0
- package/dist/sd-core-node/src/utils/PathUtil.mjs +24 -0
- package/dist/sd-core-node/src/utils/SdFsWatcher.d.ts +15 -0
- package/dist/sd-core-node/src/utils/SdFsWatcher.js.map +1 -0
- package/dist/sd-core-node/src/utils/SdFsWatcher.mjs +43 -0
- package/dist/sd-core-node/src/utils/SdProcess.d.ts +5 -0
- package/dist/sd-core-node/src/utils/SdProcess.js.map +1 -0
- package/dist/sd-core-node/src/utils/SdProcess.mjs +36 -0
- package/dist/sd-orm-common/src/CaseQueryHelper.d.ts +12 -0
- package/dist/sd-orm-common/src/CaseQueryHelper.js.map +1 -0
- package/dist/sd-orm-common/src/CaseQueryHelper.mjs +19 -0
- package/dist/sd-orm-common/src/CaseWhenQueryHelper.d.ts +12 -0
- package/dist/sd-orm-common/src/CaseWhenQueryHelper.js.map +1 -0
- package/dist/sd-orm-common/src/CaseWhenQueryHelper.mjs +20 -0
- package/dist/sd-orm-common/src/DbContext.d.ts +81 -0
- package/dist/sd-orm-common/src/DbContext.js.map +1 -0
- package/dist/sd-orm-common/src/DbContext.mjs +635 -0
- package/dist/sd-orm-common/src/IDbConnection.d.ts +15 -0
- package/dist/sd-orm-common/src/IDbConnection.js.map +1 -0
- package/dist/sd-orm-common/src/IDbConnection.mjs +2 -0
- package/dist/sd-orm-common/src/IDbContextExecutor.d.ts +17 -0
- package/dist/sd-orm-common/src/IDbContextExecutor.js.map +1 -0
- package/dist/sd-orm-common/src/IDbContextExecutor.mjs +2 -0
- package/dist/sd-orm-common/src/IDbMigration.d.ts +4 -0
- package/dist/sd-orm-common/src/IDbMigration.js.map +1 -0
- package/dist/sd-orm-common/src/IDbMigration.mjs +2 -0
- package/dist/sd-orm-common/src/QueryBuilder.d.ts +48 -0
- package/dist/sd-orm-common/src/QueryBuilder.js.map +1 -0
- package/dist/sd-orm-common/src/QueryBuilder.mjs +1022 -0
- package/dist/sd-orm-common/src/QueryHelper.d.ts +75 -0
- package/dist/sd-orm-common/src/QueryHelper.js.map +1 -0
- package/dist/sd-orm-common/src/QueryHelper.mjs +627 -0
- package/dist/sd-orm-common/src/QueryUnit.d.ts +10 -0
- package/dist/sd-orm-common/src/QueryUnit.js.map +1 -0
- package/dist/sd-orm-common/src/QueryUnit.mjs +16 -0
- package/dist/sd-orm-common/src/Queryable.d.ts +105 -0
- package/dist/sd-orm-common/src/Queryable.js.map +1 -0
- package/dist/sd-orm-common/src/Queryable.mjs +1375 -0
- package/dist/sd-orm-common/src/SdOrmDataType.d.ts +21 -0
- package/dist/sd-orm-common/src/SdOrmDataType.js.map +1 -0
- package/dist/sd-orm-common/src/SdOrmDataType.mjs +2 -0
- package/dist/sd-orm-common/src/commons.d.ts +400 -0
- package/dist/sd-orm-common/src/commons.js.map +1 -0
- package/dist/sd-orm-common/src/commons.mjs +8 -0
- package/dist/sd-orm-common/src/decorators.d.ts +29 -0
- package/dist/sd-orm-common/src/decorators.js.map +1 -0
- package/dist/sd-orm-common/src/decorators.mjs +89 -0
- package/dist/sd-orm-common/src/index.d.ts +17 -0
- package/dist/sd-orm-common/src/index.js.map +1 -0
- package/dist/sd-orm-common/src/index.mjs +18 -0
- package/dist/sd-orm-common/src/models/SystemMigration.d.ts +3 -0
- package/dist/sd-orm-common/src/models/SystemMigration.js.map +1 -0
- package/dist/sd-orm-common/src/models/SystemMigration.mjs +13 -0
- package/dist/sd-orm-common/src/utils/DbDefinitionUtil.d.ts +14 -0
- package/dist/sd-orm-common/src/utils/DbDefinitionUtil.js.map +1 -0
- package/dist/sd-orm-common/src/utils/DbDefinitionUtil.mjs +66 -0
- package/dist/sd-orm-common/src/utils/SdOrmUtil.d.ts +8 -0
- package/dist/sd-orm-common/src/utils/SdOrmUtil.js.map +1 -0
- package/dist/sd-orm-common/src/utils/SdOrmUtil.mjs +248 -0
- package/dist/sd-orm-node/src/DbConnectionFactory.d.ts +4 -0
- package/dist/sd-orm-node/src/DbConnectionFactory.js.map +1 -0
- package/dist/sd-orm-node/src/DbConnectionFactory.mjs +17 -0
- package/dist/sd-orm-node/src/NodeDbContextExecutor.d.ts +19 -0
- package/dist/sd-orm-node/src/NodeDbContextExecutor.js.map +1 -0
- package/dist/sd-orm-node/src/NodeDbContextExecutor.mjs +71 -0
- package/dist/sd-orm-node/src/SdOrm.d.ts +10 -0
- package/dist/sd-orm-node/src/SdOrm.js.map +1 -0
- package/dist/sd-orm-node/src/SdOrm.mjs +25 -0
- package/dist/sd-orm-node/src/index.d.ts +4 -0
- package/dist/sd-orm-node/src/index.js.map +1 -0
- package/dist/sd-orm-node/src/index.mjs +5 -0
- package/dist/sd-orm-node-mssql/src/MssqlDbConnection.d.ts +25 -0
- package/dist/sd-orm-node-mssql/src/MssqlDbConnection.js.map +1 -0
- package/dist/sd-orm-node-mssql/src/MssqlDbConnection.mjs +321 -0
- package/dist/sd-orm-node-mssql/src/index.d.ts +2 -0
- package/dist/sd-orm-node-mssql/src/index.js.map +1 -0
- package/dist/sd-orm-node-mssql/src/index.mjs +3 -0
- package/dist/sd-orm-node-mysql/src/MysqlDbConnection.d.ts +22 -0
- package/dist/sd-orm-node-mysql/src/MysqlDbConnection.js.map +1 -0
- package/dist/sd-orm-node-mysql/src/MysqlDbConnection.mjs +200 -0
- package/dist/sd-orm-node-mysql/src/index.d.ts +2 -0
- package/dist/sd-orm-node-mysql/src/index.js.map +1 -0
- package/dist/sd-orm-node-mysql/src/index.mjs +3 -0
- package/dist/sd-orm-node-sqlite/src/SqliteDbConnection.d.ts +22 -0
- package/dist/sd-orm-node-sqlite/src/SqliteDbConnection.js.map +1 -0
- package/dist/sd-orm-node-sqlite/src/SqliteDbConnection.mjs +172 -0
- package/dist/sd-orm-node-sqlite/src/index.d.ts +2 -0
- package/dist/sd-orm-node-sqlite/src/index.js.map +1 -0
- package/dist/sd-orm-node-sqlite/src/index.mjs +3 -0
- package/dist/sd-service-common/src/commons-orm.d.ts +4 -0
- package/dist/sd-service-common/src/commons-orm.js.map +1 -0
- package/dist/sd-service-common/src/commons-orm.mjs +2 -0
- package/dist/sd-service-common/src/commons-smtp.d.ts +29 -0
- package/dist/sd-service-common/src/commons-smtp.js.map +1 -0
- package/dist/sd-service-common/src/commons-smtp.mjs +2 -0
- package/dist/sd-service-common/src/commons.d.ts +57 -0
- package/dist/sd-service-common/src/commons.js.map +1 -0
- package/dist/sd-service-common/src/commons.mjs +3 -0
- package/dist/sd-service-common/src/index.d.ts +3 -0
- package/dist/sd-service-common/src/index.js.map +1 -0
- package/dist/sd-service-common/src/index.mjs +4 -0
- package/dist/sd-service-server/src/ApiServiceError.d.ts +12 -0
- package/dist/sd-service-server/src/ApiServiceError.js.map +1 -0
- package/dist/sd-service-server/src/ApiServiceError.mjs +15 -0
- package/dist/sd-service-server/src/SdServiceServer.d.ts +39 -0
- package/dist/sd-service-server/src/SdServiceServer.js.map +1 -0
- package/dist/sd-service-server/src/SdServiceServer.mjs +513 -0
- package/dist/sd-service-server/src/commons.d.ts +23 -0
- package/dist/sd-service-server/src/commons.js.map +1 -0
- package/dist/sd-service-server/src/commons.mjs +3 -0
- package/dist/sd-service-server/src/index.d.ts +8 -0
- package/dist/sd-service-server/src/index.js.map +1 -0
- package/dist/sd-service-server/src/index.mjs +9 -0
- package/dist/sd-service-server/src/services/SdAutoUpdateService.d.ts +4 -0
- package/dist/sd-service-server/src/services/SdAutoUpdateService.js.map +1 -0
- package/dist/sd-service-server/src/services/SdAutoUpdateService.mjs +20 -0
- package/dist/sd-service-server/src/services/SdCryptoService.d.ts +7 -0
- package/dist/sd-service-server/src/services/SdCryptoService.js.map +1 -0
- package/dist/sd-service-server/src/services/SdCryptoService.mjs +39 -0
- package/dist/sd-service-server/src/services/SdOrmService.d.ts +22 -0
- package/dist/sd-service-server/src/services/SdOrmService.js.map +1 -0
- package/dist/sd-service-server/src/services/SdOrmService.mjs +115 -0
- package/dist/sd-service-server/src/services/SdSmtpClientService.d.ts +6 -0
- package/dist/sd-service-server/src/services/SdSmtpClientService.js.map +1 -0
- package/dist/sd-service-server/src/services/SdSmtpClientService.mjs +44 -0
- package/dist/sd-service-server/src/utils/SdServiceServerConfigUtil.d.ts +4 -0
- package/dist/sd-service-server/src/utils/SdServiceServerConfigUtil.js.map +1 -0
- package/dist/sd-service-server/src/utils/SdServiceServerConfigUtil.mjs +36 -0
- package/dist/server-worker.d.ts +1 -0
- package/dist/server-worker.js.map +1 -0
- package/dist/server-worker.mjs +36 -0
- package/package.json +11 -4
- package/src/SdLinter.ts +41 -0
- package/src/SdTsIncrementalBuilder.ts +75 -0
- package/src/build-cluster.ts +69 -18
- package/src/builders/SdCliClientBuilder.ts +189 -0
- package/src/builders/SdCliJsLibLinter.ts +11 -23
- package/src/builders/SdCliServerBuilder.ts +191 -0
- package/src/builders/SdCliTsLibBuilder.ts +33 -202
- package/src/commons.ts +32 -2
- package/src/entry/SdCliProject.ts +133 -17
- package/src/sd-cli.ts +1 -0
- package/src/server-worker.ts +45 -0
- package/tsconfig.json +1 -10
- package/dist/build-cluster.js +0 -75
- package/dist/builders/SdCliTsLibBuilder.js +0 -205
- /package/dist/{commons.js → commons.mjs} +0 -0
- /package/dist/utils/{SdCliBuildResultUtil.js → SdCliBuildResultUtil.mjs} +0 -0
- /package/dist/utils/{SdCliConfigUtil.js → SdCliConfigUtil.mjs} +0 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
import { QueryBuilder } from "./QueryBuilder";
|
|
2
|
+
import { QueryHelper } from "./QueryHelper";
|
|
3
|
+
import { DateTime, NeverEntryError, ObjectUtil, SdError } from "@simplysm/sd-core-common";
|
|
4
|
+
import { Queryable } from "./Queryable";
|
|
5
|
+
import { SystemMigration } from "./models/SystemMigration";
|
|
6
|
+
import { DbDefinitionUtil } from "./utils/DbDefinitionUtil";
|
|
7
|
+
export class DbContext {
|
|
8
|
+
getTableDefinitions() {
|
|
9
|
+
return Object.values(this)
|
|
10
|
+
.ofType(Queryable)
|
|
11
|
+
.map(qr => qr.tableDef)
|
|
12
|
+
.filterExists();
|
|
13
|
+
}
|
|
14
|
+
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
15
|
+
constructor(_executor, opt) {
|
|
16
|
+
this._executor = _executor;
|
|
17
|
+
this.opt = opt;
|
|
18
|
+
// public static readonly SELECT_CACHE_TIMEOUT = 1000;
|
|
19
|
+
// public static readonly selectCache = new Map<string, { result: any[]; timeout: any } | undefined>();
|
|
20
|
+
this.status = "ready";
|
|
21
|
+
this.prepareDefs = [];
|
|
22
|
+
this.qb = new QueryBuilder(this.opt.dialect);
|
|
23
|
+
this.qh = new QueryHelper(this.opt.dialect);
|
|
24
|
+
this.systemMigration = new Queryable(this, SystemMigration);
|
|
25
|
+
}
|
|
26
|
+
async connectWithoutTransactionAsync(callback) {
|
|
27
|
+
if (!this._executor)
|
|
28
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
29
|
+
await this._executor.connectAsync();
|
|
30
|
+
this.status = "connect";
|
|
31
|
+
this.lastConnectionDateTime = new DateTime();
|
|
32
|
+
let result;
|
|
33
|
+
try {
|
|
34
|
+
result = await callback();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
await this._executor.closeAsync();
|
|
38
|
+
this.status = "ready";
|
|
39
|
+
this.lastConnectionDateTime = undefined;
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
await this._executor.closeAsync();
|
|
43
|
+
this.status = "ready";
|
|
44
|
+
this.lastConnectionDateTime = undefined;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
async connectAsync(fn, isolationLevel) {
|
|
48
|
+
if (!this._executor)
|
|
49
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
50
|
+
await this._executor.connectAsync();
|
|
51
|
+
this.status = "connect";
|
|
52
|
+
this.lastConnectionDateTime = new DateTime();
|
|
53
|
+
await this._executor.beginTransactionAsync(isolationLevel);
|
|
54
|
+
this.status = "transact";
|
|
55
|
+
let result;
|
|
56
|
+
try {
|
|
57
|
+
result = await fn();
|
|
58
|
+
await this._executor.commitTransactionAsync();
|
|
59
|
+
this.status = "connect";
|
|
60
|
+
this.lastConnectionDateTime = new DateTime();
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
try {
|
|
64
|
+
await this._executor.rollbackTransactionAsync();
|
|
65
|
+
this.status = "connect";
|
|
66
|
+
this.lastConnectionDateTime = new DateTime();
|
|
67
|
+
}
|
|
68
|
+
catch (err1) {
|
|
69
|
+
if (!(err1 instanceof Error))
|
|
70
|
+
throw new NeverEntryError();
|
|
71
|
+
if (!err1.message.includes("ROLLBACK") || !err1.message.includes("BEGIN")) {
|
|
72
|
+
await this._executor.closeAsync();
|
|
73
|
+
this.status = "ready";
|
|
74
|
+
this.lastConnectionDateTime = undefined;
|
|
75
|
+
throw err1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
await this._executor.closeAsync();
|
|
79
|
+
this.status = "ready";
|
|
80
|
+
this.lastConnectionDateTime = undefined;
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
await this._executor.closeAsync();
|
|
84
|
+
this.status = "ready";
|
|
85
|
+
this.lastConnectionDateTime = undefined;
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
async transAsync(fn, isolationLevel) {
|
|
89
|
+
if (!this._executor)
|
|
90
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
91
|
+
if (this.status === "transact") {
|
|
92
|
+
throw new Error("이미 TRANSACTION 상태 입니다.");
|
|
93
|
+
}
|
|
94
|
+
await this._executor.beginTransactionAsync(isolationLevel);
|
|
95
|
+
this.status = "transact";
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
result = await fn();
|
|
99
|
+
await this._executor.commitTransactionAsync();
|
|
100
|
+
this.status = "connect";
|
|
101
|
+
this.lastConnectionDateTime = new DateTime();
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
try {
|
|
105
|
+
await this._executor.rollbackTransactionAsync();
|
|
106
|
+
this.status = "connect";
|
|
107
|
+
this.lastConnectionDateTime = new DateTime();
|
|
108
|
+
}
|
|
109
|
+
catch (err1) {
|
|
110
|
+
if (!(err1 instanceof Error))
|
|
111
|
+
throw new NeverEntryError();
|
|
112
|
+
if (!err1.message.includes("ROLLBACK") || !err1.message.includes("BEGIN")) {
|
|
113
|
+
await this._executor.closeAsync();
|
|
114
|
+
this.status = "ready";
|
|
115
|
+
this.lastConnectionDateTime = undefined;
|
|
116
|
+
throw err1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
await this._executor.closeAsync();
|
|
120
|
+
this.status = "ready";
|
|
121
|
+
this.lastConnectionDateTime = undefined;
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
async executeDefsAsync(defs, options) {
|
|
127
|
+
if (!this._executor)
|
|
128
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
129
|
+
return await this._executor.executeDefsAsync(defs, options);
|
|
130
|
+
}
|
|
131
|
+
async executeQueriesAsync(queries) {
|
|
132
|
+
if (!this._executor)
|
|
133
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
134
|
+
return await this._executor.executeAsync(queries);
|
|
135
|
+
}
|
|
136
|
+
async bulkInsertAsync(tableName, columnDefs, records) {
|
|
137
|
+
if (!this._executor)
|
|
138
|
+
throw new Error("DB 실행기를 알 수 없습니다.");
|
|
139
|
+
await this._executor.bulkInsertAsync(tableName, columnDefs, records);
|
|
140
|
+
}
|
|
141
|
+
async executePreparedAsync() {
|
|
142
|
+
if (this.prepareDefs.length < 1)
|
|
143
|
+
return;
|
|
144
|
+
await this.executeDefsAsync(this.prepareDefs);
|
|
145
|
+
this.prepareDefs = [];
|
|
146
|
+
// DbContext.selectCache.clear();
|
|
147
|
+
}
|
|
148
|
+
async getIsDbExistsAsync(database) {
|
|
149
|
+
if (this.opt.dialect !== "sqlite") {
|
|
150
|
+
if (database === undefined)
|
|
151
|
+
throw new NeverEntryError();
|
|
152
|
+
return (await this.executeDefsAsync([
|
|
153
|
+
{
|
|
154
|
+
type: "getDatabaseInfo",
|
|
155
|
+
database
|
|
156
|
+
}
|
|
157
|
+
]))[0].length > 0;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
throw new Error("sqlite 미구현");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async getIsTableExistsAsync(tableNameDef) {
|
|
164
|
+
return (await this.executeDefsAsync([
|
|
165
|
+
{
|
|
166
|
+
type: "getTableInfo",
|
|
167
|
+
table: tableNameDef
|
|
168
|
+
}
|
|
169
|
+
]))[0].length > 0;
|
|
170
|
+
}
|
|
171
|
+
get tableDefs() {
|
|
172
|
+
return Object.keys(this)
|
|
173
|
+
.filter((key) => !key.startsWith("_"))
|
|
174
|
+
.map((key) => this[key])
|
|
175
|
+
.ofType(Queryable)
|
|
176
|
+
.map((qr) => DbDefinitionUtil.getTableDef(qr.tableType))
|
|
177
|
+
.filterExists();
|
|
178
|
+
}
|
|
179
|
+
async getTableInfosAsync(database, schema) {
|
|
180
|
+
return (await this.executeDefsAsync([{
|
|
181
|
+
type: "getTableInfos",
|
|
182
|
+
database,
|
|
183
|
+
schema
|
|
184
|
+
}]))[0].map((item) => ({
|
|
185
|
+
schema: item.TABLE_SCHEMA,
|
|
186
|
+
name: item.TABLE_NAME
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
async getTableColumnInfosAsync(database, schema, table) {
|
|
190
|
+
return (await this.executeDefsAsync([
|
|
191
|
+
{
|
|
192
|
+
type: "getTableColumnInfos",
|
|
193
|
+
table: { database, schema, name: table }
|
|
194
|
+
}
|
|
195
|
+
]))[0].map((item) => ({
|
|
196
|
+
name: item.name,
|
|
197
|
+
dataType: item.dataType,
|
|
198
|
+
length: item.length,
|
|
199
|
+
precision: item.precision,
|
|
200
|
+
digits: item.digits,
|
|
201
|
+
nullable: item.nullable,
|
|
202
|
+
autoIncrement: item.autoIncrement
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
async getTablePkColumnNamesAsync(database, schema, table) {
|
|
206
|
+
return (await this.executeDefsAsync([
|
|
207
|
+
{
|
|
208
|
+
type: "getTablePrimaryKeys",
|
|
209
|
+
table: { database, schema, name: table }
|
|
210
|
+
}
|
|
211
|
+
]))[0].map((item) => item.name);
|
|
212
|
+
}
|
|
213
|
+
async getTableFksAsync(database, schema, table) {
|
|
214
|
+
return (await this.executeDefsAsync([
|
|
215
|
+
{
|
|
216
|
+
type: "getTableForeignKeys",
|
|
217
|
+
table: { database, schema, name: table }
|
|
218
|
+
}
|
|
219
|
+
]))[0]
|
|
220
|
+
.groupBy((item) => item.name)
|
|
221
|
+
.map((item) => ({
|
|
222
|
+
name: item.key,
|
|
223
|
+
sourceColumnNames: item.values.map((item1) => item1.sourceColumnName),
|
|
224
|
+
targetSchemaName: item.values[0].targetSchemaName,
|
|
225
|
+
targetTableName: item.values[0].targetTableName
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
async getTableIndexesAsync(database, schema, table) {
|
|
229
|
+
return (await this.executeDefsAsync([
|
|
230
|
+
{
|
|
231
|
+
type: "getTableIndexes",
|
|
232
|
+
table: { database, schema, name: table }
|
|
233
|
+
}
|
|
234
|
+
]))[0]
|
|
235
|
+
.groupBy((item) => item.name)
|
|
236
|
+
.map((item) => ({
|
|
237
|
+
name: item.key,
|
|
238
|
+
columns: item.values.map((item1) => ({
|
|
239
|
+
name: item1.columnName,
|
|
240
|
+
orderBy: item1.isDesc === true ? "DESC" : "ASC"
|
|
241
|
+
}))
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
async truncateTable(table) {
|
|
245
|
+
await this.executeDefsAsync([{
|
|
246
|
+
type: "truncateTable",
|
|
247
|
+
table: {
|
|
248
|
+
...this.opt.dialect === "sqlite" ? {} : {
|
|
249
|
+
database: this.opt.database,
|
|
250
|
+
schema: this.opt.schema,
|
|
251
|
+
},
|
|
252
|
+
name: table
|
|
253
|
+
}
|
|
254
|
+
}]);
|
|
255
|
+
}
|
|
256
|
+
async initializeAsync(dbs, force) {
|
|
257
|
+
if (force && this.status === "transact") {
|
|
258
|
+
throw new Error("DB 강제 초기화는 트랜젝션 상에서는 동작하지 못합니다.\nconnect 대신에 connectWithoutTransaction 로 연결하여 시도하세요.");
|
|
259
|
+
}
|
|
260
|
+
if (force && this.opt.dialect === "sqlite") {
|
|
261
|
+
throw new Error("sqlite 강제초기화 불가, 강제로 초기화 하려면, 데이터베이스 파일을 삭제하고 초기화를 수행하세요.");
|
|
262
|
+
}
|
|
263
|
+
// 강제 아닐때
|
|
264
|
+
if (!force) {
|
|
265
|
+
const isDbExists = this.opt.dialect === "sqlite" ? true : await this.getIsDbExistsAsync(this.opt.database);
|
|
266
|
+
const isMigrationTableExists = !isDbExists ? false : await this.getIsTableExistsAsync({
|
|
267
|
+
...this.opt.dialect === "sqlite" ? {} : {
|
|
268
|
+
database: this.opt.database,
|
|
269
|
+
schema: this.opt.schema,
|
|
270
|
+
},
|
|
271
|
+
name: "_migration"
|
|
272
|
+
});
|
|
273
|
+
// DB / Migration TABLE 있을때
|
|
274
|
+
if (isDbExists && isMigrationTableExists) {
|
|
275
|
+
const dbMigrationCodes = (await this.systemMigration
|
|
276
|
+
.select((item) => ({
|
|
277
|
+
code: item.code
|
|
278
|
+
}))
|
|
279
|
+
.resultAsync()).map((item) => item.code);
|
|
280
|
+
const migrations = this.migrations
|
|
281
|
+
.filter((item) => !dbMigrationCodes.includes(item.name))
|
|
282
|
+
.orderBy((item) => item.name);
|
|
283
|
+
// 마이그레이션 있을때
|
|
284
|
+
if (migrations.length > 0) {
|
|
285
|
+
if (this.status !== "transact") {
|
|
286
|
+
await this.transAsync(async () => {
|
|
287
|
+
for (const migration of migrations) {
|
|
288
|
+
await new migration().up(this);
|
|
289
|
+
await this.systemMigration.insertAsync([{
|
|
290
|
+
code: migration.name
|
|
291
|
+
}]);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
for (const migration of migrations) {
|
|
297
|
+
await new migration().up(this);
|
|
298
|
+
await this.systemMigration.insertAsync([{
|
|
299
|
+
code: migration.name
|
|
300
|
+
}]);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// 강제 혹은 첫 수행
|
|
311
|
+
let tableDefs;
|
|
312
|
+
if (this.opt.dialect !== "sqlite") {
|
|
313
|
+
const dbNames = dbs ?? (this.opt.database !== undefined ? [this.opt.database] : []);
|
|
314
|
+
if (dbNames.length < 1) {
|
|
315
|
+
throw new Error("생성할 데이터베이스가 없습니다.");
|
|
316
|
+
}
|
|
317
|
+
// DB 초기화
|
|
318
|
+
for (const dbName of dbNames) {
|
|
319
|
+
await this.executeDefsAsync([{
|
|
320
|
+
type: "createDatabaseIfNotExists",
|
|
321
|
+
database: dbName
|
|
322
|
+
}]);
|
|
323
|
+
await this.executeQueriesAsync([`USE ${dbName};`]);
|
|
324
|
+
await this.executeDefsAsync([{
|
|
325
|
+
type: "clearDatabaseIfExists",
|
|
326
|
+
database: dbName
|
|
327
|
+
}]);
|
|
328
|
+
}
|
|
329
|
+
await this.executeQueriesAsync([`USE ${this.opt.database};`]);
|
|
330
|
+
// TABLE 초기화: 생성/PK 설정
|
|
331
|
+
tableDefs = this.tableDefs
|
|
332
|
+
.filter((item) => item.database === undefined || dbNames.includes(item.database))
|
|
333
|
+
.filterExists();
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
tableDefs = this.tableDefs.filterExists();
|
|
337
|
+
}
|
|
338
|
+
const queryDefsList = [];
|
|
339
|
+
queryDefsList.push(...this.getCreateTablesFullQueryDefsFromTableDef(tableDefs));
|
|
340
|
+
// Migration 데이터 저장 등록
|
|
341
|
+
const migrationInsertQueryDefs = [];
|
|
342
|
+
for (const migration of this.migrations.orderBy((item) => item.name)) {
|
|
343
|
+
migrationInsertQueryDefs.push({
|
|
344
|
+
type: "insert",
|
|
345
|
+
from: this.qb.getTableName({
|
|
346
|
+
...this.opt.dialect === "sqlite" ? {} : {
|
|
347
|
+
database: this.opt.database,
|
|
348
|
+
schema: this.opt.schema
|
|
349
|
+
},
|
|
350
|
+
name: "_migration"
|
|
351
|
+
}),
|
|
352
|
+
record: {
|
|
353
|
+
[this.qb.wrap("code")]: `N'${migration.name}'`
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
queryDefsList.push(migrationInsertQueryDefs);
|
|
358
|
+
for (const queryDefs of queryDefsList) {
|
|
359
|
+
await this.executeDefsAsync(queryDefs);
|
|
360
|
+
}
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
getCreateTablesFullQueryDefsFromTableDef(tableDefs) {
|
|
364
|
+
const result = [];
|
|
365
|
+
const createTableQueryDefs = [];
|
|
366
|
+
for (const tableDef of tableDefs) {
|
|
367
|
+
createTableQueryDefs.push(this.getCreateTableQueryDefFromTableDef(tableDef));
|
|
368
|
+
}
|
|
369
|
+
result.push(createTableQueryDefs);
|
|
370
|
+
// TABLE 초기화: FK 설정
|
|
371
|
+
const addFkQueryDefs = [];
|
|
372
|
+
for (const tableDef of tableDefs) {
|
|
373
|
+
addFkQueryDefs.push(...this.getCreateFksQueryDefsFromTableDef(tableDef));
|
|
374
|
+
}
|
|
375
|
+
result.push(addFkQueryDefs);
|
|
376
|
+
// TABLE 초기화: INDEX 설정
|
|
377
|
+
const createIndexQueryDefs = [];
|
|
378
|
+
for (const tableDef of tableDefs) {
|
|
379
|
+
createIndexQueryDefs.push(...this.getCreateIndexesQueryDefsFromTableDef(tableDef));
|
|
380
|
+
}
|
|
381
|
+
result.push(createIndexQueryDefs);
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
getCreateTableQueryDefFromTableDef(tableDef) {
|
|
385
|
+
if (tableDef.columns.length < 1) {
|
|
386
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
387
|
+
}
|
|
388
|
+
if (!tableDef.view) {
|
|
389
|
+
return {
|
|
390
|
+
type: "createTable",
|
|
391
|
+
table: this.getTableNameDef(tableDef),
|
|
392
|
+
columns: tableDef.columns.map((col) => ObjectUtil.clearUndefined({
|
|
393
|
+
name: col.name,
|
|
394
|
+
dataType: this.qh.type(col.dataType ?? col.typeFwd()),
|
|
395
|
+
autoIncrement: col.autoIncrement,
|
|
396
|
+
nullable: col.nullable
|
|
397
|
+
})),
|
|
398
|
+
primaryKeys: tableDef.columns
|
|
399
|
+
.filter((item) => item.primaryKey !== undefined)
|
|
400
|
+
.orderBy((item) => item.primaryKey)
|
|
401
|
+
.map((item) => ({
|
|
402
|
+
columnName: item.name,
|
|
403
|
+
orderBy: "ASC"
|
|
404
|
+
}))
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
return {
|
|
409
|
+
type: "createView",
|
|
410
|
+
table: this.getTableNameDef(tableDef),
|
|
411
|
+
queryDef: tableDef.view(this).getSelectQueryDef()
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
getCreateFksQueryDefsFromTableDef(tableDef) {
|
|
416
|
+
if (tableDef.columns.length < 1) {
|
|
417
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
418
|
+
}
|
|
419
|
+
const addFkQueryDefs = [];
|
|
420
|
+
for (const fkDef of tableDef.foreignKeys) {
|
|
421
|
+
try {
|
|
422
|
+
const targetTableDef = DbDefinitionUtil.getTableDef(fkDef.targetTypeFwd());
|
|
423
|
+
if (targetTableDef.columns.length < 1) {
|
|
424
|
+
throw new Error(`${targetTableDef.name}의 컬럼 설정이 잘못되었습니다.`);
|
|
425
|
+
}
|
|
426
|
+
const targetPkNames = targetTableDef.columns
|
|
427
|
+
.filter((item) => item.primaryKey !== undefined)
|
|
428
|
+
.orderBy((item) => item.primaryKey)
|
|
429
|
+
.map((item) => item.name);
|
|
430
|
+
addFkQueryDefs.push(...[
|
|
431
|
+
{
|
|
432
|
+
type: "addForeignKey",
|
|
433
|
+
table: this.getTableNameDef(tableDef),
|
|
434
|
+
foreignKey: {
|
|
435
|
+
name: fkDef.name,
|
|
436
|
+
fkColumns: fkDef.columnPropertyKeys.map((propKey) => tableDef.columns.single((col) => col.propertyKey === propKey).name),
|
|
437
|
+
targetTable: this.getTableNameDef(targetTableDef),
|
|
438
|
+
targetPkColumns: targetPkNames
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: "createIndex",
|
|
443
|
+
table: this.getTableNameDef(tableDef),
|
|
444
|
+
index: {
|
|
445
|
+
name: fkDef.name,
|
|
446
|
+
columns: fkDef.columnPropertyKeys.map((item) => ({
|
|
447
|
+
name: tableDef.columns.single((col) => col.propertyKey === item).name,
|
|
448
|
+
orderBy: "ASC",
|
|
449
|
+
unique: false
|
|
450
|
+
}))
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
]);
|
|
454
|
+
}
|
|
455
|
+
catch (err) {
|
|
456
|
+
if (err instanceof Error) {
|
|
457
|
+
throw new SdError(err, tableDef.name + " > " + fkDef.name + ": 오류");
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
throw err;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return addFkQueryDefs;
|
|
465
|
+
}
|
|
466
|
+
getCreateIndexesQueryDefsFromTableDef(tableDef) {
|
|
467
|
+
if (tableDef.columns.length < 1) {
|
|
468
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
469
|
+
}
|
|
470
|
+
const createIndexQueryDefs = [];
|
|
471
|
+
for (const indexDef of tableDef.indexes) {
|
|
472
|
+
createIndexQueryDefs.push({
|
|
473
|
+
type: "createIndex",
|
|
474
|
+
table: this.getTableNameDef(tableDef),
|
|
475
|
+
index: {
|
|
476
|
+
name: indexDef.name,
|
|
477
|
+
columns: indexDef.columns.orderBy((item) => item.order).map((item) => ({
|
|
478
|
+
name: tableDef.columns.single((col) => col.propertyKey === item.columnPropertyKey).name,
|
|
479
|
+
orderBy: item.orderBy,
|
|
480
|
+
unique: item.unique
|
|
481
|
+
}))
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
return createIndexQueryDefs;
|
|
486
|
+
}
|
|
487
|
+
getAddColumnQueryDefFromTableDef(tableDef, columnName) {
|
|
488
|
+
if (tableDef.columns.length < 1) {
|
|
489
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
490
|
+
}
|
|
491
|
+
const columnDef = tableDef.columns.single((col) => col.name === columnName);
|
|
492
|
+
if (!columnDef) {
|
|
493
|
+
throw new Error(`'${tableDef.name}.${columnName}' 설정이 잘못되었습니다.`);
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
type: "addColumn",
|
|
497
|
+
table: this.getTableNameDef(tableDef),
|
|
498
|
+
column: {
|
|
499
|
+
name: columnDef.name,
|
|
500
|
+
dataType: this.qh.type(columnDef.dataType ?? columnDef.typeFwd()),
|
|
501
|
+
autoIncrement: columnDef.autoIncrement,
|
|
502
|
+
nullable: columnDef.nullable
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
getModifyColumnQueryDefFromTableDef(tableDef, columnName) {
|
|
507
|
+
if (tableDef.columns.length < 1) {
|
|
508
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
509
|
+
}
|
|
510
|
+
const columnDef = tableDef.columns.single((col) => col.name === columnName);
|
|
511
|
+
if (!columnDef) {
|
|
512
|
+
throw new Error(`'${tableDef.name}.${columnName}' 설정이 잘못되었습니다.`);
|
|
513
|
+
}
|
|
514
|
+
return {
|
|
515
|
+
type: "modifyColumn",
|
|
516
|
+
table: this.getTableNameDef(tableDef),
|
|
517
|
+
column: {
|
|
518
|
+
name: columnDef.name,
|
|
519
|
+
dataType: this.qh.type(columnDef.dataType ?? columnDef.typeFwd()),
|
|
520
|
+
autoIncrement: columnDef.autoIncrement,
|
|
521
|
+
nullable: columnDef.nullable
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
getModifyPkQueryDefFromTableDef(tableDef, columnNames) {
|
|
526
|
+
if (tableDef.columns.length < 1) {
|
|
527
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
528
|
+
}
|
|
529
|
+
return [
|
|
530
|
+
{
|
|
531
|
+
type: "dropPrimaryKey",
|
|
532
|
+
table: this.getTableNameDef(tableDef)
|
|
533
|
+
},
|
|
534
|
+
...(columnNames.length > 0) ? [
|
|
535
|
+
{
|
|
536
|
+
type: "addPrimaryKey",
|
|
537
|
+
table: this.getTableNameDef(tableDef),
|
|
538
|
+
columns: columnNames
|
|
539
|
+
}
|
|
540
|
+
] : []
|
|
541
|
+
];
|
|
542
|
+
}
|
|
543
|
+
getAddFkQueryDefFromTableDef(tableDef, fkName) {
|
|
544
|
+
if (tableDef.columns.length < 1) {
|
|
545
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
546
|
+
}
|
|
547
|
+
const fkDef = tableDef.foreignKeys.single((col) => col.name === fkName);
|
|
548
|
+
if (!fkDef) {
|
|
549
|
+
throw new Error(`'${tableDef.name} => FK: ${fkName}' 설정이 잘못되었습니다.`);
|
|
550
|
+
}
|
|
551
|
+
const targetTableDef = DbDefinitionUtil.getTableDef(fkDef.targetTypeFwd());
|
|
552
|
+
if (targetTableDef.columns.length < 1) {
|
|
553
|
+
throw new Error(`${targetTableDef.name}의 컬럼 설정이 잘못되었습니다.`);
|
|
554
|
+
}
|
|
555
|
+
const targetPkNames = targetTableDef.columns
|
|
556
|
+
.filter((item) => item.primaryKey !== undefined)
|
|
557
|
+
.orderBy((item) => item.primaryKey)
|
|
558
|
+
.map((item) => item.name);
|
|
559
|
+
return {
|
|
560
|
+
type: "addForeignKey",
|
|
561
|
+
table: this.getTableNameDef(tableDef),
|
|
562
|
+
foreignKey: {
|
|
563
|
+
name: fkDef.name,
|
|
564
|
+
fkColumns: fkDef.columnPropertyKeys.map((propKey) => tableDef.columns.single((col) => col.propertyKey === propKey).name),
|
|
565
|
+
targetTable: this.getTableNameDef(targetTableDef),
|
|
566
|
+
targetPkColumns: targetPkNames
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
getRemoveFkQueryDefFromTableDef(tableDef, fkName) {
|
|
571
|
+
if (tableDef.columns.length < 1) {
|
|
572
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
type: "removeForeignKey",
|
|
576
|
+
table: this.getTableNameDef(tableDef),
|
|
577
|
+
foreignKey: fkName
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
getCreateIndexQueryDefFromTableDef(tableDef, indexName) {
|
|
581
|
+
if (tableDef.columns.length < 1) {
|
|
582
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
583
|
+
}
|
|
584
|
+
let indexDef = tableDef.indexes.single((item) => item.name === indexName);
|
|
585
|
+
if (!indexDef) {
|
|
586
|
+
const fkDef = tableDef.foreignKeys.single((item) => item.name === indexName);
|
|
587
|
+
if (!fkDef) {
|
|
588
|
+
throw new Error(`'${tableDef.name} => IDX: ${indexName}' 설정이 잘못되었습니다.`);
|
|
589
|
+
}
|
|
590
|
+
indexDef = {
|
|
591
|
+
name: fkDef.name,
|
|
592
|
+
description: fkDef.description,
|
|
593
|
+
columns: fkDef.columnPropertyKeys.map((propKey, i) => ({
|
|
594
|
+
columnPropertyKey: propKey,
|
|
595
|
+
name: tableDef.columns.single((col) => col.propertyKey === propKey).name,
|
|
596
|
+
order: i + 1,
|
|
597
|
+
orderBy: "ASC",
|
|
598
|
+
unique: false
|
|
599
|
+
}))
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
type: "createIndex",
|
|
604
|
+
table: this.getTableNameDef(tableDef),
|
|
605
|
+
index: {
|
|
606
|
+
name: indexDef.name,
|
|
607
|
+
columns: indexDef.columns.orderBy((item) => item.order).map((item) => ({
|
|
608
|
+
name: tableDef.columns.single((col) => col.propertyKey === item.columnPropertyKey).name,
|
|
609
|
+
orderBy: item.orderBy,
|
|
610
|
+
unique: item.unique
|
|
611
|
+
}))
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
getDropIndexQueryDefFromTableDef(tableDef, indexName) {
|
|
616
|
+
if (tableDef.columns.length < 1) {
|
|
617
|
+
throw new Error(`'${tableDef.name}'의 컬럼 설정이 잘못되었습니다.`);
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
type: "dropIndex",
|
|
621
|
+
table: this.getTableNameDef(tableDef),
|
|
622
|
+
index: indexName
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
getTableNameDef(tableDef) {
|
|
626
|
+
return {
|
|
627
|
+
...this.opt.dialect === "sqlite" ? {} : {
|
|
628
|
+
database: tableDef.database ?? this.opt.database,
|
|
629
|
+
schema: tableDef.schema ?? this.opt.schema
|
|
630
|
+
},
|
|
631
|
+
name: tableDef.name
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
//# sourceMappingURL=DbContext.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { IQueryColumnDef, ISOLATION_LEVEL, TDbConnectionConfig } from "./commons";
|
|
4
|
+
export interface IDbConnection extends EventEmitter {
|
|
5
|
+
config: TDbConnectionConfig;
|
|
6
|
+
isConnected: boolean;
|
|
7
|
+
isOnTransaction: boolean;
|
|
8
|
+
connectAsync(): Promise<void>;
|
|
9
|
+
closeAsync(): Promise<void>;
|
|
10
|
+
beginTransactionAsync(isolationLevel?: ISOLATION_LEVEL): Promise<void>;
|
|
11
|
+
commitTransactionAsync(): Promise<void>;
|
|
12
|
+
rollbackTransactionAsync(): Promise<void>;
|
|
13
|
+
executeAsync(queries: string[]): Promise<any[][]>;
|
|
14
|
+
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDbConnection.js","sourceRoot":"","sources":["../../../../sd-orm-common/src/IDbConnection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IQueryColumnDef, IQueryResultParseOption, ISOLATION_LEVEL, TQueryDef } from "./commons";
|
|
2
|
+
import { TDbContextOption } from "./DbContext";
|
|
3
|
+
export interface IDbContextExecutor {
|
|
4
|
+
getInfoAsync(): Promise<{
|
|
5
|
+
dialect: TDbContextOption["dialect"];
|
|
6
|
+
database?: string;
|
|
7
|
+
schema?: string;
|
|
8
|
+
}>;
|
|
9
|
+
connectAsync(): Promise<void>;
|
|
10
|
+
beginTransactionAsync(isolationLevel?: ISOLATION_LEVEL): Promise<void>;
|
|
11
|
+
commitTransactionAsync(): Promise<void>;
|
|
12
|
+
rollbackTransactionAsync(): Promise<void>;
|
|
13
|
+
executeDefsAsync(defs: TQueryDef[], options?: (IQueryResultParseOption | undefined)[]): Promise<any[][]>;
|
|
14
|
+
executeAsync(queries: string[]): Promise<any[][]>;
|
|
15
|
+
bulkInsertAsync(tableName: string, columnDefs: IQueryColumnDef[], records: Record<string, any>[]): Promise<void>;
|
|
16
|
+
closeAsync(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDbContextExecutor.js","sourceRoot":"","sources":["../../../../sd-orm-common/src/IDbContextExecutor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDbMigration.js","sourceRoot":"","sources":["../../../../sd-orm-common/src/IDbMigration.ts"],"names":[],"mappings":""}
|