typesql-cli 0.9.6 → 0.10.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.
Files changed (110) hide show
  1. package/README.md +2 -3
  2. package/cli.js +87 -78
  3. package/cli.js.map +1 -1
  4. package/code-generator.d.ts +7 -7
  5. package/code-generator.d.ts.map +1 -1
  6. package/code-generator.js +257 -193
  7. package/code-generator.js.map +1 -1
  8. package/describe-dynamic-query.d.ts +1 -1
  9. package/describe-dynamic-query.d.ts.map +1 -1
  10. package/describe-dynamic-query.js +51 -39
  11. package/describe-dynamic-query.js.map +1 -1
  12. package/describe-nested-query.d.ts +2 -2
  13. package/describe-nested-query.d.ts.map +1 -1
  14. package/describe-nested-query.js +43 -24
  15. package/describe-nested-query.js.map +1 -1
  16. package/describe-query.d.ts +4 -4
  17. package/describe-query.d.ts.map +1 -1
  18. package/describe-query.js +29 -21
  19. package/describe-query.js.map +1 -1
  20. package/drivers/libsql.d.ts +2 -2
  21. package/drivers/libsql.d.ts.map +1 -1
  22. package/drivers/libsql.js +3 -3
  23. package/drivers/libsql.js.map +1 -1
  24. package/mysql-mapping.d.ts +1 -1
  25. package/mysql-mapping.d.ts.map +1 -1
  26. package/mysql-mapping.js +9 -9
  27. package/mysql-mapping.js.map +1 -1
  28. package/mysql-query-analyzer/collect-constraints.d.ts +4 -4
  29. package/mysql-query-analyzer/collect-constraints.d.ts.map +1 -1
  30. package/mysql-query-analyzer/collect-constraints.js +21 -16
  31. package/mysql-query-analyzer/collect-constraints.js.map +1 -1
  32. package/mysql-query-analyzer/infer-column-nullability.d.ts +2 -2
  33. package/mysql-query-analyzer/infer-column-nullability.d.ts.map +1 -1
  34. package/mysql-query-analyzer/infer-column-nullability.js +81 -67
  35. package/mysql-query-analyzer/infer-column-nullability.js.map +1 -1
  36. package/mysql-query-analyzer/infer-param-nullability.d.ts +2 -2
  37. package/mysql-query-analyzer/infer-param-nullability.d.ts.map +1 -1
  38. package/mysql-query-analyzer/infer-param-nullability.js +11 -10
  39. package/mysql-query-analyzer/infer-param-nullability.js.map +1 -1
  40. package/mysql-query-analyzer/parse.d.ts +2 -2
  41. package/mysql-query-analyzer/parse.d.ts.map +1 -1
  42. package/mysql-query-analyzer/parse.js +39 -32
  43. package/mysql-query-analyzer/parse.js.map +1 -1
  44. package/mysql-query-analyzer/select-columns.d.ts +4 -4
  45. package/mysql-query-analyzer/select-columns.d.ts.map +1 -1
  46. package/mysql-query-analyzer/select-columns.js +76 -53
  47. package/mysql-query-analyzer/select-columns.js.map +1 -1
  48. package/mysql-query-analyzer/traverse.d.ts +4 -4
  49. package/mysql-query-analyzer/traverse.d.ts.map +1 -1
  50. package/mysql-query-analyzer/traverse.js +312 -206
  51. package/mysql-query-analyzer/traverse.js.map +1 -1
  52. package/mysql-query-analyzer/types.d.ts +5 -5
  53. package/mysql-query-analyzer/types.d.ts.map +1 -1
  54. package/mysql-query-analyzer/unify.d.ts +2 -2
  55. package/mysql-query-analyzer/unify.d.ts.map +1 -1
  56. package/mysql-query-analyzer/unify.js +533 -491
  57. package/mysql-query-analyzer/unify.js.map +1 -1
  58. package/mysql-query-analyzer/util.d.ts.map +1 -1
  59. package/mysql-query-analyzer/util.js +2 -3
  60. package/mysql-query-analyzer/util.js.map +1 -1
  61. package/mysql-query-analyzer/verify-multiple-result.d.ts +2 -2
  62. package/mysql-query-analyzer/verify-multiple-result.d.ts.map +1 -1
  63. package/mysql-query-analyzer/verify-multiple-result.js +12 -8
  64. package/mysql-query-analyzer/verify-multiple-result.js.map +1 -1
  65. package/package.json +46 -45
  66. package/queryExectutor.d.ts +4 -4
  67. package/queryExectutor.d.ts.map +1 -1
  68. package/queryExectutor.js +11 -13
  69. package/queryExectutor.js.map +1 -1
  70. package/sql-generator.d.ts +2 -2
  71. package/sql-generator.d.ts.map +1 -1
  72. package/sql-generator.js +29 -25
  73. package/sql-generator.js.map +1 -1
  74. package/sqlite-query-analyzer/code-generator.d.ts +5 -5
  75. package/sqlite-query-analyzer/code-generator.d.ts.map +1 -1
  76. package/sqlite-query-analyzer/code-generator.js +372 -221
  77. package/sqlite-query-analyzer/code-generator.js.map +1 -1
  78. package/sqlite-query-analyzer/parser.d.ts +4 -4
  79. package/sqlite-query-analyzer/parser.d.ts.map +1 -1
  80. package/sqlite-query-analyzer/parser.js +30 -17
  81. package/sqlite-query-analyzer/parser.js.map +1 -1
  82. package/sqlite-query-analyzer/query-executor.d.ts +5 -5
  83. package/sqlite-query-analyzer/query-executor.d.ts.map +1 -1
  84. package/sqlite-query-analyzer/query-executor.js +39 -25
  85. package/sqlite-query-analyzer/query-executor.js.map +1 -1
  86. package/sqlite-query-analyzer/replace-list-params.d.ts +1 -1
  87. package/sqlite-query-analyzer/replace-list-params.d.ts.map +1 -1
  88. package/sqlite-query-analyzer/replace-list-params.js +4 -3
  89. package/sqlite-query-analyzer/replace-list-params.js.map +1 -1
  90. package/sqlite-query-analyzer/sqlite-describe-nested-query.d.ts +4 -4
  91. package/sqlite-query-analyzer/sqlite-describe-nested-query.d.ts.map +1 -1
  92. package/sqlite-query-analyzer/sqlite-describe-nested-query.js +33 -18
  93. package/sqlite-query-analyzer/sqlite-describe-nested-query.js.map +1 -1
  94. package/sqlite-query-analyzer/traverse.d.ts +5 -5
  95. package/sqlite-query-analyzer/traverse.d.ts.map +1 -1
  96. package/sqlite-query-analyzer/traverse.js +249 -160
  97. package/sqlite-query-analyzer/traverse.js.map +1 -1
  98. package/ts-dynamic-query-descriptor.d.ts +1 -1
  99. package/ts-dynamic-query-descriptor.d.ts.map +1 -1
  100. package/ts-dynamic-query-descriptor.js +4 -4
  101. package/ts-dynamic-query-descriptor.js.map +1 -1
  102. package/ts-nested-descriptor.d.ts +4 -4
  103. package/ts-nested-descriptor.d.ts.map +1 -1
  104. package/ts-nested-descriptor.js +11 -11
  105. package/ts-nested-descriptor.js.map +1 -1
  106. package/types.d.ts +13 -14
  107. package/types.d.ts.map +1 -1
  108. package/util.d.ts.map +1 -1
  109. package/util.js.map +1 -1
  110. package/utility-types.d.ts.map +1 -1
@@ -55,7 +55,7 @@ function traverseQueryContext(queryContext, dbSchema, namedParameters) {
55
55
  const typeInfer = traverseDeleteStatement(deleteStatement, traverseContext);
56
56
  return typeInfer;
57
57
  }
58
- throw Error('traverseSql - not supported: ' + queryContext.constructor.name);
58
+ throw Error(`traverseSql - not supported: ${queryContext.constructor.name}`);
59
59
  }
60
60
  exports.traverseQueryContext = traverseQueryContext;
61
61
  function traverseSelectStatement(selectStatement, traverseContext, namedParameters) {
@@ -65,14 +65,14 @@ function traverseSelectStatement(selectStatement, traverseContext, namedParamete
65
65
  const orderByParameters = (0, parse_1.extractOrderByParameters)(selectStatement);
66
66
  const limitParameters = (0, parse_1.extractLimitParameters)(selectStatement);
67
67
  const paramInference = (0, infer_param_nullability_1.inferParamNullabilityQueryExpression)(queryExpression);
68
- const allParameters = traverseContext.parameters
69
- .map((param, index) => {
68
+ const allParameters = traverseContext.parameters.map((param, index) => {
70
69
  const param2 = Object.assign(Object.assign({}, param), { notNull: paramInference[index] });
71
70
  return param2;
72
71
  });
73
72
  const paramIndexes = (0, util_1.getParameterIndexes)(namedParameters.slice(0, allParameters.length)); //for [a, a, b, a] will return a: [0, 1, 3]; b: [2]
74
- paramIndexes.forEach(paramIndex => {
73
+ paramIndexes.forEach((paramIndex) => {
75
74
  (0, util_1.getPairWise)(paramIndex.indexes, (cur, next) => {
75
+ //for [0, 1, 3] will return [0, 1], [1, 3]
76
76
  traverseContext.constraints.push({
77
77
  expression: paramIndex.paramName,
78
78
  type1: allParameters[cur].type,
@@ -90,27 +90,34 @@ function traverseSelectStatement(selectStatement, traverseContext, namedParamete
90
90
  isMultiRow,
91
91
  dynamicSqlInfo: traverseContext.dynamicSqlInfo
92
92
  };
93
- const orderByColumns = orderByParameters.length > 0 ? getOrderByColumns(result.fromColumns, result.columns) : undefined;
93
+ const orderByColumns = orderByParameters.length > 0
94
+ ? getOrderByColumns(result.fromColumns, result.columns)
95
+ : undefined;
94
96
  if (orderByColumns) {
95
97
  traverseResult.orderByColumns = orderByColumns;
96
98
  }
97
99
  return traverseResult;
98
100
  }
99
- throw Error('traverseSelectStatement - not supported: ' + selectStatement.getText());
101
+ throw Error(`traverseSelectStatement - not supported: ${selectStatement.getText()}`);
100
102
  }
101
103
  function traverseInsertStatement(insertStatement, traverseContext) {
102
104
  var _a, _b;
103
105
  const allParameters = [];
104
106
  const paramsNullability = {};
105
107
  let exprOrDefaultList = [];
106
- const valuesContext = (_a = insertStatement.insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().values_list();
108
+ const valuesContext = (_a = insertStatement
109
+ .insertFromConstructor()) === null || _a === void 0 ? void 0 : _a.insertValues().valueList().values_list();
107
110
  if (valuesContext) {
108
- exprOrDefaultList = valuesContext.map(valueContext => { var _a; return ((_a = valueContext.children) === null || _a === void 0 ? void 0 : _a.filter(valueContext => valueContext instanceof ts_mysql_parser_1.ExprIsContext || valueContext.getText() == 'DEFAULT')) || []; });
111
+ exprOrDefaultList = valuesContext.map((valueContext) => {
112
+ 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')) || [];
115
+ });
109
116
  }
110
117
  const insertIntoTable = (0, collect_constraints_1.getInsertIntoTable)(insertStatement);
111
118
  const fromColumns = traverseContext.dbSchema
112
- .filter(c => c.table == insertIntoTable)
113
- .map(c => {
119
+ .filter((c) => c.table === insertIntoTable)
120
+ .map((c) => {
114
121
  const col = {
115
122
  table: c.table,
116
123
  columnName: c.column,
@@ -122,20 +129,23 @@ function traverseInsertStatement(insertStatement, traverseContext) {
122
129
  });
123
130
  const insertColumns = (0, collect_constraints_1.getInsertColumns)(insertStatement, fromColumns);
124
131
  traverseContext.fromColumns = insertColumns;
125
- exprOrDefaultList.forEach(exprOrDefault => {
132
+ exprOrDefaultList.forEach((exprOrDefault) => {
126
133
  exprOrDefault.forEach((expr, index) => {
127
134
  const column = insertColumns[index];
128
135
  if (expr instanceof ts_mysql_parser_1.ExprContext) {
129
136
  const numberParamsBefore = traverseContext.parameters.length;
130
137
  const exprType = traverseExpr(expr, traverseContext);
131
138
  const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullability)(expr);
132
- traverseContext.parameters.slice(numberParamsBefore).forEach(param => {
133
- paramsNullability[param.type.id] = paramNullabilityExpr.every(n => n) && column.notNull;
139
+ traverseContext.parameters
140
+ .slice(numberParamsBefore)
141
+ .forEach((param) => {
142
+ paramsNullability[param.type.id] =
143
+ paramNullabilityExpr.every((n) => n) && column.notNull;
134
144
  });
135
145
  traverseContext.constraints.push({
136
146
  expression: expr.getText(),
137
147
  //TODO - CHANGING ORDER SHOULDN'T AFFECT THE TYPE INFERENCE
138
- type1: exprType.kind == 'TypeOperator' ? exprType.types[0] : exprType,
148
+ type1: exprType.kind === 'TypeOperator' ? exprType.types[0] : exprType,
139
149
  type2: (0, collect_constraints_1.freshVar)(column.columnName, column.columnType.type)
140
150
  });
141
151
  }
@@ -144,7 +154,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
144
154
  });
145
155
  });
146
156
  const updateList = ((_b = insertStatement.insertUpdateList()) === null || _b === void 0 ? void 0 : _b.updateList().updateElement_list()) || [];
147
- updateList.forEach(updateElement => {
157
+ updateList.forEach((updateElement) => {
148
158
  const columnName = updateElement.columnRef().getText();
149
159
  const field = (0, select_columns_1.splitName)(columnName);
150
160
  const expr = updateElement.expr();
@@ -152,7 +162,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
152
162
  const numberParamsBefore = traverseContext.parameters.length;
153
163
  const exprType = traverseExpr(expr, traverseContext);
154
164
  const column = (0, select_columns_1.findColumn)(field, fromColumns);
155
- traverseContext.parameters.slice(numberParamsBefore).forEach(param => {
165
+ traverseContext.parameters.slice(numberParamsBefore).forEach((param) => {
156
166
  paramsNullability[param.type.id] = column.notNull;
157
167
  });
158
168
  traverseContext.constraints.push({
@@ -169,7 +179,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
169
179
  const exprTypes = traverseInsertQueryExpression(insertQueryExpression, traverseContext);
170
180
  exprTypes.columns.forEach((type, index) => {
171
181
  const column = insertColumns[index];
172
- if (type.type.kind == 'TypeVar') {
182
+ if (type.type.kind === 'TypeVar') {
173
183
  paramsNullability[type.type.id] = column.notNull;
174
184
  }
175
185
  traverseContext.constraints.push({
@@ -179,7 +189,9 @@ function traverseInsertStatement(insertStatement, traverseContext) {
179
189
  });
180
190
  });
181
191
  const paramNullabilityExpr = (0, infer_param_nullability_1.inferParamNullabilityQuery)(insertQueryExpression);
182
- traverseContext.parameters.slice(numberParamsBefore).forEach((param, index) => {
192
+ traverseContext.parameters
193
+ .slice(numberParamsBefore)
194
+ .forEach((param, index) => {
183
195
  if (paramsNullability[param.type.id] == null) {
184
196
  paramsNullability[param.type.id] = paramNullabilityExpr[index];
185
197
  }
@@ -189,7 +201,7 @@ function traverseInsertStatement(insertStatement, traverseContext) {
189
201
  typeInfo.forEach((param, index) => {
190
202
  const paramId = traverseContext.parameters[index].type.id;
191
203
  allParameters.push({
192
- name: 'param' + (allParameters.length + 1),
204
+ name: `param${allParameters.length + 1}`,
193
205
  columnType: (0, describe_query_1.verifyNotInferred)(param),
194
206
  notNull: paramsNullability[paramId]
195
207
  });
@@ -217,7 +229,7 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
217
229
  const paramsBefore = traverseContext.parameters.length;
218
230
  const whereExpr = (_a = updateStatement.whereClause()) === null || _a === void 0 ? void 0 : _a.expr();
219
231
  const paramNullability = (0, infer_param_nullability_1.inferParamNullability)(updateStatement);
220
- updateElement.forEach(updateElement => {
232
+ updateElement.forEach((updateElement) => {
221
233
  const expr = updateElement.expr();
222
234
  if (expr) {
223
235
  const paramBeforeExpr = traverseContext.parameters.length;
@@ -230,7 +242,9 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
230
242
  type1: result,
231
243
  type2: column.columnType //freshVar(column.columnName, )
232
244
  });
233
- traverseContext.parameters.slice(paramBeforeExpr, traverseContext.parameters.length).forEach((param, index) => {
245
+ traverseContext.parameters
246
+ .slice(paramBeforeExpr, traverseContext.parameters.length)
247
+ .forEach((param, index) => {
234
248
  dataTypes.push({
235
249
  name: namedParamters[paramBeforeExpr + index] || field.name,
236
250
  type: param.type,
@@ -246,7 +260,7 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
246
260
  }
247
261
  traverseContext.parameters.slice(0, paramsBefore).forEach((param, index) => {
248
262
  whereParameters.push({
249
- name: namedParamters[index] || 'param' + (whereParameters.length + 1),
263
+ name: namedParamters[index] || `param${whereParameters.length + 1}`,
250
264
  type: param.type,
251
265
  notNull: paramNullability[index],
252
266
  table: ''
@@ -254,7 +268,8 @@ function traverseUpdateStatement(updateStatement, traverseContext, namedParamter
254
268
  });
255
269
  traverseContext.parameters.slice(paramsAfter).forEach((param, index) => {
256
270
  whereParameters.push({
257
- name: namedParamters[paramsAfter + index] || 'param' + (whereParameters.length + 1),
271
+ name: namedParamters[paramsAfter + index] ||
272
+ `param${whereParameters.length + 1}`,
258
273
  type: param.type,
259
274
  notNull: paramNullability[paramsAfter + index],
260
275
  table: ''
@@ -280,7 +295,7 @@ function traverseDeleteStatement(deleteStatement, traverseContext) {
280
295
  const paramNullability = (0, infer_param_nullability_1.inferParamNullability)(whereExpr);
281
296
  typeInfo.forEach((param, paramIndex) => {
282
297
  allParameters.push({
283
- name: 'param' + (allParameters.length + 1),
298
+ name: `param${allParameters.length + 1}`,
284
299
  columnType: (0, describe_query_1.verifyNotInferred)(param),
285
300
  notNull: paramNullability[paramIndex]
286
301
  });
@@ -295,7 +310,9 @@ function traverseDeleteStatement(deleteStatement, traverseContext) {
295
310
  }
296
311
  exports.traverseDeleteStatement = traverseDeleteStatement;
297
312
  function getUpdateColumns(updateStatement, traverseContext) {
298
- const tableReferences = updateStatement.tableReferenceList().tableReference_list();
313
+ const tableReferences = updateStatement
314
+ .tableReferenceList()
315
+ .tableReference_list();
299
316
  const columns = traverseTableReferenceList(tableReferences, traverseContext, null);
300
317
  return columns;
301
318
  }
@@ -313,7 +330,7 @@ function traverseQueryExpressionOrParens(queryExpressionOrParens, traverseContex
313
330
  if (queryEpressionParens) {
314
331
  return traverseQueryExpressionParens(queryEpressionParens, traverseContext);
315
332
  }
316
- throw Error("walkQueryExpressionOrParens");
333
+ throw Error('walkQueryExpressionOrParens');
317
334
  }
318
335
  function traverseQueryExpression(queryExpression, traverseContext, cte, recursiveNames) {
319
336
  const withClause = queryExpression.withClause();
@@ -332,7 +349,10 @@ function traverseQueryExpression(queryExpression, traverseContext, cte, recursiv
332
349
  const orderByClause = queryExpression.orderClause();
333
350
  if (orderByClause) {
334
351
  if (orderByClause.getText().toLowerCase() !== 'orderby?') {
335
- orderByClause.orderList().orderExpression_list().forEach(orderByExpr => {
352
+ orderByClause
353
+ .orderList()
354
+ .orderExpression_list()
355
+ .forEach((orderByExpr) => {
336
356
  traverseExpr(orderByExpr.expr(), Object.assign(Object.assign({}, traverseContext), { fromColumns: exprResult.fromColumns || [] }));
337
357
  });
338
358
  }
@@ -348,7 +368,7 @@ function traverseQueryExpressionParens(queryExpressionParens, traverseContext, c
348
368
  if (queryExpressionParens2) {
349
369
  return traverseQueryExpressionParens(queryExpressionParens, traverseContext, cte, recursiveNames);
350
370
  }
351
- throw Error("walkQueryExpressionParens");
371
+ throw Error('walkQueryExpressionParens');
352
372
  }
353
373
  function createUnionVar(type, name) {
354
374
  const newVar = Object.assign(Object.assign({}, type), { name: name, table: '' });
@@ -358,26 +378,36 @@ function traverseQueryExpressionBody(queryExpressionBody, traverseContext, cte,
358
378
  const allQueries = (0, parse_1.getAllQuerySpecificationsFromSelectStatement)(queryExpressionBody);
359
379
  const [first, ...unionQuerySpec] = allQueries;
360
380
  const mainQueryResult = traverseQuerySpecification(first, traverseContext);
361
- const resultTypes = mainQueryResult.columns.map((t, index) => unionQuerySpec.length == 0 ? t.type : createUnionVar(t.type, recursiveNames && recursiveNames.length > 0 ? recursiveNames[index] : t.name)); //TODO mover para traversequeryspecificat?
381
+ const resultTypes = mainQueryResult.columns.map((t, index) => unionQuerySpec.length === 0
382
+ ? t.type
383
+ : createUnionVar(t.type, recursiveNames && recursiveNames.length > 0
384
+ ? recursiveNames[index]
385
+ : t.name)); //TODO mover para traversequeryspecificat?
362
386
  if (cte) {
363
387
  resultTypes.forEach((col, index) => {
364
388
  const withCol = {
365
389
  table: cte,
366
390
  columnName: col.name,
367
391
  columnType: col,
368
- columnKey: "",
392
+ columnKey: '',
369
393
  notNull: mainQueryResult.columns[index].notNull
370
394
  };
371
395
  traverseContext.withSchema.push(withCol);
372
396
  });
373
397
  }
374
398
  for (let queryIndex = 0; queryIndex < unionQuerySpec.length; queryIndex++) {
375
- const columnNames = recursiveNames && recursiveNames.length > 0 ? recursiveNames : mainQueryResult.columns.map(col => col.name);
376
- const newFromColumns = recursiveNames ? renameFromColumns(mainQueryResult.columns, columnNames) : [];
399
+ const columnNames = recursiveNames && recursiveNames.length > 0
400
+ ? recursiveNames
401
+ : mainQueryResult.columns.map((col) => col.name);
402
+ const newFromColumns = recursiveNames
403
+ ? renameFromColumns(mainQueryResult.columns, columnNames)
404
+ : [];
377
405
  const unionQuery = unionQuerySpec[queryIndex];
378
406
  const unionResult = traverseQuerySpecification(unionQuery, Object.assign(Object.assign({}, traverseContext), { fromColumns: newFromColumns }));
379
407
  resultTypes.forEach((t2, index) => {
380
- mainQueryResult.columns[index].notNull = mainQueryResult.columns[index].notNull && unionResult.columns[index].notNull;
408
+ mainQueryResult.columns[index].notNull =
409
+ mainQueryResult.columns[index].notNull &&
410
+ unionResult.columns[index].notNull;
381
411
  traverseContext.constraints.push({
382
412
  expression: 'union',
383
413
  coercionType: 'Union',
@@ -405,10 +435,10 @@ function traverseQueryExpressionBody(queryExpressionBody, traverseContext, cte,
405
435
  function renameFromColumns(fromColumns, recursiveNames) {
406
436
  const newFromColumns = fromColumns.map((col, index) => {
407
437
  const newCol = {
408
- table: "",
438
+ table: '',
409
439
  columnName: recursiveNames[index],
410
440
  columnType: col.type,
411
- columnKey: "",
441
+ columnKey: '',
412
442
  notNull: col.notNull
413
443
  };
414
444
  return newCol;
@@ -417,8 +447,12 @@ function renameFromColumns(fromColumns, recursiveNames) {
417
447
  }
418
448
  function traverseQuerySpecification(querySpec, traverseContext) {
419
449
  const fromClause = querySpec.fromClause();
420
- const fromColumnsFrom = fromClause ? traverseFromClause(fromClause, traverseContext) : [];
421
- const allColumns = traverseContext.subQuery ? traverseContext.fromColumns.concat(fromColumnsFrom) : fromColumnsFrom; //(... where id = t1.id)
450
+ const fromColumnsFrom = fromClause
451
+ ? traverseFromClause(fromClause, traverseContext)
452
+ : [];
453
+ const allColumns = traverseContext.subQuery
454
+ ? traverseContext.fromColumns.concat(fromColumnsFrom)
455
+ : fromColumnsFrom; //(... where id = t1.id)
422
456
  const selectItemListResult = traverseSelectItemList(querySpec.selectItemList(), Object.assign(Object.assign({}, traverseContext), { fromColumns: allColumns, subQueryColumns: fromColumnsFrom }));
423
457
  const whereClause = querySpec.whereClause();
424
458
  //TODO - HAVING, BLAH
@@ -438,12 +472,12 @@ function traverseQuerySpecification(querySpec, traverseContext) {
438
472
  });
439
473
  const havingClause = querySpec.havingClause();
440
474
  if (havingClause) {
441
- const selectColumns = columns.map(c => {
475
+ const selectColumns = columns.map((c) => {
442
476
  const col = {
443
- table: "",
477
+ table: '',
444
478
  columnName: c.name,
445
479
  columnType: c.type,
446
- columnKey: "",
480
+ columnKey: '',
447
481
  notNull: c.notNull
448
482
  };
449
483
  return col;
@@ -458,14 +492,17 @@ function traverseQuerySpecification(querySpec, traverseContext) {
458
492
  exports.traverseQuerySpecification = traverseQuerySpecification;
459
493
  function traverseWithClause(withClause, traverseContext) {
460
494
  //result1, result2
461
- withClause.commonTableExpression_list().forEach(commonTableExpression => {
495
+ withClause.commonTableExpression_list().forEach((commonTableExpression) => {
462
496
  var _a, _b;
463
497
  const cte = commonTableExpression.identifier().getText();
464
- const recursiveNames = withClause.RECURSIVE_SYMBOL() ? ((_a = commonTableExpression.columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.columnInternalRef_list().map(t => t.getText())) || [] : undefined;
498
+ const recursiveNames = withClause.RECURSIVE_SYMBOL()
499
+ ? ((_a = commonTableExpression
500
+ .columnInternalRefList()) === null || _a === void 0 ? void 0 : _a.columnInternalRef_list().map((t) => t.getText())) || []
501
+ : undefined;
465
502
  const subQuery = commonTableExpression.subquery();
466
503
  traverseSubquery(subQuery, traverseContext, cte, recursiveNames); //recursive= true??
467
504
  (_b = traverseContext.dynamicSqlInfo.with) === null || _b === void 0 ? void 0 : _b.push({
468
- fragment: (0, select_columns_1.extractOriginalSql)(commonTableExpression) + '',
505
+ fragment: `${(0, select_columns_1.extractOriginalSql)(commonTableExpression)}`,
469
506
  relation: cte,
470
507
  fields: [],
471
508
  dependOnFields: [],
@@ -478,22 +515,25 @@ function traverseWithClause(withClause, traverseContext) {
478
515
  exports.traverseWithClause = traverseWithClause;
479
516
  function traverseFromClause(fromClause, traverseContext) {
480
517
  var _a;
481
- const tableReferenceList = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference_list();
482
- const fromColumns = tableReferenceList ? traverseTableReferenceList(tableReferenceList, traverseContext, null) : [];
518
+ const tableReferenceList = (_a = fromClause
519
+ .tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference_list();
520
+ const fromColumns = tableReferenceList
521
+ ? traverseTableReferenceList(tableReferenceList, traverseContext, null)
522
+ : [];
483
523
  return fromColumns;
484
524
  }
485
525
  function traverseTableReferenceList(tableReferenceList, traverseContext, currentFragment) {
486
526
  const result = [];
487
527
  const fragements = [];
488
- tableReferenceList.forEach(tab => {
528
+ tableReferenceList.forEach((tab) => {
489
529
  const tableFactor = tab.tableFactor();
490
530
  if (tableFactor) {
491
- let paramBefore = traverseContext.parameters.length;
531
+ const paramBefore = traverseContext.parameters.length;
492
532
  const fields = traverseTableFactor(tableFactor, traverseContext, currentFragment);
493
- let paramsAfter = traverseContext.parameters.length;
533
+ const paramsAfter = traverseContext.parameters.length;
494
534
  result.push(...fields);
495
535
  fragements.push({
496
- fragment: 'FROM ' + (0, select_columns_1.extractOriginalSql)(tableFactor) + '',
536
+ fragment: `FROM ${(0, select_columns_1.extractOriginalSql)(tableFactor)}`,
497
537
  fields: [], //fields.map(field => ({ field: field.columnName, name: field.columnName, table: field.table })),
498
538
  dependOnFields: [],
499
539
  dependOnParams: [],
@@ -505,16 +545,17 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
505
545
  let firstLeftJoinIndex = -1;
506
546
  tab.joinedTable_list().forEach((joined, index) => {
507
547
  var _a, _b;
508
- 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())) {
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())) {
509
550
  firstLeftJoinIndex = -1; //dont need to add notNull = false to joins
510
551
  }
511
- else if (firstLeftJoinIndex == -1) {
552
+ else if (firstLeftJoinIndex === -1) {
512
553
  firstLeftJoinIndex = index; //add notNull = false to all joins after the first left join
513
554
  }
514
555
  const tableReferences = joined.tableReference();
515
556
  if (tableReferences) {
516
557
  const innerJoinFragment = {
517
- fragment: (0, select_columns_1.extractOriginalSql)(joined) + '',
558
+ fragment: `${(0, select_columns_1.extractOriginalSql)(joined)}`,
518
559
  fields: [],
519
560
  dependOnFields: [],
520
561
  dependOnParams: [],
@@ -526,18 +567,22 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
526
567
  const joinedFields = traverseTableReferenceList([tableReferences], traverseContext, innerJoinFragment);
527
568
  const paramsAfter = traverseContext.parameters.length;
528
569
  //doesn't duplicate the fields of the USING clause. Ex. INNER JOIN mytable2 USING(id);
529
- const joinedFieldsFiltered = usingFields.length > 0 ? filterUsingFields(joinedFields, usingFields) : joinedFields;
570
+ const joinedFieldsFiltered = usingFields.length > 0
571
+ ? filterUsingFields(joinedFields, usingFields)
572
+ : joinedFields;
530
573
  allJoinedColumns.push(joinedFieldsFiltered);
531
- innerJoinFragment.fields = [...joinedFieldsFiltered.map(f => ({
574
+ innerJoinFragment.fields = [
575
+ ...joinedFieldsFiltered.map((f) => ({
532
576
  field: f.columnName,
533
577
  table: f.tableAlias || f.table,
534
578
  name: f.columnName
535
- }))];
579
+ }))
580
+ ];
536
581
  innerJoinFragment.parameters = Array.from({ length: paramsAfter - paramsBefore }, (x, i) => i + paramsAfter - 1);
537
582
  fragements.push(innerJoinFragment);
538
583
  const onClause = joined.expr(); //ON expr
539
584
  if (onClause) {
540
- joinedFieldsFiltered.forEach(field => {
585
+ joinedFieldsFiltered.forEach((field) => {
541
586
  const fieldName = {
542
587
  name: field.columnName,
543
588
  prefix: field.tableAlias || ''
@@ -545,18 +590,18 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
545
590
  field.notNull = field.notNull || !(0, infer_column_nullability_1.possibleNull)(fieldName, onClause);
546
591
  });
547
592
  //apply inference to the parent join too
548
- result.forEach(field => {
593
+ result.forEach((field) => {
549
594
  const fieldName = {
550
595
  name: field.columnName,
551
596
  prefix: field.tableAlias || ''
552
597
  };
553
598
  field.notNull = field.notNull || !(0, infer_column_nullability_1.possibleNull)(fieldName, onClause);
554
599
  });
555
- traverseExpr(onClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: allJoinedColumns.flatMap(c => c).concat(result) }));
600
+ traverseExpr(onClause, Object.assign(Object.assign({}, traverseContext), { fromColumns: allJoinedColumns.flat().concat(result) }));
556
601
  const columns = (0, select_columns_1.getExpressions)(onClause, ts_mysql_parser_1.SimpleExprColumnRefContext);
557
- columns.forEach(columnRef => {
602
+ columns.forEach((columnRef) => {
558
603
  const fieldName = (0, select_columns_1.splitName)(columnRef.expr.getText());
559
- if ((innerJoinFragment === null || innerJoinFragment === void 0 ? void 0 : innerJoinFragment.relation) != fieldName.prefix) {
604
+ if ((innerJoinFragment === null || innerJoinFragment === void 0 ? void 0 : innerJoinFragment.relation) !== fieldName.prefix) {
560
605
  innerJoinFragment.parentRelation = fieldName.prefix;
561
606
  }
562
607
  });
@@ -564,8 +609,8 @@ function traverseTableReferenceList(tableReferenceList, traverseContext, current
564
609
  }
565
610
  });
566
611
  allJoinedColumns.forEach((joinedColumns, index) => {
567
- joinedColumns.forEach(field => {
568
- if (firstLeftJoinIndex != -1 && index >= firstLeftJoinIndex) {
612
+ joinedColumns.forEach((field) => {
613
+ if (firstLeftJoinIndex !== -1 && index >= firstLeftJoinIndex) {
569
614
  const newField = Object.assign(Object.assign({}, field), { notNull: false });
570
615
  result.push(newField);
571
616
  }
@@ -595,12 +640,12 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
595
640
  const subQuery = derivadTable.subquery();
596
641
  if (subQuery) {
597
642
  const subQueryResult = traverseSubquery(subQuery, traverseContext);
598
- const result = subQueryResult.columns.map(t => {
643
+ const result = subQueryResult.columns.map((t) => {
599
644
  const colDef = {
600
645
  table: t.table ? tableAlias || '' : '',
601
646
  columnName: t.name,
602
647
  columnType: t.type,
603
- columnKey: "",
648
+ columnKey: '',
604
649
  notNull: t.notNull,
605
650
  tableAlias: tableAlias
606
651
  };
@@ -614,7 +659,7 @@ function traverseTableFactor(tableFactor, traverseContext, currentFragment) {
614
659
  const listParens = traverseTableReferenceListParens(tableReferenceListParens, traverseContext);
615
660
  return listParens;
616
661
  }
617
- throw Error('traverseTableFactor - not supported: ' + tableFactor.constructor.name);
662
+ throw Error(`traverseTableFactor - not supported: ${tableFactor.constructor.name}`);
618
663
  }
619
664
  //tableReferenceList | tableReferenceListParens
620
665
  function traverseTableReferenceListParens(ctx, traverseContext) {
@@ -626,7 +671,7 @@ function traverseTableReferenceListParens(ctx, traverseContext) {
626
671
  if (tableReferenceListParens) {
627
672
  return traverseTableReferenceListParens(tableReferenceListParens, traverseContext);
628
673
  }
629
- throw Error('traverseTableReferenceListParens - not supported: ' + ctx.constructor.name);
674
+ throw Error(`traverseTableReferenceListParens - not supported: ${ctx.constructor.name}`);
630
675
  }
631
676
  function traverseSingleTable(singleTable, dbSchema, withSchema, currentFragment, withFragments) {
632
677
  var _a;
@@ -636,8 +681,8 @@ function traverseSingleTable(singleTable, dbSchema, withSchema, currentFragment,
636
681
  if (currentFragment) {
637
682
  currentFragment.relation = tableAlias || tableName.name;
638
683
  }
639
- withFragments === null || withFragments === void 0 ? void 0 : withFragments.forEach(withFragment => {
640
- if (withFragment.relation == table) {
684
+ withFragments === null || withFragments === void 0 ? void 0 : withFragments.forEach((withFragment) => {
685
+ if (withFragment.relation === table) {
641
686
  withFragment.parentRelation = tableAlias || tableName.name;
642
687
  }
643
688
  });
@@ -654,23 +699,25 @@ function traverseSubquery(subQuery, traverseContext, cte, recursiveNames) {
654
699
  if (queryExpressionParens2) {
655
700
  return traverseQueryExpressionParens(queryExpressionParens2, traverseContext);
656
701
  }
657
- throw Error('traverseSubquery - not expected: ' + subQuery.constructor.name);
702
+ throw Error(`traverseSubquery - not expected: ${subQuery.constructor.name}`);
658
703
  }
659
704
  function traverseSelectItemList(selectItemList, traverseContext) {
660
705
  const listType = [];
661
706
  if (selectItemList.MULT_OPERATOR()) {
662
- traverseContext.fromColumns.forEach(col => {
707
+ traverseContext.fromColumns.forEach((col) => {
663
708
  // const columnType = createColumnType(col);
664
709
  const tableName = col.tableAlias || col.table;
665
710
  listType.push(Object.assign(Object.assign({}, col.columnType), { table: tableName }));
666
711
  const fieldFragment = {
667
712
  fragment: `${tableName}.${col.columnName}`,
668
713
  fragementWithoutAlias: `${tableName}.${col.columnName}`,
669
- fields: [{
714
+ fields: [
715
+ {
670
716
  field: col.columnName,
671
717
  name: col.columnName,
672
718
  table: tableName
673
- }],
719
+ }
720
+ ],
674
721
  dependOnFields: [],
675
722
  dependOnParams: [],
676
723
  parameters: [],
@@ -681,14 +728,14 @@ function traverseSelectItemList(selectItemList, traverseContext) {
681
728
  }
682
729
  });
683
730
  }
684
- selectItemList.selectItem_list().forEach(selectItem => {
731
+ selectItemList.selectItem_list().forEach((selectItem) => {
685
732
  var _a;
686
733
  const tableWild = selectItem.tableWild();
687
734
  if (tableWild) {
688
735
  if (tableWild.MULT_OPERATOR()) {
689
736
  const itemName = (0, select_columns_1.splitName)(selectItem.getText());
690
737
  const allColumns = selectAllColumns(itemName.prefix, traverseContext.fromColumns);
691
- allColumns.forEach(col => {
738
+ allColumns.forEach((col) => {
692
739
  const columnType = (0, collect_constraints_1.createColumnType)(col);
693
740
  listType.push(columnType);
694
741
  });
@@ -697,7 +744,7 @@ function traverseSelectItemList(selectItemList, traverseContext) {
697
744
  const expr = selectItem.expr();
698
745
  if (expr) {
699
746
  const selectFragment = {
700
- fragment: (0, select_columns_1.extractOriginalSql)(selectItem) + '',
747
+ fragment: `${(0, select_columns_1.extractOriginalSql)(selectItem)}`,
701
748
  fragementWithoutAlias: (0, select_columns_1.extractOriginalSql)(expr),
702
749
  fields: [],
703
750
  dependOnFields: [],
@@ -705,17 +752,19 @@ function traverseSelectItemList(selectItemList, traverseContext) {
705
752
  parameters: [],
706
753
  dependOn: []
707
754
  };
708
- const exprType = traverseExpr(expr, Object.assign(Object.assign({}, traverseContext), { currentFragement: traverseContext.subQuery ? traverseContext.currentFragement : selectFragment }));
755
+ const exprType = traverseExpr(expr, Object.assign(Object.assign({}, traverseContext), { currentFragement: traverseContext.subQuery
756
+ ? traverseContext.currentFragement
757
+ : selectFragment }));
709
758
  if (!traverseContext.subQuery) {
710
759
  (_a = traverseContext.dynamicSqlInfo.select) === null || _a === void 0 ? void 0 : _a.push(selectFragment);
711
760
  }
712
761
  // const fields = exprType.kind == 'TypeVar' ? [{ field: exprType.name, table: exprType.table + '', name: getColumnName(selectItem) }] : []
713
- if (exprType.kind == 'TypeOperator') {
762
+ if (exprType.kind === 'TypeOperator') {
714
763
  const subqueryType = exprType.types[0];
715
764
  subqueryType.name = (0, select_columns_1.getColumnName)(selectItem);
716
765
  listType.push(subqueryType);
717
766
  }
718
- else if (exprType.kind == 'TypeVar') {
767
+ else if (exprType.kind === 'TypeVar') {
719
768
  exprType.name = (0, select_columns_1.getColumnName)(selectItem);
720
769
  listType.push(Object.assign({}, exprType)); //clone
721
770
  }
@@ -738,7 +787,7 @@ function traverseExpr(expr, traverseContext) {
738
787
  const boolPriType = traverseBoolPri(boolPri, traverseContext);
739
788
  if (traverseContext.where) {
740
789
  const currentFragment = {
741
- fragment: 'AND ' + (0, select_columns_1.extractOriginalSql)(expr),
790
+ fragment: `AND ${(0, select_columns_1.extractOriginalSql)(expr)}`,
742
791
  fields: [],
743
792
  dependOnFields: [],
744
793
  dependOnParams: [],
@@ -746,12 +795,12 @@ function traverseExpr(expr, traverseContext) {
746
795
  dependOn: []
747
796
  };
748
797
  const paramsRight = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.SimpleExprParamMarkerContext);
749
- paramsRight.forEach(_ => {
798
+ paramsRight.forEach((_) => {
750
799
  currentFragment.dependOnParams.push(paramsCount);
751
800
  paramsCount++;
752
801
  });
753
802
  const columnsRef = (0, select_columns_1.getExpressions)(expr, ts_mysql_parser_1.ColumnRefContext);
754
- columnsRef.forEach(colRef => {
803
+ columnsRef.forEach((colRef) => {
755
804
  const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
756
805
  currentFragment.fields.push({
757
806
  field: fileName.name,
@@ -769,17 +818,18 @@ function traverseExpr(expr, traverseContext) {
769
818
  return traverseExpr(expr2, traverseContext);
770
819
  }
771
820
  return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
772
- ;
773
821
  }
774
- if (expr instanceof ts_mysql_parser_1.ExprAndContext || expr instanceof ts_mysql_parser_1.ExprXorContext || expr instanceof ts_mysql_parser_1.ExprOrContext) {
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) {
775
825
  const all = [];
776
826
  (0, select_columns_1.getTopLevelAndExpr)(expr, all);
777
- all.forEach(andExpression => {
827
+ all.forEach((andExpression) => {
778
828
  let paramsCount = traverseContext.parameters.length;
779
829
  traverseExpr(andExpression.expr, Object.assign(Object.assign({}, traverseContext), { where: false }));
780
830
  if (traverseContext.where) {
781
831
  const currentFragment = {
782
- fragment: andExpression.operator + ' ' + (0, select_columns_1.extractOriginalSql)(andExpression.expr),
832
+ fragment: `${andExpression.operator} ${(0, select_columns_1.extractOriginalSql)(andExpression.expr)}`,
783
833
  fields: [],
784
834
  dependOnFields: [],
785
835
  dependOnParams: [],
@@ -787,12 +837,12 @@ function traverseExpr(expr, traverseContext) {
787
837
  dependOn: []
788
838
  };
789
839
  const paramsRight = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.SimpleExprParamMarkerContext);
790
- paramsRight.forEach(_ => {
840
+ paramsRight.forEach((_) => {
791
841
  currentFragment.dependOnParams.push(paramsCount);
792
842
  paramsCount++;
793
843
  });
794
844
  const columnsRef = (0, select_columns_1.getExpressions)(andExpression.expr, ts_mysql_parser_1.ColumnRefContext);
795
- columnsRef.forEach(colRef => {
845
+ columnsRef.forEach((colRef) => {
796
846
  const fileName = (0, select_columns_1.splitName)(colRef.expr.getText());
797
847
  currentFragment.fields.push({
798
848
  field: fileName.name,
@@ -805,7 +855,7 @@ function traverseExpr(expr, traverseContext) {
805
855
  });
806
856
  return (0, collect_constraints_1.freshVar)(expr.getText(), 'tinyint');
807
857
  }
808
- throw Error('traverseExpr - not supported: ' + expr.getText());
858
+ throw Error(`traverseExpr - not supported: ${expr.getText()}`);
809
859
  }
810
860
  function traverseBoolPri(boolPri, traverseContext) {
811
861
  if (boolPri instanceof ts_mysql_parser_1.PrimaryExprPredicateContext) {
@@ -841,12 +891,12 @@ function traverseBoolPri(boolPri, traverseContext) {
841
891
  type1: typeLeft,
842
892
  type2: {
843
893
  kind: 'TypeOperator',
844
- types: subQueryResult.columns.map(t => t.type)
894
+ types: subQueryResult.columns.map((t) => t.type)
845
895
  }
846
896
  });
847
897
  return (0, collect_constraints_1.freshVar)(boolPri.getText(), 'tinyint');
848
898
  }
849
- throw Error('traverseExpr - not supported: ' + boolPri.constructor.name);
899
+ throw Error(`traverseExpr - not supported: ${boolPri.constructor.name}`);
850
900
  }
851
901
  function traversePredicate(predicate, traverseContext) {
852
902
  const bitExpr = predicate.bitExpr(0); //TODO - predicate length = 2? [1] == predicateOperations
@@ -854,7 +904,8 @@ function traversePredicate(predicate, traverseContext) {
854
904
  const predicateOperations = predicate.predicateOperations();
855
905
  if (predicateOperations) {
856
906
  const rightType = traversePredicateOperations(predicateOperations, bitExprType, traverseContext);
857
- if (bitExprType.kind == 'TypeOperator' && rightType.kind == 'TypeOperator') {
907
+ if (bitExprType.kind === 'TypeOperator' &&
908
+ rightType.kind === 'TypeOperator') {
858
909
  rightType.types.forEach((t, i) => {
859
910
  traverseContext.constraints.push({
860
911
  expression: predicateOperations.getText(),
@@ -864,7 +915,7 @@ function traversePredicate(predicate, traverseContext) {
864
915
  });
865
916
  });
866
917
  }
867
- if (bitExprType.kind == 'TypeVar' && rightType.kind == 'TypeOperator') {
918
+ if (bitExprType.kind === 'TypeVar' && rightType.kind === 'TypeOperator') {
868
919
  rightType.types.forEach((t, i) => {
869
920
  traverseContext.constraints.push({
870
921
  expression: predicateOperations.getText(),
@@ -880,7 +931,7 @@ function traversePredicate(predicate, traverseContext) {
880
931
  return bitExprType;
881
932
  }
882
933
  function traverseExprList(exprList, traverseContext) {
883
- const listType = exprList.expr_list().map(item => {
934
+ const listType = exprList.expr_list().map((item) => {
884
935
  const exprType = traverseExpr(item, traverseContext);
885
936
  return exprType;
886
937
  });
@@ -895,18 +946,24 @@ function traverseBitExpr(bitExpr, traverseContext) {
895
946
  if (simpleExpr) {
896
947
  return traverseSimpleExpr(simpleExpr, Object.assign(Object.assign({}, traverseContext), { where: false }));
897
948
  }
898
- if (bitExpr.bitExpr_list().length == 2) {
949
+ if (bitExpr.bitExpr_list().length === 2) {
899
950
  const bitExprLeft = bitExpr.bitExpr(0);
900
951
  const typeLeftTemp = traverseBitExpr(bitExprLeft, traverseContext);
901
- const typeLeft = typeLeftTemp.kind == 'TypeOperator' ? typeLeftTemp.types[0] : typeLeftTemp;
952
+ const typeLeft = typeLeftTemp.kind === 'TypeOperator'
953
+ ? typeLeftTemp.types[0]
954
+ : typeLeftTemp;
902
955
  //const newTypeLeft = typeLeft.name == '?'? freshVar('?', 'bigint') : typeLeft;
903
956
  const bitExprRight = bitExpr.bitExpr(1);
904
957
  const typeRightTemp = traverseBitExpr(bitExprRight, traverseContext);
905
958
  //In the expression 'id + (value + 2) + ?' the '(value+2)' is treated as a SimpleExprListContext and return a TypeOperator
906
- const typeRight = typeRightTemp.kind == 'TypeOperator' ? typeRightTemp.types[0] : typeRightTemp;
959
+ const typeRight = typeRightTemp.kind === 'TypeOperator'
960
+ ? typeRightTemp.types[0]
961
+ : typeRightTemp;
907
962
  //const newTypeRight = typeRight.name == '?'? freshVar('?', 'bigint') : typeRight;
908
963
  const bitExprType = (0, collect_constraints_1.freshVar)(bitExpr.getText(), '?');
909
- if (typeLeftTemp.kind == 'TypeVar' && typeRightTemp.kind == 'TypeVar' && typeLeftTemp.table == typeRightTemp.table) {
964
+ if (typeLeftTemp.kind === 'TypeVar' &&
965
+ typeRightTemp.kind === 'TypeVar' &&
966
+ typeLeftTemp.table === typeRightTemp.table) {
910
967
  bitExprType.table = typeLeftTemp.table;
911
968
  }
912
969
  //PRECISA?
@@ -967,14 +1024,17 @@ function traverseBitExpr(bitExpr, traverseContext) {
967
1024
  });
968
1025
  return (0, collect_constraints_1.freshVar)('datetime', 'datetime');
969
1026
  }
970
- throw Error('traverseBitExpr - not supported: ' + bitExpr.constructor.name);
1027
+ throw Error(`traverseBitExpr - not supported: ${bitExpr.constructor.name}`);
971
1028
  }
972
1029
  function traversePredicateOperations(predicateOperations, parentType, traverseContext) {
973
1030
  if (predicateOperations instanceof ts_mysql_parser_1.PredicateExprInContext) {
974
1031
  const subquery = predicateOperations.subquery();
975
1032
  if (subquery) {
976
1033
  const subQueryResult = traverseSubquery(subquery, traverseContext);
977
- return { kind: 'TypeOperator', types: subQueryResult.columns.map(t => t.type) };
1034
+ return {
1035
+ kind: 'TypeOperator',
1036
+ types: subQueryResult.columns.map((t) => t.type)
1037
+ };
978
1038
  }
979
1039
  const exprList = predicateOperations.exprList();
980
1040
  if (exprList) {
@@ -1014,7 +1074,7 @@ function traversePredicateOperations(predicateOperations, parentType, traverseCo
1014
1074
  });
1015
1075
  return bitExprType;
1016
1076
  }
1017
- throw Error("Not supported: " + predicateOperations.constructor.name);
1077
+ throw Error(`Not supported: ${predicateOperations.constructor.name}`);
1018
1078
  }
1019
1079
  function traverseSimpleExpr(simpleExpr, traverseContext) {
1020
1080
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
@@ -1074,7 +1134,6 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1074
1134
  // const typeFloat = freshVar('float', 'float');
1075
1135
  // addNamedNode(simpleExpr, typeFloat, namedNodes)
1076
1136
  // }
1077
- ;
1078
1137
  }
1079
1138
  const boolLiteral = literal.boolLiteral();
1080
1139
  if (boolLiteral) {
@@ -1084,12 +1143,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1084
1143
  if (nullLiteral) {
1085
1144
  return (0, collect_constraints_1.freshVar)(nullLiteral.getText(), '?');
1086
1145
  }
1087
- throw Error('literal not supported:' + literal.getText());
1146
+ throw Error(`literal not supported:${literal.getText()}`);
1088
1147
  //...
1089
1148
  }
1090
1149
  if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprListContext) {
1091
1150
  const exprList = simpleExpr.exprList();
1092
- const listType = exprList.expr_list().map(item => {
1151
+ const listType = exprList.expr_list().map((item) => {
1093
1152
  const exprType = traverseExpr(item, Object.assign(Object.assign({}, traverseContext), { where: false }));
1094
1153
  return exprType;
1095
1154
  });
@@ -1104,29 +1163,29 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1104
1163
  const subqueryResult = traverseSubquery(subquery, traverseContext);
1105
1164
  return {
1106
1165
  kind: 'TypeOperator',
1107
- types: subqueryResult.columns.map(t => (Object.assign(Object.assign({}, t.type), { table: '' })))
1166
+ types: subqueryResult.columns.map((t) => (Object.assign(Object.assign({}, t.type), { table: '' })))
1108
1167
  };
1109
1168
  }
1110
1169
  if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprCaseContext) {
1111
1170
  //case when expr then expr else expr
1112
1171
  const caseType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
1113
- simpleExpr.whenExpression_list().forEach(whenExprCont => {
1172
+ simpleExpr.whenExpression_list().forEach((whenExprCont) => {
1114
1173
  const whenExpr = whenExprCont.expr();
1115
1174
  const whenType = traverseExpr(whenExpr, traverseContext);
1116
1175
  traverseContext.constraints.push({
1117
1176
  expression: whenExpr.getText(),
1118
- type1: whenType.kind == 'TypeOperator' ? whenType.types[0] : whenType,
1177
+ type1: whenType.kind === 'TypeOperator' ? whenType.types[0] : whenType,
1119
1178
  type2: (0, collect_constraints_1.freshVar)('tinyint', 'tinyint') //bool
1120
1179
  });
1121
1180
  });
1122
- const thenTypes = simpleExpr.thenExpression_list().map(thenExprCtx => {
1181
+ const thenTypes = simpleExpr.thenExpression_list().map((thenExprCtx) => {
1123
1182
  const thenExpr = thenExprCtx.expr();
1124
1183
  const thenType = traverseExpr(thenExpr, traverseContext);
1125
1184
  traverseContext.constraints.push({
1126
1185
  expression: thenExprCtx.getText(),
1127
1186
  type1: caseType,
1128
- type2: thenType.kind == 'TypeOperator' ? thenType.types[0] : thenType,
1129
- mostGeneralType: true,
1187
+ type2: thenType.kind === 'TypeOperator' ? thenType.types[0] : thenType,
1188
+ mostGeneralType: true
1130
1189
  });
1131
1190
  return thenType;
1132
1191
  });
@@ -1136,15 +1195,15 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1136
1195
  traverseContext.constraints.push({
1137
1196
  expression: (_c = simpleExpr.elseExpression()) === null || _c === void 0 ? void 0 : _c.getText(),
1138
1197
  type1: caseType,
1139
- type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
1198
+ type2: elseType.kind === 'TypeOperator' ? elseType.types[0] : elseType,
1140
1199
  mostGeneralType: true
1141
1200
  });
1142
- thenTypes.forEach(thenType => {
1201
+ thenTypes.forEach((thenType) => {
1143
1202
  var _a;
1144
1203
  traverseContext.constraints.push({
1145
1204
  expression: (_a = simpleExpr.elseExpression()) === null || _a === void 0 ? void 0 : _a.getText(),
1146
1205
  type1: thenType,
1147
- type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,
1206
+ type2: elseType.kind === 'TypeOperator' ? elseType.types[0] : elseType,
1148
1207
  mostGeneralType: true
1149
1208
  });
1150
1209
  });
@@ -1162,7 +1221,8 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1162
1221
  type1: typeLeft,
1163
1222
  type2: (0, collect_constraints_1.freshVar)('bigint', 'bigint')
1164
1223
  });
1165
- if (typeRight.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeRight.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeRight.name))) {
1224
+ if (typeRight.kind === 'TypeVar' &&
1225
+ ((0, collect_constraints_1.isDateLiteral)(typeRight.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeRight.name))) {
1166
1226
  typeRight.type = 'datetime';
1167
1227
  }
1168
1228
  traverseContext.constraints.push({
@@ -1208,7 +1268,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1208
1268
  mostGeneralType: true,
1209
1269
  coercionType: 'SumFunction'
1210
1270
  });
1211
- if (inSumExprType.kind == 'TypeVar') {
1271
+ if (inSumExprType.kind === 'TypeVar') {
1212
1272
  functionType.table = inSumExprType.table;
1213
1273
  }
1214
1274
  }
@@ -1217,7 +1277,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1217
1277
  if (sumExpr.GROUP_CONCAT_SYMBOL()) {
1218
1278
  const exprList = sumExpr.exprList();
1219
1279
  if (exprList) {
1220
- exprList.expr_list().map(item => {
1280
+ exprList.expr_list().map((item) => {
1221
1281
  const exprType = traverseExpr(item, traverseContext);
1222
1282
  return exprType;
1223
1283
  });
@@ -1227,10 +1287,9 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1227
1287
  */
1228
1288
  //TODO - Infer TEXT/BLOB or VARCHAR/VARBINARY
1229
1289
  return (0, collect_constraints_1.freshVar)(sumExpr.getText(), 'varchar');
1230
- ;
1231
1290
  }
1232
1291
  }
1233
- throw Error('Expression not supported: ' + sumExpr.constructor.name);
1292
+ throw Error(`Expression not supported: ${sumExpr.constructor.name}`);
1234
1293
  }
1235
1294
  if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprRuntimeFunctionContext) {
1236
1295
  const runtimeFunctionCall = simpleExpr.runtimeFunctionCall();
@@ -1245,7 +1304,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1245
1304
  }
1246
1305
  if (runtimeFunctionCall.REPLACE_SYMBOL()) {
1247
1306
  const exprList = runtimeFunctionCall.expr_list();
1248
- exprList.forEach(expr => {
1307
+ exprList.forEach((expr) => {
1249
1308
  const exprType = traverseExpr(expr, traverseContext);
1250
1309
  traverseContext.constraints.push({
1251
1310
  expression: expr.getText(),
@@ -1255,14 +1314,16 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1255
1314
  });
1256
1315
  return (0, collect_constraints_1.freshVar)('varchar', 'varchar');
1257
1316
  }
1258
- if (runtimeFunctionCall.YEAR_SYMBOL() || runtimeFunctionCall.MONTH_SYMBOL() || runtimeFunctionCall.DAY_SYMBOL()) {
1317
+ if (runtimeFunctionCall.YEAR_SYMBOL() ||
1318
+ runtimeFunctionCall.MONTH_SYMBOL() ||
1319
+ runtimeFunctionCall.DAY_SYMBOL()) {
1259
1320
  const expr = (_g = runtimeFunctionCall.exprWithParentheses()) === null || _g === void 0 ? void 0 : _g.expr();
1260
1321
  if (expr) {
1261
1322
  const paramType = traverseExpr(expr, traverseContext);
1262
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1323
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1263
1324
  paramType.type = 'datetime';
1264
1325
  }
1265
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1326
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1266
1327
  paramType.type = 'date';
1267
1328
  }
1268
1329
  traverseContext.constraints.push({
@@ -1278,10 +1339,10 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1278
1339
  const expr = (_h = runtimeFunctionCall.exprWithParentheses()) === null || _h === void 0 ? void 0 : _h.expr();
1279
1340
  if (expr) {
1280
1341
  const paramType = traverseExpr(expr, traverseContext);
1281
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1342
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1282
1343
  paramType.type = 'datetime';
1283
1344
  }
1284
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1345
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1285
1346
  paramType.type = 'date';
1286
1347
  }
1287
1348
  traverseContext.constraints.push({
@@ -1292,17 +1353,19 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1292
1353
  }
1293
1354
  return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
1294
1355
  }
1295
- if (runtimeFunctionCall.HOUR_SYMBOL() || runtimeFunctionCall.MINUTE_SYMBOL() || runtimeFunctionCall.SECOND_SYMBOL()) {
1356
+ if (runtimeFunctionCall.HOUR_SYMBOL() ||
1357
+ runtimeFunctionCall.MINUTE_SYMBOL() ||
1358
+ runtimeFunctionCall.SECOND_SYMBOL()) {
1296
1359
  const expr = (_j = runtimeFunctionCall.exprWithParentheses()) === null || _j === void 0 ? void 0 : _j.expr();
1297
1360
  if (expr) {
1298
1361
  const paramType = traverseExpr(expr, traverseContext);
1299
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isTimeLiteral)(paramType.name)) {
1362
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isTimeLiteral)(paramType.name)) {
1300
1363
  paramType.type = 'time';
1301
1364
  }
1302
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1365
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateLiteral)(paramType.name)) {
1303
1366
  paramType.type = 'date';
1304
1367
  }
1305
- if (paramType.kind == 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1368
+ if (paramType.kind === 'TypeVar' && (0, collect_constraints_1.isDateTimeLiteral)(paramType.name)) {
1306
1369
  paramType.type = 'datetime';
1307
1370
  }
1308
1371
  traverseContext.constraints.push({
@@ -1319,7 +1382,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1319
1382
  const trimFunction = runtimeFunctionCall.trimFunction();
1320
1383
  if (trimFunction) {
1321
1384
  const exprList = trimFunction.expr_list();
1322
- if (exprList.length == 1) {
1385
+ if (exprList.length === 1) {
1323
1386
  const exprType = traverseExpr(exprList[0], traverseContext);
1324
1387
  traverseContext.constraints.push({
1325
1388
  expression: exprList[0].getText(),
@@ -1327,7 +1390,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1327
1390
  type2: (0, collect_constraints_1.freshVar)('varchar', 'varchar')
1328
1391
  });
1329
1392
  }
1330
- if (exprList.length == 2) {
1393
+ if (exprList.length === 2) {
1331
1394
  const exprType = traverseExpr(exprList[0], traverseContext);
1332
1395
  const expr2Type = traverseExpr(exprList[1], traverseContext);
1333
1396
  traverseContext.constraints.push({
@@ -1355,17 +1418,18 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1355
1418
  traverseExprListParameters(exprList, params, traverseContext);
1356
1419
  return varcharParam;
1357
1420
  }
1358
- if (runtimeFunctionCall.ADDDATE_SYMBOL()
1359
- || runtimeFunctionCall.DATE_ADD_SYMBOL()
1360
- || runtimeFunctionCall.SUBDATE_SYMBOL()
1361
- || runtimeFunctionCall.DATE_SUB_SYMBOL()) {
1421
+ if (runtimeFunctionCall.ADDDATE_SYMBOL() ||
1422
+ runtimeFunctionCall.DATE_ADD_SYMBOL() ||
1423
+ runtimeFunctionCall.SUBDATE_SYMBOL() ||
1424
+ runtimeFunctionCall.DATE_SUB_SYMBOL()) {
1362
1425
  //SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY)
1363
1426
  //SELECT ADDDATE('2008-01-02', 31)
1364
1427
  const expr1 = runtimeFunctionCall.expr(0);
1365
1428
  const expr2 = runtimeFunctionCall.expr(1);
1366
1429
  const typeExpr1 = traverseExpr(expr1, traverseContext);
1367
1430
  const typeExpr2 = traverseExpr(expr2, traverseContext);
1368
- if (typeExpr1.kind == 'TypeVar' && ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
1431
+ if (typeExpr1.kind === 'TypeVar' &&
1432
+ ((0, collect_constraints_1.isDateLiteral)(typeExpr1.name) || (0, collect_constraints_1.isDateTimeLiteral)(typeExpr1.name))) {
1369
1433
  typeExpr1.type = 'datetime';
1370
1434
  }
1371
1435
  traverseContext.constraints.push({
@@ -1381,7 +1445,8 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1381
1445
  return (0, collect_constraints_1.freshVar)('datetime', 'datetime');
1382
1446
  }
1383
1447
  if (runtimeFunctionCall.COALESCE_SYMBOL()) {
1384
- const exprList = (_k = runtimeFunctionCall.exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
1448
+ const exprList = (_k = runtimeFunctionCall
1449
+ .exprListWithParentheses()) === null || _k === void 0 ? void 0 : _k.exprList().expr_list();
1385
1450
  if (exprList) {
1386
1451
  const paramType = (0, collect_constraints_1.freshVar)('COALESCE', 'any');
1387
1452
  const params = {
@@ -1391,7 +1456,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1391
1456
  const paramsTypeList = traverseExprListParameters(exprList, params, traverseContext);
1392
1457
  paramsTypeList.forEach((typeVar, paramIndex) => {
1393
1458
  traverseContext.constraints.push({
1394
- expression: runtimeFunctionCall.getText() + '_param' + (paramIndex + 1),
1459
+ expression: `${runtimeFunctionCall.getText()}_param${paramIndex + 1}`,
1395
1460
  type1: paramType,
1396
1461
  type2: typeVar,
1397
1462
  mostGeneralType: true,
@@ -1451,11 +1516,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1451
1516
  });
1452
1517
  return expr2Type;
1453
1518
  }
1454
- throw Error('Function not supported: ' + runtimeFunctionCall.getText());
1519
+ throw Error(`Function not supported: ${runtimeFunctionCall.getText()}`);
1455
1520
  }
1456
1521
  if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprFunctionContext) {
1457
1522
  const functionIdentifier = (0, collect_constraints_1.getFunctionName)(simpleExpr);
1458
- if (functionIdentifier === 'concat_ws' || (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
1523
+ if (functionIdentifier === 'concat_ws' ||
1524
+ (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {
1459
1525
  const varcharType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'varchar');
1460
1526
  const params = {
1461
1527
  kind: 'VariableLengthParams',
@@ -1514,7 +1580,9 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1514
1580
  return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'date');
1515
1581
  }
1516
1582
  if (functionIdentifier === 'datediff') {
1517
- const udfExprList = (_l = simpleExpr.functionCall().udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
1583
+ const udfExprList = (_l = simpleExpr
1584
+ .functionCall()
1585
+ .udfExprList()) === null || _l === void 0 ? void 0 : _l.udfExpr_list();
1518
1586
  if (udfExprList) {
1519
1587
  udfExprList.forEach((inExpr) => {
1520
1588
  const expr = inExpr.expr();
@@ -1530,8 +1598,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1530
1598
  }
1531
1599
  return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
1532
1600
  }
1533
- if (functionIdentifier === 'period_add' || functionIdentifier == 'period_diff') {
1534
- const udfExprList = (_m = simpleExpr.functionCall().udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
1601
+ if (functionIdentifier === 'period_add' ||
1602
+ functionIdentifier === 'period_diff') {
1603
+ const udfExprList = (_m = simpleExpr
1604
+ .functionCall()
1605
+ .udfExprList()) === null || _m === void 0 ? void 0 : _m.udfExpr_list();
1535
1606
  if (udfExprList) {
1536
1607
  udfExprList.forEach((inExpr) => {
1537
1608
  const expr = inExpr.expr();
@@ -1546,7 +1617,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1546
1617
  }
1547
1618
  return (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'bigint');
1548
1619
  }
1549
- if (functionIdentifier === 'lpad' || functionIdentifier == 'rpad') {
1620
+ if (functionIdentifier === 'lpad' || functionIdentifier === 'rpad') {
1550
1621
  const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
1551
1622
  const intParam = (0, collect_constraints_1.freshVar)('int', 'int');
1552
1623
  const params = {
@@ -1556,13 +1627,13 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1556
1627
  walkFunctionParameters(simpleExpr, params, traverseContext);
1557
1628
  return varcharParam;
1558
1629
  }
1559
- if (functionIdentifier === 'lower'
1560
- || functionIdentifier === 'lcase'
1561
- || functionIdentifier === 'upper'
1562
- || functionIdentifier === 'ucase'
1563
- || functionIdentifier === 'trim'
1564
- || functionIdentifier === 'ltrim'
1565
- || functionIdentifier === 'rtrim') {
1630
+ if (functionIdentifier === 'lower' ||
1631
+ functionIdentifier === 'lcase' ||
1632
+ functionIdentifier === 'upper' ||
1633
+ functionIdentifier === 'ucase' ||
1634
+ functionIdentifier === 'trim' ||
1635
+ functionIdentifier === 'ltrim' ||
1636
+ functionIdentifier === 'rtrim') {
1566
1637
  const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
1567
1638
  const params = {
1568
1639
  kind: 'FixedLengthParams',
@@ -1571,7 +1642,8 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1571
1642
  walkFunctionParameters(simpleExpr, params, traverseContext);
1572
1643
  return varcharParam;
1573
1644
  }
1574
- if (functionIdentifier === 'length' || functionIdentifier == 'char_length') {
1645
+ if (functionIdentifier === 'length' ||
1646
+ functionIdentifier === 'char_length') {
1575
1647
  const varcharParam = (0, collect_constraints_1.freshVar)('varchar', 'varchar');
1576
1648
  const params = {
1577
1649
  kind: 'FixedLengthParams',
@@ -1582,8 +1654,10 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1582
1654
  }
1583
1655
  if (functionIdentifier === 'abs') {
1584
1656
  const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
1585
- const udfExprList = (_o = simpleExpr.functionCall().udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
1586
- udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
1657
+ const udfExprList = (_o = simpleExpr
1658
+ .functionCall()
1659
+ .udfExprList()) === null || _o === void 0 ? void 0 : _o.udfExpr_list();
1660
+ udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach((expr) => {
1587
1661
  const param1 = traverseExpr(expr.expr(), traverseContext);
1588
1662
  traverseContext.constraints.push({
1589
1663
  expression: simpleExpr.getText(),
@@ -1595,10 +1669,12 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1595
1669
  });
1596
1670
  return functionType;
1597
1671
  }
1598
- if (functionIdentifier == 'ceiling' || functionIdentifier == 'ceil') {
1672
+ if (functionIdentifier === 'ceiling' || functionIdentifier === 'ceil') {
1599
1673
  const functionType = (0, collect_constraints_1.freshVar)('number', 'number');
1600
- const udfExprList = (_p = simpleExpr.functionCall().udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
1601
- udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach(expr => {
1674
+ const udfExprList = (_p = simpleExpr
1675
+ .functionCall()
1676
+ .udfExprList()) === null || _p === void 0 ? void 0 : _p.udfExpr_list();
1677
+ udfExprList === null || udfExprList === void 0 ? void 0 : udfExprList.forEach((expr) => {
1602
1678
  const param1 = traverseExpr(expr.expr(), traverseContext);
1603
1679
  traverseContext.constraints.push({
1604
1680
  expression: simpleExpr.getText(),
@@ -1610,12 +1686,14 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1610
1686
  });
1611
1687
  return functionType;
1612
1688
  }
1613
- if (functionIdentifier == 'timestampdiff') {
1614
- const udfExprList = (_q = simpleExpr.functionCall().udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
1689
+ if (functionIdentifier === 'timestampdiff') {
1690
+ const udfExprList = (_q = simpleExpr
1691
+ .functionCall()
1692
+ .udfExprList()) === null || _q === void 0 ? void 0 : _q.udfExpr_list();
1615
1693
  if (udfExprList) {
1616
1694
  const [first, ...rest] = udfExprList;
1617
1695
  const unit = first.getText().trim().toLowerCase();
1618
- rest.forEach((inExpr, paramIndex) => {
1696
+ rest.forEach((inExpr) => {
1619
1697
  const expr = inExpr.expr();
1620
1698
  const exprType = traverseExpr(expr, traverseContext);
1621
1699
  const newType = (0, collect_constraints_1.verifyDateTypesCoercion)(exprType);
@@ -1630,9 +1708,11 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1630
1708
  }
1631
1709
  return (0, collect_constraints_1.freshVar)('int', 'int');
1632
1710
  }
1633
- if (functionIdentifier == 'ifnull' || functionIdentifier == 'nullif') {
1711
+ if (functionIdentifier === 'ifnull' || functionIdentifier === 'nullif') {
1634
1712
  const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), '?');
1635
- const udfExprList = (_r = simpleExpr.functionCall().udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
1713
+ const udfExprList = (_r = simpleExpr
1714
+ .functionCall()
1715
+ .udfExprList()) === null || _r === void 0 ? void 0 : _r.udfExpr_list();
1636
1716
  if (udfExprList) {
1637
1717
  const [expr1, expr2] = udfExprList;
1638
1718
  const expr1Type = traverseExpr(expr1.expr(), traverseContext);
@@ -1650,11 +1730,14 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1650
1730
  }
1651
1731
  return functionType;
1652
1732
  }
1653
- if (functionIdentifier == 'md5' //md5(str) - TODO - have input constraint = string
1654
- || functionIdentifier == 'hex' //md5(n or str)
1655
- || functionIdentifier == 'unhex') { //unhex (str) - TODO - have input constraint = string
1733
+ if (functionIdentifier === 'md5' || //md5(str) - TODO - have input constraint = string
1734
+ functionIdentifier === 'hex' || //md5(n or str)
1735
+ functionIdentifier === 'unhex') {
1736
+ //unhex (str) - TODO - have input constraint = string
1656
1737
  const functionType = (0, collect_constraints_1.freshVar)(simpleExpr.getText(), 'char');
1657
- const udfExprList = (_s = simpleExpr.functionCall().udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
1738
+ const udfExprList = (_s = simpleExpr
1739
+ .functionCall()
1740
+ .udfExprList()) === null || _s === void 0 ? void 0 : _s.udfExpr_list();
1658
1741
  if (udfExprList) {
1659
1742
  const [expr1] = udfExprList;
1660
1743
  const paramType = traverseExpr(expr1.expr(), traverseContext);
@@ -1666,7 +1749,7 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1666
1749
  }
1667
1750
  return functionType;
1668
1751
  }
1669
- throw Error('Function not supported: ' + functionIdentifier);
1752
+ throw Error(`Function not supported: ${functionIdentifier}`);
1670
1753
  }
1671
1754
  if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprWindowingFunctionContext) {
1672
1755
  const windowFunctionCall = simpleExpr.windowFunctionCall();
@@ -1678,14 +1761,14 @@ function traverseSimpleExpr(simpleExpr, traverseContext) {
1678
1761
  return (0, collect_constraints_1.freshVar)(castType.getText(), 'char');
1679
1762
  }
1680
1763
  }
1681
- throw Error('traverseSimpleExpr - not supported: ' + simpleExpr.constructor.name);
1764
+ throw Error(`traverseSimpleExpr - not supported: ${simpleExpr.constructor.name}`);
1682
1765
  }
1683
1766
  function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
1684
- if (windowFunctionCall.ROW_NUMBER_SYMBOL()
1685
- || windowFunctionCall.RANK_SYMBOL()
1686
- || windowFunctionCall.DENSE_RANK_SYMBOL()
1687
- || windowFunctionCall.CUME_DIST_SYMBOL()
1688
- || windowFunctionCall.PERCENT_RANK_SYMBOL()) {
1767
+ if (windowFunctionCall.ROW_NUMBER_SYMBOL() ||
1768
+ windowFunctionCall.RANK_SYMBOL() ||
1769
+ windowFunctionCall.DENSE_RANK_SYMBOL() ||
1770
+ windowFunctionCall.CUME_DIST_SYMBOL() ||
1771
+ windowFunctionCall.PERCENT_RANK_SYMBOL()) {
1689
1772
  return (0, collect_constraints_1.freshVar)(windowFunctionCall.getText(), 'bigint');
1690
1773
  }
1691
1774
  const expr = windowFunctionCall.expr();
@@ -1697,12 +1780,14 @@ function traverseWindowFunctionCall(windowFunctionCall, traverseContext) {
1697
1780
  const expr = exprWithParentheses.expr();
1698
1781
  return traverseExpr(expr, traverseContext);
1699
1782
  }
1700
- throw Error('No support for expression' + windowFunctionCall.constructor.name);
1783
+ throw Error(`No support for expression${windowFunctionCall.constructor.name}`);
1701
1784
  }
1702
1785
  function traverseExprListParameters(exprList, params, traverseContext) {
1703
1786
  return exprList.map((expr, paramIndex) => {
1704
1787
  const exprType = traverseExpr(expr, traverseContext);
1705
- const paramType = params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
1788
+ const paramType = params.kind === 'FixedLengthParams'
1789
+ ? params.paramsType[paramIndex]
1790
+ : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType);
1706
1791
  traverseContext.constraints.push({
1707
1792
  expression: expr.getText(),
1708
1793
  type1: exprType,
@@ -1715,11 +1800,13 @@ function traverseExprListParameters(exprList, params, traverseContext) {
1715
1800
  function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
1716
1801
  var _a, _b;
1717
1802
  const functionName = (0, collect_constraints_1.getFunctionName)(simpleExprFunction);
1718
- const udfExprList = (_a = simpleExprFunction.functionCall().udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
1803
+ const udfExprList = (_a = simpleExprFunction
1804
+ .functionCall()
1805
+ .udfExprList()) === null || _a === void 0 ? void 0 : _a.udfExpr_list();
1719
1806
  if (udfExprList) {
1720
1807
  const paramTypes = udfExprList
1721
- .filter((undefined, paramIndex) => {
1722
- return functionName == 'timestampdiff' ? paramIndex != 0 : true; //filter the first parameter of timestampdiff function
1808
+ .filter((_, paramIndex) => {
1809
+ return functionName === 'timestampdiff' ? paramIndex !== 0 : true; //filter the first parameter of timestampdiff function
1723
1810
  })
1724
1811
  .map((inExpr, paramIndex) => {
1725
1812
  const expr = inExpr.expr();
@@ -1727,7 +1814,9 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
1727
1814
  traverseContext.constraints.push({
1728
1815
  expression: expr.getText(),
1729
1816
  type1: exprType,
1730
- type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
1817
+ type2: params.kind === 'FixedLengthParams'
1818
+ ? params.paramsType[paramIndex]
1819
+ : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType)
1731
1820
  });
1732
1821
  return exprType;
1733
1822
  });
@@ -1739,7 +1828,9 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
1739
1828
  const inSumExprType = traverseExpr(inExpr, traverseContext);
1740
1829
  traverseContext.constraints.push({
1741
1830
  expression: inExpr.getText(),
1742
- type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
1831
+ type1: params.kind === 'FixedLengthParams'
1832
+ ? params.paramsType[paramIndex]
1833
+ : (0, collect_constraints_1.freshVar)(params.paramType, params.paramType),
1743
1834
  type2: inSumExprType,
1744
1835
  mostGeneralType: true
1745
1836
  });
@@ -1750,14 +1841,21 @@ function walkFunctionParameters(simpleExprFunction, params, traverseContext) {
1750
1841
  throw Error('Error in walkFunctionParameters');
1751
1842
  }
1752
1843
  function filterColumns(dbSchema, withSchema, tableAlias, table) {
1753
- const withResult = withSchema.filter(t => t.table.toLowerCase() == table.name.toLowerCase()).map(s => (Object.assign(Object.assign({}, s), { tableAlias: tableAlias })));
1844
+ const withResult = withSchema
1845
+ .filter((t) => t.table.toLowerCase() === table.name.toLowerCase())
1846
+ .map((s) => (Object.assign(Object.assign({}, s), { tableAlias: tableAlias })));
1754
1847
  const tableColumns1 = dbSchema
1755
- .filter(schema => schema.table.toLowerCase() == table.name.toLowerCase() && (schema.schema == table.prefix || table.prefix == ''))
1756
- .map(tableColumn => {
1848
+ .filter((schema) => schema.table.toLowerCase() === table.name.toLowerCase() &&
1849
+ (schema.schema === table.prefix || table.prefix === ''))
1850
+ .map((tableColumn) => {
1757
1851
  //name and colum are the same on the leaf table
1758
1852
  const r = {
1759
- columnName: tableColumn.column, columnType: (0, collect_constraints_1.createColumnTypeFomColumnSchema)(tableColumn),
1760
- notNull: tableColumn.notNull, table: table.name, tableAlias: tableAlias || '', columnKey: tableColumn.columnKey
1853
+ columnName: tableColumn.column,
1854
+ columnType: (0, collect_constraints_1.createColumnTypeFomColumnSchema)(tableColumn),
1855
+ notNull: tableColumn.notNull,
1856
+ table: table.name,
1857
+ tableAlias: tableAlias || '',
1858
+ columnKey: tableColumn.columnKey
1761
1859
  };
1762
1860
  return r;
1763
1861
  });
@@ -1766,8 +1864,10 @@ function filterColumns(dbSchema, withSchema, tableAlias, table) {
1766
1864
  }
1767
1865
  exports.filterColumns = filterColumns;
1768
1866
  function selectAllColumns(tablePrefix, fromColumns) {
1769
- return fromColumns.filter(column => {
1770
- if (tablePrefix == '' || tablePrefix == column.tableAlias || tablePrefix == column.table) {
1867
+ return fromColumns.filter((column) => {
1868
+ if (tablePrefix === '' ||
1869
+ tablePrefix === column.tableAlias ||
1870
+ tablePrefix === column.table) {
1771
1871
  return true;
1772
1872
  }
1773
1873
  return false;
@@ -1775,7 +1875,7 @@ function selectAllColumns(tablePrefix, fromColumns) {
1775
1875
  }
1776
1876
  exports.selectAllColumns = selectAllColumns;
1777
1877
  function filterUsingFields(joinedFields, usingFields) {
1778
- return joinedFields.filter(joinedField => {
1878
+ return joinedFields.filter((joinedField) => {
1779
1879
  const isUsing = usingFields.includes(joinedField.columnName);
1780
1880
  if (!isUsing) {
1781
1881
  return true;
@@ -1789,13 +1889,14 @@ function isMultipleRowResult(selectStatement, fromColumns) {
1789
1889
  return false;
1790
1890
  }
1791
1891
  const querySpecs = (0, parse_1.getAllQuerySpecificationsFromSelectStatement)(selectStatement);
1792
- if (querySpecs.length == 1) { //UNION queries are multipleRowsResult = true
1892
+ if (querySpecs.length === 1) {
1893
+ //UNION queries are multipleRowsResult = true
1793
1894
  const fromClause = querySpecs[0].fromClause();
1794
1895
  if (!fromClause) {
1795
1896
  return false;
1796
1897
  }
1797
- if (querySpecs[0].selectItemList().getChildCount() == 1) {
1798
- const selectItem = querySpecs[0].selectItemList().getChild(0);
1898
+ if (querySpecs[0].selectItemList().getChildCount() === 1) {
1899
+ const selectItem = (querySpecs[0].selectItemList().getChild(0));
1799
1900
  //if selectItem = * (TerminalNode) childCount = 0; selectItem.expr() throws exception
1800
1901
  const expr = selectItem.getChildCount() > 0 ? selectItem.expr() : null;
1801
1902
  if (expr) {
@@ -1806,13 +1907,14 @@ function isMultipleRowResult(selectStatement, fromColumns) {
1806
1907
  }
1807
1908
  }
1808
1909
  }
1809
- const joinedTable = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
1910
+ const joinedTable = (_a = fromClause
1911
+ .tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference(0).joinedTable_list();
1810
1912
  if (joinedTable && joinedTable.length > 0) {
1811
1913
  return true;
1812
1914
  }
1813
1915
  const whereClauseExpr = (_b = querySpecs[0].whereClause()) === null || _b === void 0 ? void 0 : _b.expr();
1814
1916
  const isMultipleRowResult = whereClauseExpr && verifyMultipleResult2(whereClauseExpr, fromColumns);
1815
- if (isMultipleRowResult == false) {
1917
+ if (isMultipleRowResult === false) {
1816
1918
  return false;
1817
1919
  }
1818
1920
  }
@@ -1821,10 +1923,10 @@ function isMultipleRowResult(selectStatement, fromColumns) {
1821
1923
  exports.isMultipleRowResult = isMultipleRowResult;
1822
1924
  function isLimitOne(selectStatement) {
1823
1925
  const limitOptions = (0, parse_1.getLimitOptions)(selectStatement);
1824
- if (limitOptions.length == 1 && limitOptions[0].getText() == '1') {
1926
+ if (limitOptions.length === 1 && limitOptions[0].getText() === '1') {
1825
1927
  return true;
1826
1928
  }
1827
- if (limitOptions.length == 2 && limitOptions[1].getText() == '1') {
1929
+ if (limitOptions.length === 2 && limitOptions[1].getText() === '1') {
1828
1930
  return true;
1829
1931
  }
1830
1932
  return false;
@@ -1834,9 +1936,10 @@ function verifyMultipleResult2(exprContext, fromColumns) {
1834
1936
  const boolPri = exprContext.boolPri();
1835
1937
  if (boolPri instanceof ts_mysql_parser_1.PrimaryExprCompareContext) {
1836
1938
  if (boolPri.compOp().EQUAL_OPERATOR()) {
1837
- let compareLeft = boolPri.boolPri();
1838
- let compareRight = boolPri.predicate();
1839
- if (isUniqueKeyComparation(compareLeft, fromColumns) || isUniqueKeyComparation(compareRight, fromColumns)) {
1939
+ const compareLeft = boolPri.boolPri();
1940
+ const compareRight = boolPri.predicate();
1941
+ if (isUniqueKeyComparation(compareLeft, fromColumns) ||
1942
+ isUniqueKeyComparation(compareRight, fromColumns)) {
1840
1943
  return false; //multipleRow = false
1841
1944
  }
1842
1945
  }
@@ -1848,8 +1951,10 @@ function verifyMultipleResult2(exprContext, fromColumns) {
1848
1951
  return true;
1849
1952
  }
1850
1953
  if (exprContext instanceof ts_mysql_parser_1.ExprAndContext) {
1851
- const oneIsSingleResult = exprContext.expr_list().some(expr => verifyMultipleResult2(expr, fromColumns) == false);
1852
- return oneIsSingleResult == false;
1954
+ const oneIsSingleResult = exprContext
1955
+ .expr_list()
1956
+ .some((expr) => verifyMultipleResult2(expr, fromColumns) === false);
1957
+ return oneIsSingleResult === false;
1853
1958
  }
1854
1959
  // if (exprContext instanceof ExprXorContext) {
1855
1960
  // const expressions = exprContext.expr();
@@ -1857,15 +1962,16 @@ function verifyMultipleResult2(exprContext, fromColumns) {
1857
1962
  if (exprContext instanceof ts_mysql_parser_1.ExprOrContext) {
1858
1963
  return true; //multipleRow = true
1859
1964
  }
1860
- throw Error('Unknow type:' + exprContext.constructor.name);
1965
+ throw Error(`Unknow type:${exprContext.constructor.name}`);
1861
1966
  }
1862
1967
  exports.verifyMultipleResult2 = verifyMultipleResult2;
1863
1968
  function isUniqueKeyComparation(compare, fromColumns) {
1864
1969
  const tokens = (0, select_columns_1.getSimpleExpressions)(compare);
1865
- if (tokens.length == 1 && tokens[0] instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
1970
+ if (tokens.length === 1 && tokens[0] instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {
1866
1971
  const fieldName = (0, select_columns_1.splitName)(tokens[0].getText());
1867
1972
  const col = (0, select_columns_1.findColumn)(fieldName, fromColumns);
1868
- if (col.columnKey == 'PRI' || col.columnKey == 'UNI') { //TODO - UNIQUE
1973
+ if (col.columnKey === 'PRI' || col.columnKey === 'UNI') {
1974
+ //TODO - UNIQUE
1869
1975
  return true; //isUniqueKeyComparation = true
1870
1976
  }
1871
1977
  }
@@ -1876,7 +1982,7 @@ function getOrderByColumns(fromColumns, selectColumns) {
1876
1982
  fromColumns.forEach((col) => {
1877
1983
  const ambiguous = isAmbiguous(fromColumns, col.columnName);
1878
1984
  if (!ambiguous) {
1879
- const exists = orderByColumns.find(orderBy => orderBy == col.columnName);
1985
+ const exists = orderByColumns.find((orderBy) => orderBy === col.columnName);
1880
1986
  if (!exists) {
1881
1987
  orderByColumns.push(col.columnName);
1882
1988
  }
@@ -1888,10 +1994,10 @@ function getOrderByColumns(fromColumns, selectColumns) {
1888
1994
  orderByColumns.push(`${col.table}.${col.columnName}`);
1889
1995
  }
1890
1996
  });
1891
- selectColumns.forEach(col => {
1892
- const duplicated = selectColumns.filter(orderBy => orderBy.name == col.name);
1997
+ selectColumns.forEach((col) => {
1998
+ const duplicated = selectColumns.filter((orderBy) => orderBy.name === col.name);
1893
1999
  if (duplicated.length <= 1) {
1894
- const exists = orderByColumns.find(orderBy => orderBy == col.name);
2000
+ const exists = orderByColumns.find((orderBy) => orderBy === col.name);
1895
2001
  if (!exists) {
1896
2002
  orderByColumns.push(col.name);
1897
2003
  }
@@ -1901,7 +2007,7 @@ function getOrderByColumns(fromColumns, selectColumns) {
1901
2007
  }
1902
2008
  exports.getOrderByColumns = getOrderByColumns;
1903
2009
  function isAmbiguous(columns, columnName) {
1904
- const filterByName = columns.filter(col => col.columnName == columnName);
2010
+ const filterByName = columns.filter((col) => col.columnName === columnName);
1905
2011
  return filterByName.length > 1;
1906
2012
  }
1907
2013
  //# sourceMappingURL=traverse.js.map