@l-v-yonsama/multi-platform-database-drivers 1.3.0 → 2.0.0
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/README.md +40 -0
- package/built/src/drivers/Auth0Driver.js +9 -9
- package/built/src/drivers/Auth0Driver.js.map +1 -1
- package/built/src/drivers/AwsDriver.js +3 -3
- package/built/src/drivers/AwsDriver.js.map +1 -1
- package/built/src/drivers/BaseDriver.d.ts +1 -1
- package/built/src/drivers/BaseDriver.js +4 -6
- package/built/src/drivers/BaseDriver.js.map +1 -1
- package/built/src/drivers/DBDriverResolver.js.map +1 -1
- package/built/src/drivers/DBError.js.map +1 -1
- package/built/src/drivers/KeycloakDriver.d.ts +2 -3
- package/built/src/drivers/KeycloakDriver.js +27 -262
- package/built/src/drivers/KeycloakDriver.js.map +1 -1
- package/built/src/drivers/MemcacheDriver.d.ts +0 -1
- package/built/src/drivers/MemcacheDriver.js +5 -5
- package/built/src/drivers/MemcacheDriver.js.map +1 -1
- package/built/src/drivers/MqttDriver.d.ts +0 -1
- package/built/src/drivers/MqttDriver.js +4 -4
- package/built/src/drivers/MqttDriver.js.map +1 -1
- package/built/src/drivers/MySQLDriver.js +12 -12
- package/built/src/drivers/MySQLDriver.js.map +1 -1
- package/built/src/drivers/OracleDriver.js +13 -13
- package/built/src/drivers/OracleDriver.js.map +1 -1
- package/built/src/drivers/PostgresDriver.js +22 -2
- package/built/src/drivers/PostgresDriver.js.map +1 -1
- package/built/src/drivers/RDSBaseDriver.d.ts +1 -1
- package/built/src/drivers/RDSBaseDriver.js +6 -6
- package/built/src/drivers/RDSBaseDriver.js.map +1 -1
- package/built/src/drivers/RedisDriver.js +2 -2
- package/built/src/drivers/RedisDriver.js.map +1 -1
- package/built/src/drivers/SQLServerDriver.js +7 -7
- package/built/src/drivers/SQLServerDriver.js.map +1 -1
- package/built/src/drivers/SQLiteDriver.d.ts +1 -1
- package/built/src/drivers/SQLiteDriver.js +7 -7
- package/built/src/drivers/SQLiteDriver.js.map +1 -1
- package/built/src/drivers/aws/AwsCloudFormationServiceClient.js +2 -2
- package/built/src/drivers/aws/AwsCloudFormationServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsCloudwatchServiceClient.js +3 -3
- package/built/src/drivers/aws/AwsCloudwatchServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsDynamoServiceClient.js +7 -7
- package/built/src/drivers/aws/AwsDynamoServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsS3ServiceClient.js +24 -24
- package/built/src/drivers/aws/AwsS3ServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsSESServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsSQSServiceClient.js +8 -8
- package/built/src/drivers/aws/AwsSQSServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsSecretsManagerServiceClient.js +1 -1
- package/built/src/drivers/aws/AwsSecretsManagerServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsServiceClient.js +2 -2
- package/built/src/drivers/aws/AwsServiceClient.js.map +1 -1
- package/built/src/drivers/aws/AwsSsmServiceClient.js +1 -1
- package/built/src/drivers/aws/AwsSsmServiceClient.js.map +1 -1
- package/built/src/drivers/keycloak/resourceTreeBuilder.d.ts +5 -0
- package/built/src/drivers/keycloak/resourceTreeBuilder.js +37 -0
- package/built/src/drivers/keycloak/resourceTreeBuilder.js.map +1 -0
- package/built/src/drivers/keycloak/scanResultBuilder.d.ts +8 -0
- package/built/src/drivers/keycloak/scanResultBuilder.js +212 -0
- package/built/src/drivers/keycloak/scanResultBuilder.js.map +1 -0
- package/built/src/drivers/memcache/helper.d.ts +0 -1
- package/built/src/drivers/memcache/helper.js +13 -14
- package/built/src/drivers/memcache/helper.js.map +1 -1
- package/built/src/helpers/ProposalHelper.js +3 -3
- package/built/src/helpers/ProposalHelper.js.map +1 -1
- package/built/src/helpers/RdhRecordRuleHelper.js.map +1 -1
- package/built/src/helpers/RuleEngine.d.ts +5 -5
- package/built/src/helpers/RuleEngine.js +14 -14
- package/built/src/helpers/RuleEngine.js.map +1 -1
- package/built/src/helpers/SQLHelper.d.ts +8 -115
- package/built/src/helpers/SQLHelper.js +35 -1084
- package/built/src/helpers/SQLHelper.js.map +1 -1
- package/built/src/helpers/prompts/Auth0PromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/AwsPromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/KeycloakPromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/MemcachePromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/MqttPromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/RdsPromptHelper.js +1 -1
- package/built/src/helpers/prompts/RdsPromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/RedisPromptHelper.js.map +1 -1
- package/built/src/helpers/prompts/SchemaPromptHelper.js.map +1 -1
- package/built/src/helpers/sql/dynamoConversion.d.ts +2 -0
- package/built/src/helpers/sql/dynamoConversion.js +27 -0
- package/built/src/helpers/sql/dynamoConversion.js.map +1 -0
- package/built/src/helpers/sql/formatQuery.d.ts +6 -0
- package/built/src/helpers/sql/formatQuery.js +45 -0
- package/built/src/helpers/sql/formatQuery.js.map +1 -0
- package/built/src/helpers/sql/mutationQuery.d.ts +54 -0
- package/built/src/helpers/sql/mutationQuery.js +250 -0
- package/built/src/helpers/sql/mutationQuery.js.map +1 -0
- package/built/src/helpers/sql/parameterNormalizer.d.ts +16 -0
- package/built/src/helpers/sql/parameterNormalizer.js +166 -0
- package/built/src/helpers/sql/parameterNormalizer.js.map +1 -0
- package/built/src/helpers/sql/queryParser.d.ts +6 -0
- package/built/src/helpers/sql/queryParser.js +239 -0
- package/built/src/helpers/sql/queryParser.js.map +1 -0
- package/built/src/helpers/sql/quote.d.ts +17 -0
- package/built/src/helpers/sql/quote.js +140 -0
- package/built/src/helpers/sql/quote.js.map +1 -0
- package/built/src/helpers/sql/selectQuery.d.ts +24 -0
- package/built/src/helpers/sql/selectQuery.js +262 -0
- package/built/src/helpers/sql/selectQuery.js.map +1 -0
- package/built/src/resource/aws.d.ts +106 -0
- package/built/src/resource/aws.js +219 -0
- package/built/src/resource/aws.js.map +1 -0
- package/built/src/resource/base.d.ts +28 -0
- package/built/src/resource/base.js +76 -0
- package/built/src/resource/base.js.map +1 -0
- package/built/src/resource/connection.d.ts +35 -0
- package/built/src/resource/connection.js +52 -0
- package/built/src/resource/connection.js.map +1 -0
- package/built/src/resource/fromJson.d.ts +2 -0
- package/built/src/resource/fromJson.js +125 -0
- package/built/src/resource/fromJson.js.map +1 -0
- package/built/src/resource/iam.d.ts +70 -0
- package/built/src/resource/iam.js +175 -0
- package/built/src/resource/iam.js.map +1 -0
- package/built/src/resource/index.d.ts +8 -1
- package/built/src/resource/index.js +8 -1
- package/built/src/resource/index.js.map +1 -1
- package/built/src/resource/keyValue.d.ts +85 -0
- package/built/src/resource/keyValue.js +74 -0
- package/built/src/resource/keyValue.js.map +1 -0
- package/built/src/resource/rdb.d.ts +49 -0
- package/built/src/resource/rdb.js +155 -0
- package/built/src/resource/rdb.js.map +1 -0
- package/built/src/resource/types.d.ts +18 -0
- package/built/src/resource/types.js +3 -0
- package/built/src/resource/types.js.map +1 -0
- package/built/src/types/drivers/Keycloak.js +1 -1
- package/built/src/types/drivers/Keycloak.js.map +1 -1
- package/built/src/types/drivers/MemcachedParams.d.ts +0 -1
- package/built/src/types/helpers/index.js +1 -1
- package/built/src/types/helpers/index.js.map +1 -1
- package/built/src/types/resource/AwsCfnStackAttributes.d.ts +1 -1
- package/built/src/types/resource/MySQLColumnType.js +2 -2
- package/built/src/types/resource/MySQLColumnType.js.map +1 -1
- package/built/src/types/resource/OracleColumnType.js +2 -2
- package/built/src/types/resource/OracleColumnType.js.map +1 -1
- package/built/src/types/resource/PartiQLAttrType.js.map +1 -1
- package/built/src/types/resource/PostgresColumnType.js +2 -2
- package/built/src/types/resource/PostgresColumnType.js.map +1 -1
- package/built/src/types/resource/SQLServerColumnType.js +2 -2
- package/built/src/types/resource/SQLServerColumnType.js.map +1 -1
- package/built/src/types/utils/index.js +2 -2
- package/built/src/types/utils/index.js.map +1 -1
- package/built/src/utils/base.js +1 -1
- package/built/src/utils/base.js.map +1 -1
- package/built/src/utils/cfn/applicationDiagram.js +52 -12
- package/built/src/utils/cfn/applicationDiagram.js.map +1 -1
- package/built/src/utils/cfn/applicationRelations.d.ts +1 -1
- package/built/src/utils/cfn/applicationRelations.js +107 -15
- package/built/src/utils/cfn/applicationRelations.js.map +1 -1
- package/built/src/utils/cfn/cfnDependencyGraphDiagram.js.map +1 -1
- package/built/src/utils/cfn/{architectureTopology.d.ts → deploymentTopology.d.ts} +5 -1
- package/built/src/utils/cfn/{architectureTopology.js → deploymentTopology.js} +127 -13
- package/built/src/utils/cfn/deploymentTopology.js.map +1 -0
- package/built/src/utils/cfn/diagramFileModel.js.map +1 -1
- package/built/src/utils/cfn/drawio/cfnDependencyGraphDiagram.d.ts +3 -0
- package/built/src/utils/cfn/drawio/cfnDependencyGraphDiagram.js +174 -0
- package/built/src/utils/cfn/drawio/cfnDependencyGraphDiagram.js.map +1 -0
- package/built/src/utils/cfn/drawio/commonCells.d.ts +22 -0
- package/built/src/utils/cfn/drawio/commonCells.js +83 -0
- package/built/src/utils/cfn/drawio/commonCells.js.map +1 -0
- package/built/src/utils/cfn/drawio/edgeRouting.d.ts +34 -0
- package/built/src/utils/cfn/drawio/edgeRouting.js +77 -0
- package/built/src/utils/cfn/drawio/edgeRouting.js.map +1 -0
- package/built/src/utils/cfn/drawio/multiAzInfrastructureDiagram.d.ts +3 -0
- package/built/src/utils/cfn/drawio/multiAzInfrastructureDiagram.js +812 -0
- package/built/src/utils/cfn/drawio/multiAzInfrastructureDiagram.js.map +1 -0
- package/built/src/utils/cfn/drawioApplicationDiagram.d.ts +1 -0
- package/built/src/utils/cfn/drawioApplicationDiagram.js +290 -32
- package/built/src/utils/cfn/drawioApplicationDiagram.js.map +1 -1
- package/built/src/utils/cfn/drawioInfrastructureDiagrams.d.ts +2 -4
- package/built/src/utils/cfn/drawioInfrastructureDiagrams.js +7 -441
- package/built/src/utils/cfn/drawioInfrastructureDiagrams.js.map +1 -1
- package/built/src/utils/cfn/drawioXml.d.ts +0 -24
- package/built/src/utils/cfn/drawioXml.js +5 -47
- package/built/src/utils/cfn/drawioXml.js.map +1 -1
- package/built/src/utils/cfn/generateDiagram.js +3 -4
- package/built/src/utils/cfn/generateDiagram.js.map +1 -1
- package/built/src/utils/cfn/icons.js.map +1 -1
- package/built/src/utils/cfn/index.d.ts +4 -4
- package/built/src/utils/cfn/index.js +9 -8
- package/built/src/utils/cfn/index.js.map +1 -1
- package/built/src/utils/cfn/intrinsics.d.ts +1 -1
- package/built/src/utils/cfn/intrinsics.js.map +1 -1
- package/built/src/utils/cfn/multiAzDeploymentTrafficPathsAndProtection.d.ts +27 -0
- package/built/src/utils/cfn/{multiAzDeploymentDataPaths.js → multiAzDeploymentTrafficPathsAndProtection.js} +162 -10
- package/built/src/utils/cfn/multiAzDeploymentTrafficPathsAndProtection.js.map +1 -0
- package/built/src/utils/cfn/multiAzDeploymentTrafficPathsAndProtectionDiagram.d.ts +2 -0
- package/built/src/utils/cfn/{architectureDiagram.js → multiAzDeploymentTrafficPathsAndProtectionDiagram.js} +82 -34
- package/built/src/utils/cfn/multiAzDeploymentTrafficPathsAndProtectionDiagram.js.map +1 -0
- package/built/src/utils/cfn/naming.d.ts +2 -1
- package/built/src/utils/cfn/naming.js +3 -3
- package/built/src/utils/cfn/naming.js.map +1 -1
- package/built/src/utils/cfn/resourceDependencies.js.map +1 -1
- package/built/src/utils/cfn/templateParsing.js +11 -26
- package/built/src/utils/cfn/templateParsing.js.map +1 -1
- package/built/src/utils/csv.js.map +1 -1
- package/built/src/utils/dbType.js.map +1 -1
- package/built/src/utils/diagramLayout/elkLayoutEngine.d.ts +3 -0
- package/built/src/utils/diagramLayout/elkLayoutEngine.js +199 -0
- package/built/src/utils/diagramLayout/elkLayoutEngine.js.map +1 -0
- package/built/src/utils/diagramLayout/index.d.ts +4 -0
- package/built/src/utils/diagramLayout/index.js +13 -0
- package/built/src/utils/diagramLayout/index.js.map +1 -0
- package/built/src/utils/diagramLayout/normalizeLayout.d.ts +33 -0
- package/built/src/utils/diagramLayout/normalizeLayout.js +116 -0
- package/built/src/utils/diagramLayout/normalizeLayout.js.map +1 -0
- package/built/src/utils/diagramLayout/types.d.ts +64 -0
- package/built/src/utils/diagramLayout/types.js +3 -0
- package/built/src/utils/diagramLayout/types.js.map +1 -0
- package/built/src/utils/drawio/drawioXml.d.ts +24 -0
- package/built/src/utils/drawio/drawioXml.js +47 -0
- package/built/src/utils/drawio/drawioXml.js.map +1 -0
- package/built/src/utils/drawio/index.d.ts +2 -0
- package/built/src/utils/drawio/index.js +10 -0
- package/built/src/utils/drawio/index.js.map +1 -0
- package/built/src/utils/driverUtil.d.ts +1 -1
- package/built/src/utils/driverUtil.js.map +1 -1
- package/built/src/utils/er/erDiagramDrawioGenerator.d.ts +26 -0
- package/built/src/utils/er/erDiagramDrawioGenerator.js +99 -0
- package/built/src/utils/er/erDiagramDrawioGenerator.js.map +1 -0
- package/built/src/utils/er/erDiagramDrawioGeneratorAuto.d.ts +2 -0
- package/built/src/utils/er/erDiagramDrawioGeneratorAuto.js +103 -0
- package/built/src/utils/er/erDiagramDrawioGeneratorAuto.js.map +1 -0
- package/built/src/utils/er/erDiagramGenerator.d.ts +7 -0
- package/built/src/utils/er/erDiagramGenerator.js +321 -0
- package/built/src/utils/er/erDiagramGenerator.js.map +1 -0
- package/built/src/utils/er/index.d.ts +4 -0
- package/built/src/utils/er/index.js +13 -0
- package/built/src/utils/er/index.js.map +1 -0
- package/built/src/utils/er/types.d.ts +31 -0
- package/built/src/utils/er/types.js +3 -0
- package/built/src/utils/er/types.js.map +1 -0
- package/built/src/utils/index.d.ts +1 -0
- package/built/src/utils/index.js +1 -0
- package/built/src/utils/index.js.map +1 -1
- package/built/src/utils/log/LogParser.js.map +1 -1
- package/built/src/utils/log/buildSqlExecutions.js +3 -4
- package/built/src/utils/log/buildSqlExecutions.js.map +1 -1
- package/built/src/utils/log/classify/classifyEvent.js +2 -3
- package/built/src/utils/log/classify/classifyEvent.js.map +1 -1
- package/built/src/utils/log/detect/presetDetector.js +4 -5
- package/built/src/utils/log/detect/presetDetector.js.map +1 -1
- package/built/src/utils/log/extract/runExtractors.js +1 -2
- package/built/src/utils/log/extract/runExtractors.js.map +1 -1
- package/built/src/utils/log/logSummary.js +5 -5
- package/built/src/utils/log/logSummary.js.map +1 -1
- package/built/src/utils/log/pattern/logEventPattern.js +2 -3
- package/built/src/utils/log/pattern/logEventPattern.js.map +1 -1
- package/built/src/utils/log/rdh/convertExtractedSqlRdhResult.js +2 -3
- package/built/src/utils/log/rdh/convertExtractedSqlRdhResult.js.map +1 -1
- package/built/src/utils/log/split/splitLogEvents.js +1 -2
- package/built/src/utils/log/split/splitLogEvents.js.map +1 -1
- package/built/src/utils/log/sql/removeSqlComments.js +2 -3
- package/built/src/utils/log/sql/removeSqlComments.js.map +1 -1
- package/built/src/utils/log/validator.js +8 -5
- package/built/src/utils/log/validator.js.map +1 -1
- package/package.json +13 -9
- package/built/src/resource/DbResource.d.ts +0 -373
- package/built/src/resource/DbResource.js +0 -836
- package/built/src/resource/DbResource.js.map +0 -1
- package/built/src/utils/cfn/architectureDiagram.d.ts +0 -3
- package/built/src/utils/cfn/architectureDiagram.js.map +0 -1
- package/built/src/utils/cfn/architectureTopology.js.map +0 -1
- package/built/src/utils/cfn/multiAzDeploymentDataPaths.d.ts +0 -27
- package/built/src/utils/cfn/multiAzDeploymentDataPaths.js.map +0 -1
|
@@ -1,1087 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toRdsDatabase = exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Keycloak: 'mysql',
|
|
39
|
-
Auth0: 'mysql',
|
|
40
|
-
Aws: 'mysql',
|
|
41
|
-
Mqtt: 'mysql',
|
|
42
|
-
};
|
|
43
|
-
const getSqlLanguage = (dbType) => {
|
|
44
|
-
return DBTypeToSqlLanguageMap[dbType];
|
|
45
|
-
};
|
|
46
|
-
exports.getSqlLanguage = getSqlLanguage;
|
|
47
|
-
const formatQuery = (query, cfg) => {
|
|
48
|
-
const _a = cfg !== null && cfg !== void 0 ? cfg : {}, { dbType, language } = _a, rest = tslib_1.__rest(_a, ["dbType", "language"]);
|
|
49
|
-
const resolvedLanguage = language !== null && language !== void 0 ? language : (dbType ? (0, exports.getSqlLanguage)(dbType) : undefined);
|
|
50
|
-
const merged = Object.assign(Object.assign(Object.assign({}, DEFAULT_FORMAT_OPTIONS), rest), (resolvedLanguage ? { language: resolvedLanguage } : {}));
|
|
51
|
-
return (0, sql_formatter_1.format)(query, merged);
|
|
52
|
-
};
|
|
53
|
-
exports.formatQuery = formatQuery;
|
|
54
|
-
const createUndoChangeSQL = ({ schemaName, tableName, columns, diffResult, bindOption, quote, sqlLang, idQuoteCharacter, }) => {
|
|
55
|
-
const { ok, toBeInserted, toBeUpdated, toBeDeleted } = diffResult;
|
|
56
|
-
if (!ok) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
const list = [];
|
|
60
|
-
list.push(...toBeInserted.map((it) => (0, exports.toInsertStatement)({
|
|
61
|
-
schemaName,
|
|
62
|
-
tableName,
|
|
63
|
-
columns,
|
|
64
|
-
values: it.values,
|
|
65
|
-
bindOption,
|
|
66
|
-
compactSql: true,
|
|
67
|
-
quote,
|
|
68
|
-
sqlLang,
|
|
69
|
-
idQuoteCharacter,
|
|
70
|
-
})));
|
|
71
|
-
list.push(...toBeUpdated.map((it) => (0, exports.toUpdateStatement)({
|
|
72
|
-
schemaName,
|
|
73
|
-
tableName,
|
|
74
|
-
columns,
|
|
75
|
-
values: it.values,
|
|
76
|
-
conditions: it.conditions,
|
|
77
|
-
bindOption,
|
|
78
|
-
quote,
|
|
79
|
-
sqlLang,
|
|
80
|
-
idQuoteCharacter,
|
|
81
|
-
})));
|
|
82
|
-
list.push(...toBeDeleted.map((it) => (0, exports.toDeleteStatement)({
|
|
83
|
-
schemaName,
|
|
84
|
-
tableName,
|
|
85
|
-
columns,
|
|
86
|
-
conditions: it.conditions,
|
|
87
|
-
bindOption,
|
|
88
|
-
quote,
|
|
89
|
-
sqlLang,
|
|
90
|
-
idQuoteCharacter,
|
|
91
|
-
})));
|
|
92
|
-
return list;
|
|
93
|
-
};
|
|
94
|
-
exports.createUndoChangeSQL = createUndoChangeSQL;
|
|
95
|
-
const toInsertStatement = ({ schemaName, tableName, tableComment, columns, values, bindOption, withComment, compactSql, quote, idQuoteCharacter, sqlLang, }) => {
|
|
96
|
-
const tableNameWithSchema = (0, exports.createTableNameWithSchema)({
|
|
97
|
-
schema: schemaName,
|
|
98
|
-
table: tableName,
|
|
99
|
-
idQuoteCharacter,
|
|
100
|
-
sqlLang,
|
|
101
|
-
});
|
|
102
|
-
const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
|
|
103
|
-
const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
|
|
104
|
-
const binds = [];
|
|
105
|
-
const embdeddedValues = [];
|
|
106
|
-
const columnComments = [];
|
|
107
|
-
const columnNames = [];
|
|
108
|
-
const placeHolders = [];
|
|
109
|
-
let index = 0;
|
|
110
|
-
Object.keys(values).forEach((key) => {
|
|
111
|
-
var _a;
|
|
112
|
-
const column = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key));
|
|
113
|
-
const colType = (_a = column === null || column === void 0 ? void 0 : column.type) !== null && _a !== void 0 ? _a : rdh_1.GeneralColumnType.UNKNOWN;
|
|
114
|
-
columnNames.push(`${quote ? (0, exports.wrapQuote)(key, '`') : key}`);
|
|
115
|
-
if (specifyValuesWithBindParameters) {
|
|
116
|
-
const value = toBindValue(colType, values[key]);
|
|
117
|
-
binds.push(value);
|
|
118
|
-
placeHolders.push(toPositionedParameter === true ? `${pChar}${index + 1}` : '?');
|
|
119
|
-
index++;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
embdeddedValues.push(toEmbeddedStringValue(colType, values[key]));
|
|
123
|
-
}
|
|
124
|
-
if (column === null || column === void 0 ? void 0 : column.comment) {
|
|
125
|
-
columnComments.push(`${column === null || column === void 0 ? void 0 : column.comment} [${colType}]`);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
columnComments.push(`${key} [${colType}]`);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
let query = '';
|
|
132
|
-
if (withComment && tableComment) {
|
|
133
|
-
query += `-- ${tableComment + os.EOL}`;
|
|
134
|
-
}
|
|
135
|
-
if (compactSql) {
|
|
136
|
-
if (sqlLang === 'partiql') {
|
|
137
|
-
query += `INSERT INTO ${tableNameWithSchema} VALUE {${columnNames
|
|
138
|
-
.map((it, idx) => `${(0, exports.wrapSingleQuote)(it)}: ${specifyValuesWithBindParameters
|
|
139
|
-
? placeHolders[idx]
|
|
140
|
-
: embdeddedValues[idx]}`)
|
|
141
|
-
.join(',' + os.EOL)}}`;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
query += `INSERT INTO ${tableNameWithSchema} (${columnNames.join(',')}) VALUES (${specifyValuesWithBindParameters
|
|
145
|
-
? placeHolders.join(',')
|
|
146
|
-
: embdeddedValues.join(',')})`;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
if (sqlLang === 'partiql') {
|
|
151
|
-
query += `INSERT INTO ${tableNameWithSchema} ${os.EOL}`;
|
|
152
|
-
query += `VALUE {${os.EOL}`;
|
|
153
|
-
if (specifyValuesWithBindParameters) {
|
|
154
|
-
for (let i = 0; i < placeHolders.length; i++) {
|
|
155
|
-
query += ` ${(0, exports.wrapSingleQuote)(columnNames[i])}: ${placeHolders[i]}${i < placeHolders.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
for (let i = 0; i < embdeddedValues.length; i++) {
|
|
160
|
-
query += ` ${(0, exports.wrapSingleQuote)(columnNames[i])}: ${embdeddedValues[i]}${i < embdeddedValues.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
query += `}${os.EOL}`;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
query += `INSERT INTO ${tableNameWithSchema + os.EOL} (${os.EOL} `;
|
|
167
|
-
query += `${columnNames.join(',' + os.EOL + ' ')}${os.EOL}`;
|
|
168
|
-
query += `) VALUES (${os.EOL}`;
|
|
169
|
-
if (specifyValuesWithBindParameters) {
|
|
170
|
-
for (let i = 0; i < placeHolders.length; i++) {
|
|
171
|
-
query += ` ${placeHolders[i]}${i < placeHolders.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
for (let i = 0; i < embdeddedValues.length; i++) {
|
|
176
|
-
query += ` ${embdeddedValues[i]}${i < embdeddedValues.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
query += `)${os.EOL}`;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
query,
|
|
184
|
-
binds,
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
exports.toInsertStatement = toInsertStatement;
|
|
188
|
-
const toUpdateStatement = ({ schemaName, tableName, columns, values, conditions, bindOption, quote, idQuoteCharacter, sqlLang, }) => {
|
|
189
|
-
const tableNameWithSchema = (0, exports.createTableNameWithSchema)({
|
|
190
|
-
schema: schemaName,
|
|
191
|
-
table: tableName,
|
|
192
|
-
idQuoteCharacter,
|
|
193
|
-
sqlLang,
|
|
194
|
-
});
|
|
195
|
-
const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
|
|
196
|
-
const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
|
|
197
|
-
const binds = [];
|
|
198
|
-
const setList = [];
|
|
199
|
-
const conditionList = [];
|
|
200
|
-
let index = 0;
|
|
201
|
-
Object.keys(values).forEach((key) => {
|
|
202
|
-
var _a, _b;
|
|
203
|
-
const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
|
|
204
|
-
if (sqlLang === 'partiql') {
|
|
205
|
-
if (specifyValuesWithBindParameters) {
|
|
206
|
-
setList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
|
|
207
|
-
binds.push(toBindValue(colType, values[key]));
|
|
208
|
-
index++;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
setList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toEmbeddedStringValue(colType, values[key])}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
if (specifyValuesWithBindParameters) {
|
|
216
|
-
setList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
|
|
217
|
-
binds.push(toBindValue(colType, values[key]));
|
|
218
|
-
index++;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
setList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toEmbeddedStringValue(colType, values[key])}`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
Object.keys(conditions).forEach((key) => {
|
|
226
|
-
var _a, _b;
|
|
227
|
-
const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
|
|
228
|
-
if (sqlLang === 'partiql') {
|
|
229
|
-
if (specifyValuesWithBindParameters) {
|
|
230
|
-
conditionList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
|
|
231
|
-
binds.push(toBindValue(colType, conditions[key]));
|
|
232
|
-
index++;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
conditionList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
if (specifyValuesWithBindParameters) {
|
|
240
|
-
conditionList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
|
|
241
|
-
binds.push(toBindValue(colType, conditions[key]));
|
|
242
|
-
index++;
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
conditionList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toEmbeddedStringValue(colType, conditions[key])}`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
const query = `UPDATE ${tableNameWithSchema} SET ${setList.join(',')} WHERE ${conditionList.join(' AND ')}`;
|
|
250
|
-
return {
|
|
251
|
-
query,
|
|
252
|
-
binds,
|
|
253
|
-
};
|
|
254
|
-
};
|
|
255
|
-
exports.toUpdateStatement = toUpdateStatement;
|
|
256
|
-
const toDeleteStatement = ({ schemaName, tableName, columns, conditions, bindOption, quote, idQuoteCharacter, sqlLang, }) => {
|
|
257
|
-
const tableNameWithSchema = (0, exports.createTableNameWithSchema)({
|
|
258
|
-
schema: schemaName,
|
|
259
|
-
table: tableName,
|
|
260
|
-
idQuoteCharacter,
|
|
261
|
-
sqlLang,
|
|
262
|
-
});
|
|
263
|
-
const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
|
|
264
|
-
const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
|
|
265
|
-
const binds = [];
|
|
266
|
-
const conditionList = [];
|
|
267
|
-
Object.keys(conditions).forEach((key, index) => {
|
|
268
|
-
var _a, _b;
|
|
269
|
-
const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
|
|
270
|
-
if (sqlLang === 'partiql') {
|
|
271
|
-
if (specifyValuesWithBindParameters) {
|
|
272
|
-
conditionList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
|
|
273
|
-
binds.push(toBindValue(colType, conditions[key]));
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
conditionList.push(`${(0, exports.wrapDoubleQuote)(key)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
if (specifyValuesWithBindParameters) {
|
|
281
|
-
conditionList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
|
|
282
|
-
binds.push(toBindValue(colType, conditions[key]));
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
conditionList.push(`${quote ? (0, exports.wrapBackQuote)(key) : key} = ${toEmbeddedStringValue(colType, conditions[key])}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
const query = `DELETE FROM ${tableNameWithSchema} WHERE ${conditionList.join(' AND ')}`;
|
|
290
|
-
return {
|
|
291
|
-
query,
|
|
292
|
-
binds,
|
|
293
|
-
};
|
|
294
|
-
};
|
|
295
|
-
exports.toDeleteStatement = toDeleteStatement;
|
|
296
|
-
function toViewRecordsQuery({ tableRes, schemaName, idQuoteCharacter, sqlLang, limit, limitClauseStyle, limitMode, limitLastColumn, }) {
|
|
297
|
-
const tableNameWithSchema = (0, exports.createTableNameWithSchema)({
|
|
298
|
-
schema: schemaName,
|
|
299
|
-
table: tableRes.name,
|
|
300
|
-
idQuoteCharacter,
|
|
301
|
-
sqlLang,
|
|
302
|
-
});
|
|
303
|
-
let query = '';
|
|
304
|
-
if (limitClauseStyle === 'top' && limit) {
|
|
305
|
-
query = `SELECT TOP ${limit} * FROM ${tableNameWithSchema}`;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
query = `SELECT * FROM ${tableNameWithSchema}`;
|
|
309
|
-
}
|
|
310
|
-
if (limitMode === 'last') {
|
|
311
|
-
if (!limitLastColumn) {
|
|
312
|
-
throw new Error('limitLastColumn is required when limitMode is "last"');
|
|
313
|
-
}
|
|
314
|
-
const quotedColumn = (0, exports.needsQuoting)(limitLastColumn)
|
|
315
|
-
? (0, exports.wrapBackQuote)(limitLastColumn)
|
|
316
|
-
: limitLastColumn;
|
|
317
|
-
query += ` ORDER BY ${quotedColumn} DESC`;
|
|
318
|
-
}
|
|
319
|
-
if (limitClauseStyle === 'trailing' && limit) {
|
|
320
|
-
query += ` LIMIT ${limit}`;
|
|
321
|
-
}
|
|
322
|
-
else if (limitClauseStyle === 'fetchFirst' && limit) {
|
|
323
|
-
query += ` FETCH FIRST ${limit} ROWS ONLY`;
|
|
324
|
-
}
|
|
325
|
-
return query;
|
|
326
|
-
}
|
|
327
|
-
exports.toViewRecordsQuery = toViewRecordsQuery;
|
|
328
|
-
const toCountRecordsQuery = (params) => {
|
|
329
|
-
return toGeneralQuery(Object.assign({ selectClause: 'COUNT(*)' }, params));
|
|
330
|
-
};
|
|
331
|
-
exports.toCountRecordsQuery = toCountRecordsQuery;
|
|
332
|
-
const createTableNames = (schemaRes) => {
|
|
333
|
-
return schemaRes.children
|
|
334
|
-
.filter((it) => it.resourceType === types_1.ResourceType.Table)
|
|
335
|
-
.map((it) => constant_1.RESERVED_WORDS.includes(it.name.toUpperCase())
|
|
336
|
-
? '`' + it.name + '`'
|
|
337
|
-
: it.name)
|
|
338
|
-
.join(',');
|
|
339
|
-
};
|
|
340
|
-
exports.createTableNames = createTableNames;
|
|
341
|
-
const createColumnNames = (tableRes) => {
|
|
342
|
-
return tableRes.children
|
|
343
|
-
.map((it) => constant_1.RESERVED_WORDS.includes(it.name.toUpperCase())
|
|
344
|
-
? '`' + it.name + '`'
|
|
345
|
-
: it.name)
|
|
346
|
-
.join(',');
|
|
347
|
-
};
|
|
348
|
-
exports.createColumnNames = createColumnNames;
|
|
349
|
-
const toViewDataQuery = (params) => {
|
|
350
|
-
return toGeneralQuery(Object.assign({ selectClause: '*' }, params));
|
|
351
|
-
};
|
|
352
|
-
exports.toViewDataQuery = toViewDataQuery;
|
|
353
|
-
const toViewDataNormalizedQuery = (params) => {
|
|
354
|
-
const { toPositionedParameter, toPositionalCharacter } = params, others = tslib_1.__rest(params, ["toPositionedParameter", "toPositionalCharacter"]);
|
|
355
|
-
const result = (0, exports.toViewDataQuery)(others);
|
|
356
|
-
return (0, exports.normalizeQuery)({
|
|
357
|
-
query: result.query,
|
|
358
|
-
toPositionedParameter,
|
|
359
|
-
toPositionalCharacter,
|
|
360
|
-
bindParams: result.binds,
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
exports.toViewDataNormalizedQuery = toViewDataNormalizedQuery;
|
|
364
|
-
const createConditionalClause = ({ conditions, columns, params, indent, quote, sqlLang, }) => {
|
|
365
|
-
var _a, _b, _c, _d;
|
|
366
|
-
const queries = [];
|
|
367
|
-
let andOr = 'AND';
|
|
368
|
-
const nestedList = [];
|
|
369
|
-
if ((0, RuleEngine_1.isAllConditions)(conditions)) {
|
|
370
|
-
nestedList.push(...conditions.all);
|
|
371
|
-
}
|
|
372
|
-
else if ((0, RuleEngine_1.isAnyConditions)(conditions)) {
|
|
373
|
-
nestedList.push(...conditions.any);
|
|
374
|
-
andOr = 'OR';
|
|
375
|
-
}
|
|
376
|
-
for (const nest of nestedList) {
|
|
377
|
-
if ((0, RuleEngine_1.isTopLevelCondition)(nest)) {
|
|
378
|
-
const q = createConditionalClause({
|
|
379
|
-
conditions: nest,
|
|
380
|
-
columns,
|
|
381
|
-
params,
|
|
382
|
-
indent: indent + ' ',
|
|
383
|
-
quote,
|
|
384
|
-
sqlLang,
|
|
385
|
-
});
|
|
386
|
-
queries.push(`(${os.EOL}${q}${os.EOL}${indent})`);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
const { fact, value, operator } = nest;
|
|
390
|
-
const mcol = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, fact));
|
|
391
|
-
let colType = rdh_1.GeneralColumnType.TEXT;
|
|
392
|
-
if (mcol) {
|
|
393
|
-
if (mcol instanceof DbResource_1.DbColumn) {
|
|
394
|
-
colType = mcol.colType;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
colType = (0, types_1.parseDynamoAttrType)(mcol.attrType);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
let q = `${sqlLang === 'partiql'
|
|
401
|
-
? (0, exports.wrapDoubleQuote)(fact)
|
|
402
|
-
: quote
|
|
403
|
-
? (0, exports.wrapBackQuote)(fact)
|
|
404
|
-
: fact}`;
|
|
405
|
-
q += ` ${(0, RuleEngine_1.operatorToSQLString)(operator)} `;
|
|
406
|
-
if (operator === 'isNull' || operator === 'isNotNull') {
|
|
407
|
-
}
|
|
408
|
-
else if (operator === 'between' ||
|
|
409
|
-
operator === 'in' ||
|
|
410
|
-
operator === 'notIn') {
|
|
411
|
-
let val = null;
|
|
412
|
-
if (value === undefined || value === null) {
|
|
413
|
-
val = null;
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
let arr = [];
|
|
417
|
-
if (Array.isArray(value)) {
|
|
418
|
-
arr = value;
|
|
419
|
-
}
|
|
420
|
-
else if (value.startsWith('[') && value.endsWith(']')) {
|
|
421
|
-
arr = JSON.parse(value);
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
arr = ('' + value).split(/,/).map((it) => it.trim());
|
|
425
|
-
}
|
|
426
|
-
if ((0, rdh_1.isNumericLike)(colType)) {
|
|
427
|
-
val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toNum)(it)) !== null && _a !== void 0 ? _a : null; });
|
|
428
|
-
}
|
|
429
|
-
else if ((0, rdh_1.isBooleanLike)(colType)) {
|
|
430
|
-
val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toBoolean)(it)) !== null && _a !== void 0 ? _a : null; });
|
|
431
|
-
}
|
|
432
|
-
else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
|
|
433
|
-
val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toDate)(it)) !== null && _a !== void 0 ? _a : null; });
|
|
434
|
-
}
|
|
435
|
-
else if ((0, rdh_1.isTime)(colType)) {
|
|
436
|
-
val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toTime)(it)) !== null && _a !== void 0 ? _a : null; });
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
val = arr.map((it) => it + '');
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
if (operator === 'between') {
|
|
443
|
-
const bindName1 = `val${params.pos}`;
|
|
444
|
-
params.pos++;
|
|
445
|
-
const bindName2 = `val${params.pos}`;
|
|
446
|
-
params.pos++;
|
|
447
|
-
q += `:${bindName1} AND :${bindName2}`;
|
|
448
|
-
if (val === null) {
|
|
449
|
-
params.bindParams[bindName1] = null;
|
|
450
|
-
params.bindParams[bindName2] = null;
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
params.bindParams[bindName1] = val[0];
|
|
454
|
-
params.bindParams[bindName2] = val[1];
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
const bindName = `val${params.pos}`;
|
|
459
|
-
params.pos++;
|
|
460
|
-
q += `(:${bindName})`;
|
|
461
|
-
params.bindParams[bindName] = val;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
else if (operator === 'like' && sqlLang === 'partiql') {
|
|
465
|
-
if (value === undefined || value === null) {
|
|
466
|
-
q = `Contains(${(0, exports.wrapDoubleQuote)(fact)}, NULL)`;
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
const bindName = `val${params.pos}`;
|
|
470
|
-
params.bindParams[bindName] = value;
|
|
471
|
-
q = `Contains(${(0, exports.wrapDoubleQuote)(fact)}, :${bindName})`;
|
|
472
|
-
params.pos++;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
let val = null;
|
|
477
|
-
if ((0, rdh_1.isNumericLike)(colType)) {
|
|
478
|
-
val = (_a = (0, rdh_1.toNum)(value)) !== null && _a !== void 0 ? _a : null;
|
|
479
|
-
}
|
|
480
|
-
else if ((0, rdh_1.isBooleanLike)(colType)) {
|
|
481
|
-
val = (_b = (0, rdh_1.toBoolean)(value)) !== null && _b !== void 0 ? _b : null;
|
|
482
|
-
}
|
|
483
|
-
else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
|
|
484
|
-
val = (_c = (0, rdh_1.toDate)(value)) !== null && _c !== void 0 ? _c : null;
|
|
485
|
-
}
|
|
486
|
-
else if ((0, rdh_1.isTime)(colType)) {
|
|
487
|
-
val = (_d = (0, rdh_1.toTime)(value)) !== null && _d !== void 0 ? _d : null;
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
val = value;
|
|
491
|
-
}
|
|
492
|
-
const bindName = `val${params.pos}`;
|
|
493
|
-
q += `:${bindName}`;
|
|
494
|
-
params.bindParams[bindName] = val;
|
|
495
|
-
params.pos++;
|
|
496
|
-
}
|
|
497
|
-
queries.push(q);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
if (queries.length > 0) {
|
|
501
|
-
return indent + queries.join(`${os.EOL}${indent}${andOr} `);
|
|
502
|
-
}
|
|
503
|
-
return '';
|
|
504
|
-
};
|
|
505
|
-
const toSafeQueryForPgsqlAst = (query) => {
|
|
506
|
-
let replacedSql = stripComment(query).replace(/\?/g, '$1');
|
|
507
|
-
replacedSql = replacedSql
|
|
508
|
-
.replace(/^\s*(SHOW)\s+FULL\s+(.*)$/i, '$1 $2')
|
|
509
|
-
.replace(/^\s*(SHOW)\s+(\S+).*$/i, '$1 $2')
|
|
510
|
-
.replace(/@@(GLOBAL|SESSION)\./gi, '');
|
|
511
|
-
replacedSql = replacedSql.replace(/\s*INTERVAL\s+([\d]+)\s+(\S+)/i, " cast('$1 $2' as INTERVAL)");
|
|
512
|
-
replacedSql = replacedSql.replace(/\bLIMIT\s+([\d]+)\s*,\s*([\d]+)/i, 'LIMIT $2 OFFSET $1');
|
|
513
|
-
replacedSql = replacedSql.replace(/\b(SELECT)\s+TOP\s+[\d]+/i, '$1 ');
|
|
514
|
-
replacedSql = replacedSql.replace(/\bLOCK\s+IN\s+(S+)\s+MODE/i, ' ');
|
|
515
|
-
replacedSql = replacedSql.replace(/^\s*(SET)(\s+global)?\s+(\S+)\s+=\s+\S+$/i, '$1 $3 TO dummy');
|
|
516
|
-
replacedSql = replacedSql.replace(/\s*WAITFOR\s+DELAY\s+'([\d:]+)'/i, 'SELECT pg_sleep(1)');
|
|
517
|
-
replacedSql = replacedSql.replace(/\bWITHIN\s+GROUP\s*\([^)]+?\)/gi, ' ');
|
|
518
|
-
replacedSql = replacedSql.replace(/\.\[(notnull|from|table|to)\]/gi, '.a1');
|
|
519
|
-
replacedSql = replacedSql.replace(/\bDATETIME2?\b/gi, 'TIMESTAMP');
|
|
520
|
-
replacedSql = replacedSql.replace(/\bAUTOINCREMENT/gi, '');
|
|
521
|
-
replacedSql = replacedSql.replace(/\b(authorization)/i, '$1_1');
|
|
522
|
-
replacedSql = replacedSql.replace(/\[([^\]]+)\]/g, '"$1"');
|
|
523
|
-
replacedSql = replacedSql.replace(/`([^`]+)`/g, '"$1"');
|
|
524
|
-
replacedSql = replacedSql.replace(/^[ \r\n]+/, '');
|
|
525
|
-
replacedSql = replacedSql.replace(/\bINSERT\s+INTO\s+(.+)\s+VALUE\s+\{[^}]+\}/gim, 'INSERT INTO $1 VALUES (NULL)');
|
|
526
|
-
return replacedSql.replace(FUNCTION_MATCHER, '1');
|
|
527
|
-
};
|
|
528
|
-
exports.toSafeQueryForPgsqlAst = toSafeQueryForPgsqlAst;
|
|
529
|
-
const hasSetVariableClause = (sql) => {
|
|
530
|
-
if (sql.match(/\bSET\s+(VAR|VARIABLE)\s+\w+\s*=\s*['"\w]+;?/gi)) {
|
|
531
|
-
return true;
|
|
532
|
-
}
|
|
533
|
-
if (sql.match(/\bSET\s+@\w+\s*=\s*['"\w]+;?/gi)) {
|
|
534
|
-
return true;
|
|
535
|
-
}
|
|
536
|
-
return false;
|
|
537
|
-
};
|
|
538
|
-
exports.hasSetVariableClause = hasSetVariableClause;
|
|
539
|
-
const parseQuery = (sql) => {
|
|
540
|
-
const replacedSql = (0, exports.toSafeQueryForPgsqlAst)(sql);
|
|
541
|
-
if (replacedSql.toLocaleLowerCase().startsWith('pragma')) {
|
|
542
|
-
return {
|
|
543
|
-
ast: {
|
|
544
|
-
type: 'pragma',
|
|
545
|
-
},
|
|
546
|
-
names: undefined,
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
try {
|
|
550
|
-
const result = (0, pgsql_ast_parser_1.parse)(replacedSql, { locationTracking: true });
|
|
551
|
-
if (result && result.length) {
|
|
552
|
-
let ast = result[0];
|
|
553
|
-
if (ast.type === 'with recursive' || ast.type === 'with') {
|
|
554
|
-
ast = ast.in;
|
|
555
|
-
}
|
|
556
|
-
const { names, additionalNames } = getQNames(result[0], replacedSql);
|
|
557
|
-
return {
|
|
558
|
-
ast,
|
|
559
|
-
names,
|
|
560
|
-
additionalNames,
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
catch (_) {
|
|
565
|
-
const getTypeWithTable = () => {
|
|
566
|
-
const rsql = replacedSql.replace(/[\r\n]/gm, ' ');
|
|
567
|
-
let result = rsql.match(/select\s+.+?\s+FROM\s+(.+?)\s+/i);
|
|
568
|
-
if (result) {
|
|
569
|
-
return { type: 'select', table: unwrapQuote(result[1]) };
|
|
570
|
-
}
|
|
571
|
-
result = rsql.match(/insert\s+into\s+(.+?)\s+/i);
|
|
572
|
-
if (result) {
|
|
573
|
-
return { type: 'insert', table: unwrapQuote(result[1]) };
|
|
574
|
-
}
|
|
575
|
-
result = rsql.match(/update\s+(.+?)\s+(set|remove)\s+/i);
|
|
576
|
-
if (result) {
|
|
577
|
-
return { type: 'update', table: unwrapQuote(result[1]) };
|
|
578
|
-
}
|
|
579
|
-
result = rsql.match(/delete\s+from\s+(.+?)\s+/i);
|
|
580
|
-
if (result) {
|
|
581
|
-
return { type: 'delete', table: unwrapQuote(result[1]) };
|
|
582
|
-
}
|
|
583
|
-
return null;
|
|
584
|
-
};
|
|
585
|
-
const tt = getTypeWithTable();
|
|
586
|
-
if (tt) {
|
|
587
|
-
if (tt.table) {
|
|
588
|
-
return {
|
|
589
|
-
ast: {
|
|
590
|
-
type: tt.type,
|
|
591
|
-
},
|
|
592
|
-
names: {
|
|
593
|
-
tableName: tt.table,
|
|
594
|
-
},
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
return {
|
|
598
|
-
ast: {
|
|
599
|
-
type: tt.type,
|
|
600
|
-
},
|
|
601
|
-
names: undefined,
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return undefined;
|
|
606
|
-
};
|
|
607
|
-
exports.parseQuery = parseQuery;
|
|
608
|
-
const READ_ONLY_STATEMENT_TYPES = new Set([
|
|
609
|
-
'select',
|
|
610
|
-
'show',
|
|
611
|
-
'union',
|
|
612
|
-
'union all',
|
|
613
|
-
'values',
|
|
614
|
-
]);
|
|
615
|
-
const isReadOnlyQuery = (sql) => {
|
|
616
|
-
var _a;
|
|
617
|
-
const qst = (0, exports.parseQuery)(sql);
|
|
618
|
-
const type = (_a = qst === null || qst === void 0 ? void 0 : qst.ast) === null || _a === void 0 ? void 0 : _a.type;
|
|
619
|
-
if (!type) {
|
|
620
|
-
return false;
|
|
621
|
-
}
|
|
622
|
-
if (type === 'pragma') {
|
|
623
|
-
return !/\bpragma\s+[a-zA-Z0-9\-_.()]+\s*=\s*.+/i.test(sql);
|
|
624
|
-
}
|
|
625
|
-
return READ_ONLY_STATEMENT_TYPES.has(type);
|
|
626
|
-
};
|
|
627
|
-
exports.isReadOnlyQuery = isReadOnlyQuery;
|
|
628
|
-
const normalizeQuery = ({ query, toPositionedParameter, toPositionalCharacter, bindParams, }) => {
|
|
629
|
-
if (toPositionedParameter) {
|
|
630
|
-
return (0, exports.normalizePositionedParametersQuery)(query, bindParams, toPositionalCharacter);
|
|
631
|
-
}
|
|
632
|
-
return (0, exports.normalizeSimpleParametersQuery)(query, bindParams);
|
|
633
|
-
};
|
|
634
|
-
exports.normalizeQuery = normalizeQuery;
|
|
635
|
-
const normalizePositionedParametersQuery = (query, bindParams, toPositionalCharacter) => {
|
|
636
|
-
let i = 0;
|
|
637
|
-
const nameWithPos = {};
|
|
638
|
-
const missingParams = new Set();
|
|
639
|
-
const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
|
|
640
|
-
const checkBindParam = (s) => {
|
|
641
|
-
if (bindParams && bindParams[s] === undefined) {
|
|
642
|
-
missingParams.add(s);
|
|
643
|
-
return false;
|
|
644
|
-
}
|
|
645
|
-
return true;
|
|
646
|
-
};
|
|
647
|
-
const getOrCreateSinglePosition = (word) => {
|
|
648
|
-
if (!nameWithPos[word]) {
|
|
649
|
-
nameWithPos[word] = {
|
|
650
|
-
firstPosition: ++i,
|
|
651
|
-
kind: 'single',
|
|
652
|
-
numOfBinds: 1,
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
return `${pChar}${nameWithPos[word].firstPosition}`;
|
|
656
|
-
};
|
|
657
|
-
const getOrCreateMultiplePosition = (word) => {
|
|
658
|
-
var _a, _b;
|
|
659
|
-
if (!nameWithPos[word]) {
|
|
660
|
-
const numOfBinds = bindParams ? (_b = (_a = bindParams[word]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
|
|
661
|
-
if (numOfBinds) {
|
|
662
|
-
++i;
|
|
663
|
-
}
|
|
664
|
-
nameWithPos[word] = {
|
|
665
|
-
firstPosition: i,
|
|
666
|
-
kind: 'multiple',
|
|
667
|
-
numOfBinds,
|
|
668
|
-
};
|
|
669
|
-
if (numOfBinds > 1) {
|
|
670
|
-
i += numOfBinds - 1;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
if (nameWithPos[word].numOfBinds === 0) {
|
|
674
|
-
return ' null ';
|
|
675
|
-
}
|
|
676
|
-
const list = [];
|
|
677
|
-
const first = nameWithPos[word].firstPosition;
|
|
678
|
-
for (let j = first; j < first + nameWithPos[word].numOfBinds; j++) {
|
|
679
|
-
list.push(`${pChar}${j}`);
|
|
680
|
-
}
|
|
681
|
-
return list.join(',');
|
|
682
|
-
};
|
|
683
|
-
const lines = (0, rdh_1.toLines)(stripComment(query));
|
|
684
|
-
const newLines = [];
|
|
685
|
-
lines.forEach((line) => {
|
|
686
|
-
const reg = /((?<!:):([a-zA-Z_$]\w*)\b)/gi;
|
|
687
|
-
const normalized = line.replace(reg, (substring, g1, g2, offset) => {
|
|
688
|
-
const before = line.slice(0, offset);
|
|
689
|
-
const inSingleQuote = (before.match(/'/g) || []).length % 2 !== 0;
|
|
690
|
-
const inDoubleQuote = (before.match(/"/g) || []).length % 2 !== 0;
|
|
691
|
-
if (inSingleQuote || inDoubleQuote) {
|
|
692
|
-
return substring;
|
|
693
|
-
}
|
|
694
|
-
if (g1) {
|
|
695
|
-
const word = g2;
|
|
696
|
-
const ok = checkBindParam(word);
|
|
697
|
-
if (ok && Array.isArray(bindParams[word])) {
|
|
698
|
-
return getOrCreateMultiplePosition(word);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
return getOrCreateSinglePosition(word);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
return '';
|
|
705
|
-
});
|
|
706
|
-
newLines.push(normalized);
|
|
707
|
-
});
|
|
708
|
-
const keys = Object.keys(nameWithPos);
|
|
709
|
-
const binds = new Array(i);
|
|
710
|
-
if (bindParams) {
|
|
711
|
-
if (missingParams.size) {
|
|
712
|
-
const arr = [...missingParams];
|
|
713
|
-
if (arr.length === 1) {
|
|
714
|
-
throw new Error(`Missing bind parameter [${arr[0]}]`);
|
|
715
|
-
}
|
|
716
|
-
throw new Error(`Missing bind parameters [${arr.join(',')}]`);
|
|
717
|
-
}
|
|
718
|
-
keys.forEach((k) => {
|
|
719
|
-
const pos = nameWithPos[k];
|
|
720
|
-
const v = bindParams[k];
|
|
721
|
-
if (pos.kind === 'single') {
|
|
722
|
-
const idx = pos.firstPosition - 1;
|
|
723
|
-
binds[idx] = v;
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
for (let j = 0; j < pos.numOfBinds; j++) {
|
|
727
|
-
const idx = pos.firstPosition + j - 1;
|
|
728
|
-
binds[idx] = v[j];
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
return { query: newLines.join('\n'), binds };
|
|
734
|
-
};
|
|
735
|
-
exports.normalizePositionedParametersQuery = normalizePositionedParametersQuery;
|
|
736
|
-
const normalizeSimpleParametersQuery = (query, bindParams) => {
|
|
737
|
-
const binds = [];
|
|
738
|
-
const missingParams = new Set();
|
|
739
|
-
const checkBindParam = (s) => {
|
|
740
|
-
if (bindParams && bindParams[s] === undefined) {
|
|
741
|
-
missingParams.add(s);
|
|
742
|
-
return false;
|
|
743
|
-
}
|
|
744
|
-
return true;
|
|
745
|
-
};
|
|
746
|
-
const pushBindParam = (s) => {
|
|
747
|
-
if (bindParams) {
|
|
748
|
-
binds.push(bindParams[s]);
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
const lines = (0, rdh_1.toLines)(stripComment(query));
|
|
752
|
-
const newLines = [];
|
|
753
|
-
lines.forEach((line) => {
|
|
754
|
-
const reg = /((?<!:):([a-zA-Z_$]\w*)\b)/gi;
|
|
755
|
-
const normalized = line.replace(reg, (substring, g1, g2, offset) => {
|
|
756
|
-
const before = line.slice(0, offset);
|
|
757
|
-
const inSingleQuote = (before.match(/'/g) || []).length % 2 !== 0;
|
|
758
|
-
const inDoubleQuote = (before.match(/"/g) || []).length % 2 !== 0;
|
|
759
|
-
if (inSingleQuote || inDoubleQuote) {
|
|
760
|
-
return substring;
|
|
761
|
-
}
|
|
762
|
-
if (g1) {
|
|
763
|
-
const word = g2;
|
|
764
|
-
const ok = checkBindParam(word);
|
|
765
|
-
if (ok && Array.isArray(bindParams[word])) {
|
|
766
|
-
const numOfBinds = bindParams[word].length;
|
|
767
|
-
binds.push(...bindParams[word]);
|
|
768
|
-
const bindStr = '?,'.repeat(numOfBinds);
|
|
769
|
-
return bindStr.substring(0, bindStr.length - 1);
|
|
770
|
-
}
|
|
771
|
-
else {
|
|
772
|
-
pushBindParam(word);
|
|
773
|
-
return '?';
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
return '';
|
|
777
|
-
});
|
|
778
|
-
newLines.push(normalized);
|
|
779
|
-
});
|
|
780
|
-
return { query: newLines.join('\n'), binds };
|
|
781
|
-
};
|
|
782
|
-
exports.normalizeSimpleParametersQuery = normalizeSimpleParametersQuery;
|
|
783
|
-
const stripComment = (query) => {
|
|
784
|
-
return query
|
|
785
|
-
.replace(/\/\*[^*]*\*\//gm, '')
|
|
786
|
-
.replace(/(\s)?(#|--)\s+.*$/gm, '$1');
|
|
787
|
-
};
|
|
788
|
-
const wrapSingleQuote = (input) => (0, exports.wrapQuote)(input, "'");
|
|
789
|
-
exports.wrapSingleQuote = wrapSingleQuote;
|
|
790
|
-
const wrapDoubleQuote = (input) => (0, exports.wrapQuote)(input, '"');
|
|
791
|
-
exports.wrapDoubleQuote = wrapDoubleQuote;
|
|
792
|
-
const wrapBackQuote = (input) => (0, exports.wrapQuote)(input, '`');
|
|
793
|
-
exports.wrapBackQuote = wrapBackQuote;
|
|
794
|
-
const wrapQuote = (input, quoteChar) => {
|
|
795
|
-
if (input.startsWith(quoteChar) && input.endsWith(quoteChar)) {
|
|
796
|
-
return input;
|
|
797
|
-
}
|
|
798
|
-
switch (quoteChar) {
|
|
799
|
-
case '"':
|
|
800
|
-
return `"${input.replace(/"/g, '""')}"`;
|
|
801
|
-
case "'":
|
|
802
|
-
return `'${input.replace(/'/g, "''")}'`;
|
|
803
|
-
case '`':
|
|
804
|
-
return `\`${input.replace(/`/g, '``')}\``;
|
|
805
|
-
default:
|
|
806
|
-
throw new Error('Invalid quote char');
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
exports.wrapQuote = wrapQuote;
|
|
810
|
-
const unwrapQuote = (s) => {
|
|
811
|
-
if (s.startsWith('"') && s.endsWith('"')) {
|
|
812
|
-
return s.substring(1, s.length - 1);
|
|
813
|
-
}
|
|
814
|
-
if (s.startsWith("'") && s.endsWith("'")) {
|
|
815
|
-
return s.substring(1, s.length - 1);
|
|
816
|
-
}
|
|
817
|
-
return s;
|
|
818
|
-
};
|
|
819
|
-
const createTableNameWithSchema = ({ schema, table, idQuoteCharacter, sqlLang, }) => {
|
|
820
|
-
if (sqlLang === 'partiql') {
|
|
821
|
-
return (0, exports.wrapDoubleQuote)(table);
|
|
822
|
-
}
|
|
823
|
-
const convertId = (name) => {
|
|
824
|
-
if ((0, exports.needsQuoting)(name)) {
|
|
825
|
-
return idQuoteCharacter === '`'
|
|
826
|
-
? (0, exports.wrapBackQuote)(name)
|
|
827
|
-
: (0, exports.wrapDoubleQuote)(name);
|
|
828
|
-
}
|
|
829
|
-
return name;
|
|
830
|
-
};
|
|
831
|
-
if (schema) {
|
|
832
|
-
return `${convertId(schema)}.${convertId(table)}`;
|
|
833
|
-
}
|
|
834
|
-
return convertId(table);
|
|
835
|
-
};
|
|
836
|
-
exports.createTableNameWithSchema = createTableNameWithSchema;
|
|
837
|
-
const FUNCTION_MATCHER = new RegExp(`(${constant_1.FUNCTIONS.join('|')})\\([^)]+?\\)`, 'gi');
|
|
838
|
-
const toBindValue = (colType, value) => {
|
|
839
|
-
if ((0, rdh_1.isTextLike)(colType)) {
|
|
840
|
-
return value;
|
|
841
|
-
}
|
|
842
|
-
if (value === undefined || value === null || value.length === 0) {
|
|
843
|
-
return null;
|
|
844
|
-
}
|
|
845
|
-
if (colType === rdh_1.GeneralColumnType.STRING_SET) {
|
|
846
|
-
return (0, rdh_1.setOf)(...value
|
|
847
|
-
.split(',')
|
|
848
|
-
.map((it) => it.trim())
|
|
849
|
-
.filter((it) => it.length > 0));
|
|
850
|
-
}
|
|
851
|
-
else if (colType === rdh_1.GeneralColumnType.NUMERIC_SET) {
|
|
852
|
-
return (0, rdh_1.setOf)(...value
|
|
853
|
-
.split(',')
|
|
854
|
-
.map((it) => it.trim())
|
|
855
|
-
.filter((it) => it.length > 0)
|
|
856
|
-
.map((it) => (0, rdh_1.toNum)(it)));
|
|
857
|
-
}
|
|
858
|
-
if ((0, rdh_1.isNumericLike)(colType) ||
|
|
859
|
-
(0, rdh_1.isDateTimeOrDateOrTime)(colType) ||
|
|
860
|
-
(0, rdh_1.isBooleanLike)(colType)) {
|
|
861
|
-
let v;
|
|
862
|
-
if ((0, rdh_1.isNumericLike)(colType)) {
|
|
863
|
-
v = (0, rdh_1.toNum)(value);
|
|
864
|
-
}
|
|
865
|
-
else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
|
|
866
|
-
v = (0, rdh_1.toDate)(value);
|
|
867
|
-
}
|
|
868
|
-
else if ((0, rdh_1.isTime)(colType)) {
|
|
869
|
-
v = (0, rdh_1.toTime)(value);
|
|
870
|
-
}
|
|
871
|
-
else {
|
|
872
|
-
v = (0, rdh_1.toBoolean)(value);
|
|
873
|
-
}
|
|
874
|
-
return v === undefined ? null : v;
|
|
875
|
-
}
|
|
876
|
-
return value;
|
|
877
|
-
};
|
|
878
|
-
const toEmbeddedStringValue = (colType, value) => {
|
|
879
|
-
if (value === undefined || value === null) {
|
|
880
|
-
return 'NULL';
|
|
881
|
-
}
|
|
882
|
-
if ((0, rdh_1.isTextLike)(colType) || (0, rdh_1.isEnumOrSet)(colType)) {
|
|
883
|
-
return (0, exports.wrapSingleQuote)(value);
|
|
884
|
-
}
|
|
885
|
-
if ((0, rdh_1.isJsonLike)(colType)) {
|
|
886
|
-
const text = typeof value === 'string' ? value : JSON.stringify(value);
|
|
887
|
-
return (0, exports.wrapSingleQuote)(text);
|
|
888
|
-
}
|
|
889
|
-
if (value.length === 0) {
|
|
890
|
-
return 'NULL';
|
|
891
|
-
}
|
|
892
|
-
if ((0, rdh_1.isUUIDType)(colType)) {
|
|
893
|
-
return (0, exports.wrapSingleQuote)(value);
|
|
894
|
-
}
|
|
895
|
-
if (colType == rdh_1.GeneralColumnType.BIT) {
|
|
896
|
-
const v = (0, rdh_1.toBoolean)(value);
|
|
897
|
-
return `B'${v ? 1 : 0}'`;
|
|
898
|
-
}
|
|
899
|
-
if ((0, rdh_1.isNumericLike)(colType)) {
|
|
900
|
-
const v = (0, rdh_1.toNum)(value);
|
|
901
|
-
return v === undefined ? 'NULL' : v.toString();
|
|
902
|
-
}
|
|
903
|
-
else if ((0, rdh_1.isTime)(colType)) {
|
|
904
|
-
return value === undefined ? 'NULL' : (0, exports.wrapSingleQuote)(value);
|
|
905
|
-
}
|
|
906
|
-
else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
|
|
907
|
-
const v = (0, rdh_1.toDate)(value);
|
|
908
|
-
return v === undefined
|
|
909
|
-
? 'NULL'
|
|
910
|
-
: `'${(0, dayjs_1.default)(v).format('YYYY-MM-DD HH:mm:ss')}'`;
|
|
911
|
-
}
|
|
912
|
-
return value.toString();
|
|
913
|
-
};
|
|
914
|
-
const needsQuoting = (name) => {
|
|
915
|
-
const safePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
916
|
-
return !safePattern.test(name);
|
|
917
|
-
};
|
|
918
|
-
exports.needsQuoting = needsQuoting;
|
|
919
|
-
const getQNames = (ast, sql) => {
|
|
920
|
-
const ret = {
|
|
921
|
-
names: undefined,
|
|
922
|
-
additionalNames: undefined,
|
|
923
|
-
};
|
|
924
|
-
const qnames = [];
|
|
925
|
-
if (ast) {
|
|
926
|
-
switch (ast.type) {
|
|
927
|
-
case 'select':
|
|
928
|
-
if (ast.from) {
|
|
929
|
-
ast.from
|
|
930
|
-
.filter((from) => from.type === 'table')
|
|
931
|
-
.forEach((from) => {
|
|
932
|
-
const fromName = from['name'];
|
|
933
|
-
qnames.push(createQNamesUsingLocation({
|
|
934
|
-
schemaName: fromName.schema,
|
|
935
|
-
tableName: fromName.name,
|
|
936
|
-
location: fromName._location,
|
|
937
|
-
sql,
|
|
938
|
-
}));
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
break;
|
|
942
|
-
case 'insert':
|
|
943
|
-
qnames.push(createQNamesUsingLocation({
|
|
944
|
-
schemaName: ast.into.schema,
|
|
945
|
-
tableName: ast.into.name,
|
|
946
|
-
location: ast.into._location,
|
|
947
|
-
sql,
|
|
948
|
-
}));
|
|
949
|
-
break;
|
|
950
|
-
case 'update':
|
|
951
|
-
qnames.push(createQNamesUsingLocation({
|
|
952
|
-
schemaName: ast.table.schema,
|
|
953
|
-
tableName: ast.table.name,
|
|
954
|
-
location: ast.table._location,
|
|
955
|
-
sql,
|
|
956
|
-
}));
|
|
957
|
-
break;
|
|
958
|
-
case 'delete':
|
|
959
|
-
qnames.push(createQNamesUsingLocation({
|
|
960
|
-
schemaName: ast.from.schema,
|
|
961
|
-
tableName: ast.from.name,
|
|
962
|
-
location: ast.from._location,
|
|
963
|
-
sql,
|
|
964
|
-
}));
|
|
965
|
-
break;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
if (qnames.length > 0) {
|
|
969
|
-
ret.names = qnames[0];
|
|
970
|
-
if (qnames.length > 1) {
|
|
971
|
-
ret.additionalNames = qnames.slice(1);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
return ret;
|
|
975
|
-
};
|
|
976
|
-
const createQNamesUsingLocation = ({ tableName, schemaName, location, sql, }) => {
|
|
977
|
-
if (location) {
|
|
978
|
-
const qname = sql.substring(location.start, location.end);
|
|
979
|
-
if (schemaName) {
|
|
980
|
-
const names = qname.split('.');
|
|
981
|
-
if (names.length >= 2) {
|
|
982
|
-
return {
|
|
983
|
-
schemaName: unwrapQuote(names[0]),
|
|
984
|
-
tableName: unwrapQuote(names[1]),
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
else {
|
|
989
|
-
return {
|
|
990
|
-
schemaName: undefined,
|
|
991
|
-
tableName: unwrapQuote(qname),
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
return {
|
|
996
|
-
tableName,
|
|
997
|
-
schemaName,
|
|
998
|
-
};
|
|
999
|
-
};
|
|
1000
|
-
const toGeneralQuery = ({ selectClause, tableRes, schemaName, conditions, quote, idQuoteCharacter, sqlLang, limit, limitClauseStyle, }) => {
|
|
1001
|
-
const tableNameWithSchema = (0, exports.createTableNameWithSchema)({
|
|
1002
|
-
schema: schemaName,
|
|
1003
|
-
table: tableRes.name,
|
|
1004
|
-
idQuoteCharacter,
|
|
1005
|
-
sqlLang,
|
|
1006
|
-
});
|
|
1007
|
-
const params = {
|
|
1008
|
-
pos: 1,
|
|
1009
|
-
bindParams: {},
|
|
1010
|
-
};
|
|
1011
|
-
let top = '';
|
|
1012
|
-
if (limitClauseStyle === 'top' && limit !== undefined) {
|
|
1013
|
-
top = `TOP ${limit} `;
|
|
1014
|
-
}
|
|
1015
|
-
let query = `SELECT ${top}${selectClause} ${os.EOL}FROM ${tableNameWithSchema} `;
|
|
1016
|
-
if (conditions && conditions) {
|
|
1017
|
-
const q = createConditionalClause({
|
|
1018
|
-
conditions,
|
|
1019
|
-
columns: tableRes.children,
|
|
1020
|
-
params,
|
|
1021
|
-
indent: ' ',
|
|
1022
|
-
quote,
|
|
1023
|
-
sqlLang,
|
|
1024
|
-
});
|
|
1025
|
-
if (q) {
|
|
1026
|
-
query += os.EOL + 'WHERE' + os.EOL + q;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
if (limitClauseStyle === 'trailing' && limit !== undefined) {
|
|
1030
|
-
query += os.EOL + 'LIMIT ' + limit;
|
|
1031
|
-
}
|
|
1032
|
-
else if (limitClauseStyle === 'fetchFirst' && limit !== undefined) {
|
|
1033
|
-
query += os.EOL + 'FETCH FIRST ' + limit + ' ROWS ONLY';
|
|
1034
|
-
}
|
|
1035
|
-
return {
|
|
1036
|
-
query: query.trim(),
|
|
1037
|
-
binds: params.bindParams,
|
|
1038
|
-
};
|
|
1039
|
-
};
|
|
1040
|
-
const separateMultipleQueries = (text) => {
|
|
1041
|
-
var _a;
|
|
1042
|
-
const quotePattern1 = /('(.*?)(?<!\\)')/;
|
|
1043
|
-
const quotePattern2 = /("(.*?)(?<!\\)")/;
|
|
1044
|
-
const commentPattern = /--.*?(?=[\r\n]|$)|\/\*[\s\S]*?\*\//;
|
|
1045
|
-
const delimiterPattern = /;/;
|
|
1046
|
-
const queries = [];
|
|
1047
|
-
let currentToken = [];
|
|
1048
|
-
const pattern = new RegExp(`(${quotePattern1.source}|${quotePattern2.source}|${commentPattern.source}|${delimiterPattern.source}|[\r\n]+|.)`, 'g');
|
|
1049
|
-
(_a = text.match(pattern)) === null || _a === void 0 ? void 0 : _a.forEach((token) => {
|
|
1050
|
-
if (token === ';') {
|
|
1051
|
-
if (currentToken.length > 0) {
|
|
1052
|
-
queries.push(currentToken.join('').trim());
|
|
1053
|
-
currentToken = [];
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
else {
|
|
1057
|
-
currentToken.push(token);
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
if (currentToken.length > 0) {
|
|
1061
|
-
queries.push(currentToken.join('').trim());
|
|
1062
|
-
}
|
|
1063
|
-
return queries.filter((it) => it.replace(/[\r\n]+/g, ' ').trim().length > 0);
|
|
1064
|
-
};
|
|
1065
|
-
exports.separateMultipleQueries = separateMultipleQueries;
|
|
1066
|
-
const toRdsDatabase = (awsDb) => {
|
|
1067
|
-
if (awsDb === undefined) {
|
|
1068
|
-
return undefined;
|
|
1069
|
-
}
|
|
1070
|
-
const db = new DbResource_1.RdsDatabase(awsDb.name);
|
|
1071
|
-
const schema = new resource_1.DbSchema('public');
|
|
1072
|
-
schema.isDefault = true;
|
|
1073
|
-
db.addChild(schema);
|
|
1074
|
-
awsDb.children.forEach((tbl) => {
|
|
1075
|
-
const table = new DbResource_1.DbTable(tbl.name, 'TABLE', '');
|
|
1076
|
-
schema.addChild(table);
|
|
1077
|
-
tbl.children.forEach((col) => {
|
|
1078
|
-
const column = new DbResource_1.DbColumn(col.name, (0, types_1.parseDynamoAttrType)(col.attrType), {
|
|
1079
|
-
key: col.pk ? 'PRI' : '',
|
|
1080
|
-
});
|
|
1081
|
-
table.addChild(column);
|
|
1082
|
-
});
|
|
1083
|
-
});
|
|
1084
|
-
return db;
|
|
1085
|
-
};
|
|
1086
|
-
exports.toRdsDatabase = toRdsDatabase;
|
|
3
|
+
exports.toRdsDatabase = exports.wrapSingleQuote = exports.wrapQuote = exports.wrapDoubleQuote = exports.wrapBackQuote = exports.needsQuoting = exports.createTableNameWithSchema = exports.normalizeSimpleParametersQuery = exports.normalizeQuery = exports.normalizePositionedParametersQuery = exports.toSafeQueryForPgsqlAst = exports.separateMultipleQueries = exports.parseQuery = exports.isReadOnlyQuery = exports.hasSetVariableClause = exports.toViewRecordsQuery = exports.toViewDataQuery = exports.toViewDataNormalizedQuery = exports.toCountRecordsQuery = exports.createTableNames = exports.createColumnNames = exports.toUpdateStatement = exports.toInsertStatement = exports.toDeleteStatement = exports.createUndoChangeSQL = exports.getSqlLanguage = exports.formatQuery = void 0;
|
|
4
|
+
var formatQuery_1 = require("./sql/formatQuery");
|
|
5
|
+
Object.defineProperty(exports, "formatQuery", { enumerable: true, get: function () { return formatQuery_1.formatQuery; } });
|
|
6
|
+
Object.defineProperty(exports, "getSqlLanguage", { enumerable: true, get: function () { return formatQuery_1.getSqlLanguage; } });
|
|
7
|
+
var mutationQuery_1 = require("./sql/mutationQuery");
|
|
8
|
+
Object.defineProperty(exports, "createUndoChangeSQL", { enumerable: true, get: function () { return mutationQuery_1.createUndoChangeSQL; } });
|
|
9
|
+
Object.defineProperty(exports, "toDeleteStatement", { enumerable: true, get: function () { return mutationQuery_1.toDeleteStatement; } });
|
|
10
|
+
Object.defineProperty(exports, "toInsertStatement", { enumerable: true, get: function () { return mutationQuery_1.toInsertStatement; } });
|
|
11
|
+
Object.defineProperty(exports, "toUpdateStatement", { enumerable: true, get: function () { return mutationQuery_1.toUpdateStatement; } });
|
|
12
|
+
var selectQuery_1 = require("./sql/selectQuery");
|
|
13
|
+
Object.defineProperty(exports, "createColumnNames", { enumerable: true, get: function () { return selectQuery_1.createColumnNames; } });
|
|
14
|
+
Object.defineProperty(exports, "createTableNames", { enumerable: true, get: function () { return selectQuery_1.createTableNames; } });
|
|
15
|
+
Object.defineProperty(exports, "toCountRecordsQuery", { enumerable: true, get: function () { return selectQuery_1.toCountRecordsQuery; } });
|
|
16
|
+
Object.defineProperty(exports, "toViewDataNormalizedQuery", { enumerable: true, get: function () { return selectQuery_1.toViewDataNormalizedQuery; } });
|
|
17
|
+
Object.defineProperty(exports, "toViewDataQuery", { enumerable: true, get: function () { return selectQuery_1.toViewDataQuery; } });
|
|
18
|
+
Object.defineProperty(exports, "toViewRecordsQuery", { enumerable: true, get: function () { return selectQuery_1.toViewRecordsQuery; } });
|
|
19
|
+
var queryParser_1 = require("./sql/queryParser");
|
|
20
|
+
Object.defineProperty(exports, "hasSetVariableClause", { enumerable: true, get: function () { return queryParser_1.hasSetVariableClause; } });
|
|
21
|
+
Object.defineProperty(exports, "isReadOnlyQuery", { enumerable: true, get: function () { return queryParser_1.isReadOnlyQuery; } });
|
|
22
|
+
Object.defineProperty(exports, "parseQuery", { enumerable: true, get: function () { return queryParser_1.parseQuery; } });
|
|
23
|
+
Object.defineProperty(exports, "separateMultipleQueries", { enumerable: true, get: function () { return queryParser_1.separateMultipleQueries; } });
|
|
24
|
+
Object.defineProperty(exports, "toSafeQueryForPgsqlAst", { enumerable: true, get: function () { return queryParser_1.toSafeQueryForPgsqlAst; } });
|
|
25
|
+
var parameterNormalizer_1 = require("./sql/parameterNormalizer");
|
|
26
|
+
Object.defineProperty(exports, "normalizePositionedParametersQuery", { enumerable: true, get: function () { return parameterNormalizer_1.normalizePositionedParametersQuery; } });
|
|
27
|
+
Object.defineProperty(exports, "normalizeQuery", { enumerable: true, get: function () { return parameterNormalizer_1.normalizeQuery; } });
|
|
28
|
+
Object.defineProperty(exports, "normalizeSimpleParametersQuery", { enumerable: true, get: function () { return parameterNormalizer_1.normalizeSimpleParametersQuery; } });
|
|
29
|
+
var quote_1 = require("./sql/quote");
|
|
30
|
+
Object.defineProperty(exports, "createTableNameWithSchema", { enumerable: true, get: function () { return quote_1.createTableNameWithSchema; } });
|
|
31
|
+
Object.defineProperty(exports, "needsQuoting", { enumerable: true, get: function () { return quote_1.needsQuoting; } });
|
|
32
|
+
Object.defineProperty(exports, "wrapBackQuote", { enumerable: true, get: function () { return quote_1.wrapBackQuote; } });
|
|
33
|
+
Object.defineProperty(exports, "wrapDoubleQuote", { enumerable: true, get: function () { return quote_1.wrapDoubleQuote; } });
|
|
34
|
+
Object.defineProperty(exports, "wrapQuote", { enumerable: true, get: function () { return quote_1.wrapQuote; } });
|
|
35
|
+
Object.defineProperty(exports, "wrapSingleQuote", { enumerable: true, get: function () { return quote_1.wrapSingleQuote; } });
|
|
36
|
+
var dynamoConversion_1 = require("./sql/dynamoConversion");
|
|
37
|
+
Object.defineProperty(exports, "toRdsDatabase", { enumerable: true, get: function () { return dynamoConversion_1.toRdsDatabase; } });
|
|
1087
38
|
//# sourceMappingURL=SQLHelper.js.map
|