typesql-cli 0.10.0 → 0.10.1
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/cli.js +9 -20
- package/cli.js.map +1 -1
- package/code-generator.d.ts.map +1 -1
- package/code-generator.js +46 -111
- package/code-generator.js.map +1 -1
- package/describe-dynamic-query.d.ts.map +1 -1
- package/describe-dynamic-query.js +6 -13
- package/describe-dynamic-query.js.map +1 -1
- package/describe-nested-query.d.ts.map +1 -1
- package/describe-nested-query.js +11 -27
- package/describe-nested-query.js.map +1 -1
- package/describe-query.d.ts.map +1 -1
- package/describe-query.js +9 -18
- package/describe-query.js.map +1 -1
- package/drivers/libsql.d.ts.map +1 -1
- package/drivers/libsql.js +1 -2
- package/drivers/libsql.js.map +1 -1
- package/mysql-mapping.d.ts.map +1 -1
- package/mysql-mapping.js +4 -4
- package/mysql-mapping.js.map +1 -1
- package/mysql-query-analyzer/collect-constraints.d.ts.map +1 -1
- package/mysql-query-analyzer/collect-constraints.js +17 -24
- package/mysql-query-analyzer/collect-constraints.js.map +1 -1
- package/mysql-query-analyzer/infer-column-nullability.d.ts.map +1 -1
- package/mysql-query-analyzer/infer-column-nullability.js +13 -29
- package/mysql-query-analyzer/infer-column-nullability.js.map +1 -1
- package/mysql-query-analyzer/infer-param-nullability.d.ts.map +1 -1
- package/mysql-query-analyzer/infer-param-nullability.js +8 -10
- package/mysql-query-analyzer/infer-param-nullability.js.map +1 -1
- package/mysql-query-analyzer/parse.d.ts.map +1 -1
- package/mysql-query-analyzer/parse.js +15 -20
- package/mysql-query-analyzer/parse.js.map +1 -1
- package/mysql-query-analyzer/select-columns.d.ts.map +1 -1
- package/mysql-query-analyzer/select-columns.js +25 -43
- package/mysql-query-analyzer/select-columns.js.map +1 -1
- package/mysql-query-analyzer/traverse.d.ts.map +1 -1
- package/mysql-query-analyzer/traverse.js +61 -144
- package/mysql-query-analyzer/traverse.js.map +1 -1
- package/mysql-query-analyzer/types.d.ts.map +1 -1
- package/mysql-query-analyzer/unify.d.ts.map +1 -1
- package/mysql-query-analyzer/unify.js +13 -57
- package/mysql-query-analyzer/unify.js.map +1 -1
- package/mysql-query-analyzer/util.d.ts.map +1 -1
- package/mysql-query-analyzer/util.js +2 -3
- package/mysql-query-analyzer/util.js.map +1 -1
- package/mysql-query-analyzer/verify-multiple-result.d.ts.map +1 -1
- package/mysql-query-analyzer/verify-multiple-result.js +3 -7
- package/mysql-query-analyzer/verify-multiple-result.js.map +1 -1
- package/package.json +47 -46
- package/queryExectutor.d.ts.map +1 -1
- package/queryExectutor.js +37 -38
- package/queryExectutor.js.map +1 -1
- package/sql-generator.d.ts.map +1 -1
- package/sql-generator.js +5 -8
- package/sql-generator.js.map +1 -1
- package/sqlite-query-analyzer/code-generator.d.ts +2 -2
- package/sqlite-query-analyzer/code-generator.d.ts.map +1 -1
- package/sqlite-query-analyzer/code-generator.js +117 -219
- package/sqlite-query-analyzer/code-generator.js.map +1 -1
- package/sqlite-query-analyzer/parser.d.ts.map +1 -1
- package/sqlite-query-analyzer/parser.js +9 -23
- package/sqlite-query-analyzer/parser.js.map +1 -1
- package/sqlite-query-analyzer/query-executor.d.ts +1 -1
- package/sqlite-query-analyzer/query-executor.d.ts.map +1 -1
- package/sqlite-query-analyzer/query-executor.js +10 -15
- package/sqlite-query-analyzer/query-executor.js.map +1 -1
- package/sqlite-query-analyzer/replace-list-params.d.ts.map +1 -1
- package/sqlite-query-analyzer/replace-list-params.js +1 -2
- package/sqlite-query-analyzer/replace-list-params.js.map +1 -1
- package/sqlite-query-analyzer/sqlite-describe-nested-query.d.ts.map +1 -1
- package/sqlite-query-analyzer/sqlite-describe-nested-query.js +9 -22
- package/sqlite-query-analyzer/sqlite-describe-nested-query.js.map +1 -1
- package/sqlite-query-analyzer/traverse.d.ts.map +1 -1
- package/sqlite-query-analyzer/traverse.js +36 -95
- package/sqlite-query-analyzer/traverse.js.map +1 -1
- package/ts-dynamic-query-descriptor.d.ts.map +1 -1
- package/ts-dynamic-query-descriptor.js +3 -4
- package/ts-dynamic-query-descriptor.js.map +1 -1
- package/ts-nested-descriptor.d.ts.map +1 -1
- package/ts-nested-descriptor.js +2 -3
- package/ts-nested-descriptor.js.map +1 -1
- package/types.d.ts +6 -2
- package/types.d.ts.map +1 -1
- package/util.d.ts.map +1 -1
- package/util.js.map +1 -1
@@ -1,6 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.traverseQueryContext = traverseQueryContext;
|
4
|
+
exports.traverseInsertStatement = traverseInsertStatement;
|
5
|
+
exports.traverseDeleteStatement = traverseDeleteStatement;
|
6
|
+
exports.getUpdateColumns = getUpdateColumns;
|
7
|
+
exports.traverseQuerySpecification = traverseQuerySpecification;
|
8
|
+
exports.traverseWithClause = traverseWithClause;
|
9
|
+
exports.filterColumns = filterColumns;
|
10
|
+
exports.selectAllColumns = selectAllColumns;
|
11
|
+
exports.isMultipleRowResult = isMultipleRowResult;
|
12
|
+
exports.verifyMultipleResult2 = verifyMultipleResult2;
|
13
|
+
exports.getOrderByColumns = getOrderByColumns;
|
4
14
|
const ts_mysql_parser_1 = require("@wsporto/ts-mysql-parser");
|
5
15
|
const describe_query_1 = require("../describe-query");
|
6
16
|
const parse_1 = require("./parse");
|
@@ -57,7 +67,6 @@ function traverseQueryContext(queryContext, dbSchema, namedParameters) {
|
|
57
67
|
}
|
58
68
|
throw Error(`traverseSql - not supported: ${queryContext.constructor.name}`);
|
59
69
|
}
|
60
|
-
exports.traverseQueryContext = traverseQueryContext;
|
61
70
|
function traverseSelectStatement(selectStatement, traverseContext, namedParameters) {
|
62
71
|
const queryExpression = selectStatement.queryExpression();
|
63
72
|
if (queryExpression) {
|
@@ -90,9 +99,7 @@ function traverseSelectStatement(selectStatement, traverseContext, namedParamete
|
|
90
99
|
isMultiRow,
|
91
100
|
dynamicSqlInfo: traverseContext.dynamicSqlInfo
|
92
101
|
};
|
93
|
-
const orderByColumns = orderByParameters.length > 0
|
94
|
-
? getOrderByColumns(result.fromColumns, result.columns)
|
95
|
-
: undefined;
|
102
|
+
const orderByColumns = orderByParameters.length > 0 ? getOrderByColumns(result.fromColumns, result.columns) : undefined;
|
96
103
|
if (orderByColumns) {
|
97
104
|
traverseResult.orderByColumns = orderByColumns;
|
98
105
|
}
|
@@ -105,13 +112,11 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
105
112
|
const allParameters = [];
|
106
113
|
const paramsNullability = {};
|
107
114
|
let exprOrDefaultList = [];
|
108
|
-
const valuesContext = (_a = insertStatement
|
109
|
-
.insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().values_list();
|
115
|
+
const valuesContext = (_a = insertStatement.insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().values_list();
|
110
116
|
if (valuesContext) {
|
111
117
|
exprOrDefaultList = valuesContext.map((valueContext) => {
|
112
118
|
var _a;
|
113
|
-
return ((_a = valueContext.children) === null || _a === void 0 ? void 0 : _a.filter((valueContext) => valueContext instanceof ts_mysql_parser_1.ExprIsContext ||
|
114
|
-
valueContext.getText() === 'DEFAULT')) || [];
|
119
|
+
return ((_a = valueContext.children) === null || _a === void 0 ? void 0 : _a.filter((valueContext) => valueContext instanceof ts_mysql_parser_1.ExprIsContext || valueContext.getText() === 'DEFAULT')) || [];
|
115
120
|
});
|
116
121
|
}
|
117
122
|
const insertIntoTable = (0, collect_constraints_1.getInsertIntoTable)(insertStatement);
|
@@ -136,11 +141,8 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
136
141
|
const numberParamsBefore = traverseContext.parameters.length;
|
137
142
|
const exprType = traverseExpr(expr, traverseContext);
|
138
143
|
const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullability)(expr);
|
139
|
-
traverseContext.parameters
|
140
|
-
.
|
141
|
-
.forEach((param) => {
|
142
|
-
paramsNullability[param.type.id] =
|
143
|
-
paramNullabilityExpr.every((n) => n) && column.notNull;
|
144
|
+
traverseContext.parameters.slice(numberParamsBefore).forEach((param) => {
|
145
|
+
paramsNullability[param.type.id] = paramNullabilityExpr.every((n) => n) && column.notNull;
|
144
146
|
});
|
145
147
|
traverseContext.constraints.push({
|
146
148
|
expression: expr.getText(),
|
@@ -189,9 +191,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
189
191
|
});
|
190
192
|
});
|
191
193
|
const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullabilityQuery)(insertQueryExpression);
|
192
|
-
traverseContext.parameters
|
193
|
-
.slice(numberParamsBefore)
|
194
|
-
.forEach((param, index) => {
|
194
|
+
traverseContext.parameters.slice(numberParamsBefore).forEach((param, index) => {
|
195
195
|
if (paramsNullability[param.type.id] == null) {
|
196
196
|
paramsNullability[param.type.id] = paramNullabilityExpr[index];
|
197
197
|
}
|
@@ -213,7 +213,6 @@ function traverseInsertStatement(insertStatement, traverseContext) {
|
|
213
213
|
};
|
214
214
|
return typeInferenceResult;
|
215
215
|
}
|
216
|
-
exports.traverseInsertStatement = traverseInsertStatement;
|
217
216
|
function traverseUpdateStatement(updateStatement, traverseContext, namedParamters) {
|
218
217
|
var _a;
|
219
218
|
const updateElement = updateStatement.updateList().updateElement_list();
|
@@ -242,9 +241,7 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
|
|
242
241
|
type1: result,
|
243
242
|
type2: column.columnType //freshVar(column.columnName, )
|
244
243
|
});
|
245
|
-
traverseContext.parameters
|
246
|
-
.slice(paramBeforeExpr, traverseContext.parameters.length)
|
247
|
-
.forEach((param, index) => {
|
244
|
+
traverseContext.parameters.slice(paramBeforeExpr, traverseContext.parameters.length).forEach((param, index) => {
|
248
245
|
dataTypes.push({
|
249
246
|
name: namedParamters[paramBeforeExpr + index] || field.name,
|
250
247
|
type: param.type,
|
@@ -268,8 +265,7 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
|
|
268
265
|
});
|
269
266
|
traverseContext.parameters.slice(paramsAfter).forEach((param, index) => {
|
270
267
|
whereParameters.push({
|
271
|
-
name: namedParamters[paramsAfter + index] ||
|
272
|
-
`param${whereParameters.length + 1}`,
|
268
|
+
name: namedParamters[paramsAfter + index] || `param${whereParameters.length + 1}`,
|
273
269
|
type: param.type,
|
274
270
|
notNull: paramNullability[paramsAfter + index],
|
275
271
|
table: ''
|
@@ -308,15 +304,11 @@ function traverseDeleteStatement(deleteStatement, traverseContext) {
|
|
308
304
|
};
|
309
305
|
return typeInferenceResult;
|
310
306
|
}
|
311
|
-
exports.traverseDeleteStatement = traverseDeleteStatement;
|
312
307
|
function getUpdateColumns(updateStatement, traverseContext) {
|
313
|
-
const tableReferences = updateStatement
|
314
|
-
.tableReferenceList()
|
315
|
-
.tableReference_list();
|
308
|
+
const tableReferences = updateStatement.tableReferenceList().tableReference_list();
|
316
309
|
const columns = traverseTableReferenceList(tableReferences, traverseContext, null);
|
317
310
|
return columns;
|
318
311
|
}
|
319
|
-
exports.getUpdateColumns = getUpdateColumns;
|
320
312
|
function traverseInsertQueryExpression(insertQueryExpression, traverseContext) {
|
321
313
|
const queryExpressionOrParens = insertQueryExpression.queryExpressionOrParens();
|
322
314
|
return traverseQueryExpressionOrParens(queryExpressionOrParens, traverseContext);
|
@@ -380,9 +372,7 @@ function traverseQueryExpressionBody(queryExpressionBody, traverseContext, cte,
|
|
380
372
|
const mainQueryResult = traverseQuerySpecification(first, traverseContext);
|
381
373
|
const resultTypes = mainQueryResult.columns.map((t, index) => unionQuerySpec.length === 0
|
382
374
|
? t.type
|
383
|
-
: createUnionVar(t.type, recursiveNames && recursiveNames.length > 0
|
384
|
-
? recursiveNames[index]
|
385
|
-
: t.name)); //TODO mover para traversequeryspecificat?
|
375
|
+
: createUnionVar(t.type, recursiveNames && recursiveNames.length > 0 ? recursiveNames[index] : t.name)); //TODO mover para traversequeryspecificat?
|
386
376
|
if (cte) {
|
387
377
|
resultTypes.forEach((col, index) => {
|
388
378
|
const withCol = {
|
@@ -396,18 +386,12 @@ function traverseQueryExpressionBody(queryExpressionBody, traverseContext, cte,
|
|
396
386
|
});
|
397
387
|
}
|
398
388
|
for (let queryIndex = 0; queryIndex < unionQuerySpec.length; queryIndex++) {
|
399
|
-
const columnNames = recursiveNames && recursiveNames.length > 0
|
400
|
-
|
401
|
-
: mainQueryResult.columns.map((col) => col.name);
|
402
|
-
const newFromColumns = recursiveNames
|
403
|
-
? renameFromColumns(mainQueryResult.columns, columnNames)
|
404
|
-
: [];
|
389
|
+
const columnNames = recursiveNames && recursiveNames.length > 0 ? recursiveNames : mainQueryResult.columns.map((col) => col.name);
|
390
|
+
const newFromColumns = recursiveNames ? renameFromColumns(mainQueryResult.columns, columnNames) : [];
|
405
391
|
const unionQuery = unionQuerySpec[queryIndex];
|
406
392
|
const unionResult = traverseQuerySpecification(unionQuery, Object.assign(Object.assign({}, traverseContext), { fromColumns: newFromColumns }));
|
407
393
|
resultTypes.forEach((t2, index) => {
|
408
|
-
mainQueryResult.columns[index].notNull =
|
409
|
-
mainQueryResult.columns[index].notNull &&
|
410
|
-
unionResult.columns[index].notNull;
|
394
|
+
mainQueryResult.columns[index].notNull = mainQueryResult.columns[index].notNull && unionResult.columns[index].notNull;
|
411
395
|
traverseContext.constraints.push({
|
412
396
|
expression: 'union',
|
413
397
|
coercionType: 'Union',
|
@@ -447,12 +431,8 @@ function renameFromColumns(fromColumns, recursiveNames) {
|
|
447
431
|
}
|
448
432
|
function traverseQuerySpecification(querySpec, traverseContext) {
|
449
433
|
const fromClause = querySpec.fromClause();
|
450
|
-
const fromColumnsFrom = fromClause
|
451
|
-
|
452
|
-
: [];
|
453
|
-
const allColumns = traverseContext.subQuery
|
454
|
-
? traverseContext.fromColumns.concat(fromColumnsFrom)
|
455
|
-
: fromColumnsFrom; //(... where id = t1.id)
|
434
|
+
const fromColumnsFrom = fromClause ? traverseFromClause(fromClause, traverseContext) : [];
|
435
|
+
const allColumns = traverseContext.subQuery ? traverseContext.fromColumns.concat(fromColumnsFrom) : fromColumnsFrom; //(... where id = t1.id)
|
456
436
|
const selectItemListResult = traverseSelectItemList(querySpec.selectItemList(), Object.assign(Object.assign({}, traverseContext), { fromColumns: allColumns, subQueryColumns: fromColumnsFrom }));
|
457
437
|
const whereClause = querySpec.whereClause();
|
458
438
|
//TODO - HAVING, BLAH
|
@@ -489,7 +469,6 @@ function traverseQuerySpecification(querySpec, traverseContext) {
|
|
489
469
|
fromColumns: fromColumnsFrom
|
490
470
|
};
|
491
471
|
}
|
492
|
-
exports.traverseQuerySpecification = traverseQuerySpecification;
|
493
472
|
function traverseWithClause(withClause, traverseContext) {
|
494
473
|
//result1, result2
|
495
474
|
withClause.commonTableExpression_list().forEach((commonTableExpression) => {
|
@@ -512,14 +491,10 @@ function traverseWithClause(withClause, traverseContext) {
|
|
512
491
|
});
|
513
492
|
});
|
514
493
|
}
|
515
|
-
exports.traverseWithClause = traverseWithClause;
|
516
494
|
function traverseFromClause(fromClause, traverseContext) {
|
517
495
|
var _a;
|
518
|
-
const tableReferenceList = (_a = fromClause
|
519
|
-
|
520
|
-
const fromColumns = tableReferenceList
|
521
|
-
? traverseTableReferenceList(tableReferenceList, traverseContext, null)
|
522
|
-
: [];
|
496
|
+
const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference_list();
|
497
|
+
const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList, traverseContext, null) : [];
|
523
498
|
return fromColumns;
|
524
499
|
}
|
525
500
|
function traverseTableReferenceList(tableReferenceList, traverseContext, currentFragment) {
|
@@ -545,8 +520,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
545
520
|
let firstLeftJoinIndex = -1;
|
546
521
|
tab.joinedTable_list().forEach((joined, index) => {
|
547
522
|
var _a, _b;
|
548
|
-
if (((_a = joined.innerJoinType()) === null || _a === void 0 ? void 0 : _a.INNER_SYMBOL()) ||
|
549
|
-
((_b = joined.innerJoinType()) === null || _b === void 0 ? void 0 : _b.JOIN_SYMBOL())) {
|
523
|
+
if (((_a = joined.innerJoinType()) === null || _a === void 0 ? void 0 : _a.INNER_SYMBOL()) || ((_b = joined.innerJoinType()) === null || _b === void 0 ? void 0 : _b.JOIN_SYMBOL())) {
|
550
524
|
firstLeftJoinIndex = -1; //dont need to add notNull = false to joins
|
551
525
|
}
|
552
526
|
else if (firstLeftJoinIndex === -1) {
|
@@ -567,9 +541,7 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
|
|
567
541
|
const joinedFields = traverseTableReferenceList([tableReferences], traverseContext, innerJoinFragment);
|
568
542
|
const paramsAfter = traverseContext.parameters.length;
|
569
543
|
//doesn't duplicate the fields of the USING clause. Ex. INNER JOIN mytable2 USING(id);
|
570
|
-
const joinedFieldsFiltered = usingFields.length > 0
|
571
|
-
? filterUsingFields(joinedFields, usingFields)
|
572
|
-
: joinedFields;
|
544
|
+
const joinedFieldsFiltered = usingFields.length > 0 ? filterUsingFields(joinedFields, usingFields) : joinedFields;
|
573
545
|
allJoinedColumns.push(joinedFieldsFiltered);
|
574
546
|
innerJoinFragment.fields = [
|
575
547
|
...joinedFieldsFiltered.map((f) => ({
|
@@ -752,9 +724,7 @@ function traverseSelectItemList(selectItemList, traverseContext) {
|
|
752
724
|
parameters: [],
|
753
725
|
dependOn: []
|
754
726
|
};
|
755
|
-
const exprType = traverseExpr(expr, Object.assign(Object.assign({}, traverseContext), { currentFragement: traverseContext.subQuery
|
756
|
-
? traverseContext.currentFragement
|
757
|
-
: selectFragment }));
|
727
|
+
const exprType = traverseExpr(expr, Object.assign(Object.assign({}, traverseContext), { currentFragement: traverseContext.subQuery ? traverseContext.currentFragement : selectFragment }));
|
758
728
|
if (!traverseContext.subQuery) {
|
759
729
|
(_a = traverseContext.dynamicSqlInfo.select) === null || _a === void 0 ? void 0 : _a.push(selectFragment);
|
760
730
|
}
|
@@ -819,9 +789,7 @@ function traverseExpr(expr, traverseContext) {
|
|
819
789
|
}
|
820
790
|
return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
|
821
791
|
}
|
822
|
-
if (expr instanceof ts_mysql_parser_1.ExprAndContext ||
|
823
|
-
expr instanceof ts_mysql_parser_1.ExprXorContext ||
|
824
|
-
expr instanceof ts_mysql_parser_1.ExprOrContext) {
|
792
|
+
if (expr instanceof ts_mysql_parser_1.ExprAndContext || expr instanceof ts_mysql_parser_1.ExprXorContext || expr instanceof ts_mysql_parser_1.ExprOrContext) {
|
825
793
|
const all = [];
|
826
794
|
(0, select_columns_1.getTopLevelAndExpr)(expr, all);
|
827
795
|
all.forEach((andExpression) => {
|
@@ -904,8 +872,7 @@ function traversePredicate(predicate, traverseContext) {
|
|
904
872
|
const predicateOperations = predicate.predicateOperations();
|
905
873
|
if (predicateOperations) {
|
906
874
|
const rightType = traversePredicateOperations(predicateOperations, bitExprType, traverseContext);
|
907
|
-
if (bitExprType.kind === 'TypeOperator' &&
|
908
|
-
rightType.kind === 'TypeOperator') {
|
875
|
+
if (bitExprType.kind === 'TypeOperator' && rightType.kind === 'TypeOperator') {
|
909
876
|
rightType.types.forEach((t, i) => {
|
910
877
|
traverseContext.constraints.push({
|
911
878
|
expression: predicateOperations.getText(),
|
@@ -949,21 +916,15 @@ function traverseBitExpr(bitExpr, traverseContext) {
|
|
949
916
|
if (bitExpr.bitExpr_list().length === 2) {
|
950
917
|
const bitExprLeft = bitExpr.bitExpr(0);
|
951
918
|
const typeLeftTemp = traverseBitExpr(bitExprLeft, traverseContext);
|
952
|
-
const typeLeft = typeLeftTemp.kind === 'TypeOperator'
|
953
|
-
? typeLeftTemp.types[0]
|
954
|
-
: typeLeftTemp;
|
919
|
+
const typeLeft = typeLeftTemp.kind === 'TypeOperator' ? typeLeftTemp.types[0] : typeLeftTemp;
|
955
920
|
//const newTypeLeft = typeLeft.name == '?'? freshVar('?', 'bigint') : typeLeft;
|
956
921
|
const bitExprRight = bitExpr.bitExpr(1);
|
957
922
|
const typeRightTemp = traverseBitExpr(bitExprRight, traverseContext);
|
958
923
|
//In the expression 'id + (value + 2) + ?' the '(value+2)' is treated as a SimpleExprListContext and return a TypeOperator
|
959
|
-
const typeRight = typeRightTemp.kind === 'TypeOperator'
|
960
|
-
? typeRightTemp.types[0]
|
961
|
-
: typeRightTemp;
|
924
|
+
const typeRight = typeRightTemp.kind === 'TypeOperator' ? typeRightTemp.types[0] : typeRightTemp;
|
962
925
|
//const newTypeRight = typeRight.name == '?'? freshVar('?', 'bigint') : typeRight;
|
963
926
|
const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.getText(), '?');
|
964
|
-
if (typeLeftTemp.kind === 'TypeVar' &&
|
965
|
-
typeRightTemp.kind === 'TypeVar' &&
|
966
|
-
typeLeftTemp.table === typeRightTemp.table) {
|
927
|
+
if (typeLeftTemp.kind === 'TypeVar' && typeRightTemp.kind === 'TypeVar' && typeLeftTemp.table === typeRightTemp.table) {
|
967
928
|
bitExprType.table = typeLeftTemp.table;
|
968
929
|
}
|
969
930
|
//PRECISA?
|
@@ -1221,8 +1182,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1221
1182
|
type1: typeLeft,
|
1222
1183
|
type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
|
1223
1184
|
});
|
1224
|
-
if (typeRight.kind === 'TypeVar' &&
|
1225
|
-
((0, collect_constraints_1.isDateLiteral)(typeRight.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeRight.name))) {
|
1185
|
+
if (typeRight.kind === 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeRight.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeRight.name))) {
|
1226
1186
|
typeRight.type = 'datetime';
|
1227
1187
|
}
|
1228
1188
|
traverseContext.constraints.push({
|
@@ -1314,9 +1274,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1314
1274
|
});
|
1315
1275
|
return (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
1316
1276
|
}
|
1317
|
-
if (runtimeFunctionCall.YEAR_SYMBOL() ||
|
1318
|
-
runtimeFunctionCall.MONTH_SYMBOL() ||
|
1319
|
-
runtimeFunctionCall.DAY_SYMBOL()) {
|
1277
|
+
if (runtimeFunctionCall.YEAR_SYMBOL() || runtimeFunctionCall.MONTH_SYMBOL() || runtimeFunctionCall.DAY_SYMBOL()) {
|
1320
1278
|
const expr = (_g = runtimeFunctionCall.exprWithParentheses()) === null || _g === void 0 ? void 0 : _g.expr();
|
1321
1279
|
if (expr) {
|
1322
1280
|
const paramType = traverseExpr(expr, traverseContext);
|
@@ -1353,9 +1311,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1353
1311
|
}
|
1354
1312
|
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1355
1313
|
}
|
1356
|
-
if (runtimeFunctionCall.HOUR_SYMBOL() ||
|
1357
|
-
runtimeFunctionCall.MINUTE_SYMBOL() ||
|
1358
|
-
runtimeFunctionCall.SECOND_SYMBOL()) {
|
1314
|
+
if (runtimeFunctionCall.HOUR_SYMBOL() || runtimeFunctionCall.MINUTE_SYMBOL() || runtimeFunctionCall.SECOND_SYMBOL()) {
|
1359
1315
|
const expr = (_j = runtimeFunctionCall.exprWithParentheses()) === null || _j === void 0 ? void 0 : _j.expr();
|
1360
1316
|
if (expr) {
|
1361
1317
|
const paramType = traverseExpr(expr, traverseContext);
|
@@ -1428,8 +1384,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1428
1384
|
const expr2 = runtimeFunctionCall.expr(1);
|
1429
1385
|
const typeExpr1 = traverseExpr(expr1, traverseContext);
|
1430
1386
|
const typeExpr2 = traverseExpr(expr2, traverseContext);
|
1431
|
-
if (typeExpr1.kind === 'TypeVar' &&
|
1432
|
-
((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
|
1387
|
+
if (typeExpr1.kind === 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
|
1433
1388
|
typeExpr1.type = 'datetime';
|
1434
1389
|
}
|
1435
1390
|
traverseContext.constraints.push({
|
@@ -1445,8 +1400,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1445
1400
|
return (0, collect_constraints_1.freshVar)('datetime', 'datetime');
|
1446
1401
|
}
|
1447
1402
|
if (runtimeFunctionCall.COALESCE_SYMBOL()) {
|
1448
|
-
const exprList = (_k = runtimeFunctionCall
|
1449
|
-
.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
|
1403
|
+
const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
|
1450
1404
|
if (exprList) {
|
1451
1405
|
const paramType = (0, collect_constraints_1.freshVar)('COALESCE', 'any');
|
1452
1406
|
const params = {
|
@@ -1520,8 +1474,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1520
1474
|
}
|
1521
1475
|
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprFunctionContext) {
|
1522
1476
|
const functionIdentifier = (0, collect_constraints_1.getFunctionName)(simpleExpr);
|
1523
|
-
if (functionIdentifier === 'concat_ws' ||
|
1524
|
-
(functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
|
1477
|
+
if (functionIdentifier === 'concat_ws' || (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
|
1525
1478
|
const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'varchar');
|
1526
1479
|
const params = {
|
1527
1480
|
kind: 'VariableLengthParams',
|
@@ -1580,9 +1533,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1580
1533
|
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
|
1581
1534
|
}
|
1582
1535
|
if (functionIdentifier === 'datediff') {
|
1583
|
-
const udfExprList = (_l = simpleExpr
|
1584
|
-
.functionCall()
|
1585
|
-
.udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
|
1536
|
+
const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
|
1586
1537
|
if (udfExprList) {
|
1587
1538
|
udfExprList.forEach((inExpr) => {
|
1588
1539
|
const expr = inExpr.expr();
|
@@ -1598,11 +1549,8 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1598
1549
|
}
|
1599
1550
|
return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
|
1600
1551
|
}
|
1601
|
-
if (functionIdentifier === 'period_add' ||
|
1602
|
-
|
1603
|
-
const udfExprList = (_m = simpleExpr
|
1604
|
-
.functionCall()
|
1605
|
-
.udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
|
1552
|
+
if (functionIdentifier === 'period_add' || functionIdentifier === 'period_diff') {
|
1553
|
+
const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
|
1606
1554
|
if (udfExprList) {
|
1607
1555
|
udfExprList.forEach((inExpr) => {
|
1608
1556
|
const expr = inExpr.expr();
|
@@ -1642,8 +1590,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1642
1590
|
walkFunctionParameters(simpleExpr, params, traverseContext);
|
1643
1591
|
return varcharParam;
|
1644
1592
|
}
|
1645
|
-
if (functionIdentifier === 'length' ||
|
1646
|
-
functionIdentifier === 'char_length') {
|
1593
|
+
if (functionIdentifier === 'length' || functionIdentifier === 'char_length') {
|
1647
1594
|
const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
|
1648
1595
|
const params = {
|
1649
1596
|
kind: 'FixedLengthParams',
|
@@ -1654,9 +1601,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1654
1601
|
}
|
1655
1602
|
if (functionIdentifier === 'abs') {
|
1656
1603
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1657
|
-
const udfExprList = (_o = simpleExpr
|
1658
|
-
.functionCall()
|
1659
|
-
.udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
|
1604
|
+
const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
|
1660
1605
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach((expr) => {
|
1661
1606
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1662
1607
|
traverseContext.constraints.push({
|
@@ -1671,9 +1616,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1671
1616
|
}
|
1672
1617
|
if (functionIdentifier === 'ceiling' || functionIdentifier === 'ceil') {
|
1673
1618
|
const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
|
1674
|
-
const udfExprList = (_p = simpleExpr
|
1675
|
-
.functionCall()
|
1676
|
-
.udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
|
1619
|
+
const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
|
1677
1620
|
udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach((expr) => {
|
1678
1621
|
const param1 = traverseExpr(expr.expr(), traverseContext);
|
1679
1622
|
traverseContext.constraints.push({
|
@@ -1687,9 +1630,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1687
1630
|
return functionType;
|
1688
1631
|
}
|
1689
1632
|
if (functionIdentifier === 'timestampdiff') {
|
1690
|
-
const udfExprList = (_q = simpleExpr
|
1691
|
-
.functionCall()
|
1692
|
-
.udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
|
1633
|
+
const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
|
1693
1634
|
if (udfExprList) {
|
1694
1635
|
const [first, ...rest] = udfExprList;
|
1695
1636
|
const unit = first.getText().trim().toLowerCase();
|
@@ -1710,9 +1651,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1710
1651
|
}
|
1711
1652
|
if (functionIdentifier === 'ifnull' || functionIdentifier === 'nullif') {
|
1712
1653
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
|
1713
|
-
const udfExprList = (_r = simpleExpr
|
1714
|
-
.functionCall()
|
1715
|
-
.udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
|
1654
|
+
const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
|
1716
1655
|
if (udfExprList) {
|
1717
1656
|
const [expr1, expr2] = udfExprList;
|
1718
1657
|
const expr1Type = traverseExpr(expr1.expr(), traverseContext);
|
@@ -1735,9 +1674,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
|
|
1735
1674
|
functionIdentifier === 'unhex') {
|
1736
1675
|
//unhex (str) - TODO - have input constraint = string
|
1737
1676
|
const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'char');
|
1738
|
-
const udfExprList = (_s = simpleExpr
|
1739
|
-
.functionCall()
|
1740
|
-
.udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
|
1677
|
+
const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
|
1741
1678
|
if (udfExprList) {
|
1742
1679
|
const [expr1] = udfExprList;
|
1743
1680
|
const paramType = traverseExpr(expr1.expr(), traverseContext);
|
@@ -1785,9 +1722,7 @@ function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
|
|
1785
1722
|
function traverseExprListParameters(exprList, params, traverseContext) {
|
1786
1723
|
return exprList.map((expr, paramIndex) => {
|
1787
1724
|
const exprType = traverseExpr(expr, traverseContext);
|
1788
|
-
const paramType = params.kind === 'FixedLengthParams'
|
1789
|
-
? params.paramsType[paramIndex]
|
1790
|
-
: (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
|
1725
|
+
const paramType = params.kind === 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
|
1791
1726
|
traverseContext.constraints.push({
|
1792
1727
|
expression: expr.getText(),
|
1793
1728
|
type1: exprType,
|
@@ -1800,9 +1735,7 @@ function traverseExprListParameters(exprList, params, traverseContext) {
|
|
1800
1735
|
function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
1801
1736
|
var _a, _b;
|
1802
1737
|
const functionName = (0, collect_constraints_1.getFunctionName)(simpleExprFunction);
|
1803
|
-
const udfExprList = (_a = simpleExprFunction
|
1804
|
-
.functionCall()
|
1805
|
-
.udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
|
1738
|
+
const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
|
1806
1739
|
if (udfExprList) {
|
1807
1740
|
const paramTypes = udfExprList
|
1808
1741
|
.filter((_, paramIndex) => {
|
@@ -1814,9 +1747,7 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1814
1747
|
traverseContext.constraints.push({
|
1815
1748
|
expression: expr.getText(),
|
1816
1749
|
type1: exprType,
|
1817
|
-
type2: params.kind === 'FixedLengthParams'
|
1818
|
-
? params.paramsType[paramIndex]
|
1819
|
-
: (0, collect_constraints_1.freshVar)(params.paramType, params.paramType)
|
1750
|
+
type2: params.kind === 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType)
|
1820
1751
|
});
|
1821
1752
|
return exprType;
|
1822
1753
|
});
|
@@ -1828,9 +1759,7 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
|
|
1828
1759
|
const inSumExprType = traverseExpr(inExpr, traverseContext);
|
1829
1760
|
traverseContext.constraints.push({
|
1830
1761
|
expression: inExpr.getText(),
|
1831
|
-
type1: params.kind === 'FixedLengthParams'
|
1832
|
-
? params.paramsType[paramIndex]
|
1833
|
-
: (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1762
|
+
type1: params.kind === 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
|
1834
1763
|
type2: inSumExprType,
|
1835
1764
|
mostGeneralType: true
|
1836
1765
|
});
|
@@ -1845,8 +1774,7 @@ function filterColumns(dbSchema, withSchema, tableAlias, table) {
|
|
1845
1774
|
.filter((t) => t.table.toLowerCase() === table.name.toLowerCase())
|
1846
1775
|
.map((s) => (Object.assign(Object.assign({}, s), { tableAlias: tableAlias })));
|
1847
1776
|
const tableColumns1 = dbSchema
|
1848
|
-
.filter((schema) => schema.table.toLowerCase() === table.name.toLowerCase() &&
|
1849
|
-
(schema.schema === table.prefix || table.prefix === ''))
|
1777
|
+
.filter((schema) => schema.table.toLowerCase() === table.name.toLowerCase() && (schema.schema === table.prefix || table.prefix === ''))
|
1850
1778
|
.map((tableColumn) => {
|
1851
1779
|
//name and colum are the same on the leaf table
|
1852
1780
|
const r = {
|
@@ -1862,18 +1790,14 @@ function filterColumns(dbSchema, withSchema, tableAlias, table) {
|
|
1862
1790
|
const result = tableColumns1.concat(withResult);
|
1863
1791
|
return result;
|
1864
1792
|
}
|
1865
|
-
exports.filterColumns = filterColumns;
|
1866
1793
|
function selectAllColumns(tablePrefix, fromColumns) {
|
1867
1794
|
return fromColumns.filter((column) => {
|
1868
|
-
if (tablePrefix === '' ||
|
1869
|
-
tablePrefix === column.tableAlias ||
|
1870
|
-
tablePrefix === column.table) {
|
1795
|
+
if (tablePrefix === '' || tablePrefix === column.tableAlias || tablePrefix === column.table) {
|
1871
1796
|
return true;
|
1872
1797
|
}
|
1873
1798
|
return false;
|
1874
1799
|
});
|
1875
1800
|
}
|
1876
|
-
exports.selectAllColumns = selectAllColumns;
|
1877
1801
|
function filterUsingFields(joinedFields, usingFields) {
|
1878
1802
|
return joinedFields.filter((joinedField) => {
|
1879
1803
|
const isUsing = usingFields.includes(joinedField.columnName);
|
@@ -1896,7 +1820,7 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1896
1820
|
return false;
|
1897
1821
|
}
|
1898
1822
|
if (querySpecs[0].selectItemList().getChildCount() === 1) {
|
1899
|
-
const selectItem =
|
1823
|
+
const selectItem = querySpecs[0].selectItemList().getChild(0);
|
1900
1824
|
//if selectItem = * (TerminalNode) childCount = 0; selectItem.expr() throws exception
|
1901
1825
|
const expr = selectItem.getChildCount() > 0 ? selectItem.expr() : null;
|
1902
1826
|
if (expr) {
|
@@ -1907,8 +1831,7 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1907
1831
|
}
|
1908
1832
|
}
|
1909
1833
|
}
|
1910
|
-
const joinedTable = (_a = fromClause
|
1911
|
-
.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
|
1834
|
+
const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
|
1912
1835
|
if (joinedTable && joinedTable.length > 0) {
|
1913
1836
|
return true;
|
1914
1837
|
}
|
@@ -1920,7 +1843,6 @@ function isMultipleRowResult(selectStatement, fromColumns) {
|
|
1920
1843
|
}
|
1921
1844
|
return true;
|
1922
1845
|
}
|
1923
|
-
exports.isMultipleRowResult = isMultipleRowResult;
|
1924
1846
|
function isLimitOne(selectStatement) {
|
1925
1847
|
const limitOptions = (0, parse_1.getLimitOptions)(selectStatement);
|
1926
1848
|
if (limitOptions.length === 1 && limitOptions[0].getText() === '1') {
|
@@ -1938,8 +1860,7 @@ function verifyMultipleResult2(exprContext, fromColumns) {
|
|
1938
1860
|
if (boolPri.compOp().EQUAL_OPERATOR()) {
|
1939
1861
|
const compareLeft = boolPri.boolPri();
|
1940
1862
|
const compareRight = boolPri.predicate();
|
1941
|
-
if (isUniqueKeyComparation(compareLeft, fromColumns) ||
|
1942
|
-
isUniqueKeyComparation(compareRight, fromColumns)) {
|
1863
|
+
if (isUniqueKeyComparation(compareLeft, fromColumns) || isUniqueKeyComparation(compareRight, fromColumns)) {
|
1943
1864
|
return false; //multipleRow = false
|
1944
1865
|
}
|
1945
1866
|
}
|
@@ -1951,9 +1872,7 @@ function verifyMultipleResult2(exprContext, fromColumns) {
|
|
1951
1872
|
return true;
|
1952
1873
|
}
|
1953
1874
|
if (exprContext instanceof ts_mysql_parser_1.ExprAndContext) {
|
1954
|
-
const oneIsSingleResult = exprContext
|
1955
|
-
.expr_list()
|
1956
|
-
.some((expr) => verifyMultipleResult2(expr, fromColumns) === false);
|
1875
|
+
const oneIsSingleResult = exprContext.expr_list().some((expr) => verifyMultipleResult2(expr, fromColumns) === false);
|
1957
1876
|
return oneIsSingleResult === false;
|
1958
1877
|
}
|
1959
1878
|
// if (exprContext instanceof ExprXorContext) {
|
@@ -1964,7 +1883,6 @@ function verifyMultipleResult2(exprContext, fromColumns) {
|
|
1964
1883
|
}
|
1965
1884
|
throw Error(`Unknow type:${exprContext.constructor.name}`);
|
1966
1885
|
}
|
1967
|
-
exports.verifyMultipleResult2 = verifyMultipleResult2;
|
1968
1886
|
function isUniqueKeyComparation(compare, fromColumns) {
|
1969
1887
|
const tokens = (0, select_columns_1.getSimpleExpressions)(compare);
|
1970
1888
|
if (tokens.length === 1 && tokens[0] instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
|
@@ -2005,7 +1923,6 @@ function getOrderByColumns(fromColumns, selectColumns) {
|
|
2005
1923
|
});
|
2006
1924
|
return orderByColumns;
|
2007
1925
|
}
|
2008
|
-
exports.getOrderByColumns = getOrderByColumns;
|
2009
1926
|
function isAmbiguous(columns, columnName) {
|
2010
1927
|
const filterByName = columns.filter((col) => col.columnName === columnName);
|
2011
1928
|
return filterByName.length > 1;
|