typesql-cli 0.19.1 → 0.20.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 (50) hide show
  1. package/README.md +5 -0
  2. package/cli.js +66 -75
  3. package/cli.js.map +1 -1
  4. package/code-generator.d.ts +3 -2
  5. package/code-generator.d.ts.map +1 -1
  6. package/code-generator.js +29 -21
  7. package/code-generator.js.map +1 -1
  8. package/code-generator2.d.ts +5 -4
  9. package/code-generator2.d.ts.map +1 -1
  10. package/code-generator2.js +28 -26
  11. package/code-generator2.js.map +1 -1
  12. package/dialects/postgres.d.ts +1 -0
  13. package/dialects/postgres.d.ts.map +1 -1
  14. package/dialects/postgres.js +25 -8
  15. package/dialects/postgres.js.map +1 -1
  16. package/drivers/postgres.d.ts +2 -4
  17. package/drivers/postgres.d.ts.map +1 -1
  18. package/drivers/postgres.js +44 -55
  19. package/drivers/postgres.js.map +1 -1
  20. package/drivers/types.d.ts +4 -8
  21. package/drivers/types.d.ts.map +1 -1
  22. package/load-config.d.ts +6 -0
  23. package/load-config.d.ts.map +1 -1
  24. package/load-config.js +65 -1
  25. package/load-config.js.map +1 -1
  26. package/package.json +2 -1
  27. package/postgres-query-analyzer/describe.d.ts +2 -1
  28. package/postgres-query-analyzer/describe.d.ts.map +1 -1
  29. package/postgres-query-analyzer/describe.js +18 -23
  30. package/postgres-query-analyzer/describe.js.map +1 -1
  31. package/postgres-query-analyzer/traverse.d.ts +7 -3
  32. package/postgres-query-analyzer/traverse.d.ts.map +1 -1
  33. package/postgres-query-analyzer/traverse.js +242 -154
  34. package/postgres-query-analyzer/traverse.js.map +1 -1
  35. package/postgres-query-analyzer/types.d.ts +1 -0
  36. package/postgres-query-analyzer/types.d.ts.map +1 -1
  37. package/schema-info.d.ts +13 -5
  38. package/schema-info.d.ts.map +1 -1
  39. package/schema-info.js +26 -52
  40. package/schema-info.js.map +1 -1
  41. package/sqlite-query-analyzer/code-generator.d.ts +2 -2
  42. package/sqlite-query-analyzer/code-generator.d.ts.map +1 -1
  43. package/sqlite-query-analyzer/code-generator.js.map +1 -1
  44. package/sqlite-query-analyzer/types.d.ts +1 -1
  45. package/sqlite-query-analyzer/types.d.ts.map +1 -1
  46. package/ts-dynamic-query-descriptor.d.ts.map +1 -1
  47. package/ts-dynamic-query-descriptor.js +2 -1
  48. package/ts-dynamic-query-descriptor.js.map +1 -1
  49. package/types.d.ts +7 -0
  50. package/types.d.ts.map +1 -1
@@ -120,6 +120,7 @@ function traverse_selectstmt(selectstmt, context, traverseResult) {
120
120
  };
121
121
  }
122
122
  function traverse_select_no_parens(select_no_parens, context, traverseResult) {
123
+ var _a;
123
124
  const with_clause = select_no_parens.with_clause();
124
125
  if (with_clause) {
125
126
  with_clause.cte_list().common_table_expr_list()
@@ -137,11 +138,13 @@ function traverse_select_no_parens(select_no_parens, context, traverseResult) {
137
138
  const select_limit = select_no_parens.select_limit();
138
139
  if (select_limit) {
139
140
  const numParamsBefore = traverseResult.parameters.length;
140
- const limit_clause = select_limit.limit_clause();
141
- const limit_a_expr = limit_clause.select_limit_value().a_expr();
142
- traverse_a_expr(limit_a_expr, context, traverseResult);
143
141
  let fragment = '';
142
+ const limit_clause = select_limit.limit_clause();
144
143
  if (limit_clause) {
144
+ const limit_a_expr = (_a = limit_clause.select_limit_value()) === null || _a === void 0 ? void 0 : _a.a_expr();
145
+ if (limit_a_expr) {
146
+ traverse_a_expr(limit_a_expr, context, traverseResult);
147
+ }
145
148
  if (context.collectDynamicQueryInfo) {
146
149
  fragment += (0, select_columns_1.extractOriginalSql)(limit_clause);
147
150
  }
@@ -170,7 +173,7 @@ function traverse_common_table_expr(common_table_expr, context, traverseResult)
170
173
  const select_stmt = common_table_expr.preparablestmt().selectstmt();
171
174
  const numParamsBefore = traverseResult.parameters.length;
172
175
  const selectResult = traverse_selectstmt(select_stmt, Object.assign(Object.assign({}, context), { collectDynamicQueryInfo: false }), traverseResult);
173
- const columnsWithTalbeName = selectResult.columns.map(col => (Object.assign(Object.assign({}, col), { table_name: tableName })));
176
+ const columnsWithTalbeName = selectResult.columns.map(col => (Object.assign(Object.assign({}, col), { table: tableName })));
174
177
  if (context.collectDynamicQueryInfo) {
175
178
  const parameters = traverseResult.parameters.slice(numParamsBefore).map((_, index) => index + numParamsBefore);
176
179
  (_a = traverseResult.dynamicQueryInfo) === null || _a === void 0 ? void 0 : _a.with.push({
@@ -188,11 +191,11 @@ function traverse_select_clause(select_clause, context, traverseResult) {
188
191
  //union
189
192
  const { recursiveTableName, recursiveColumnNames } = context;
190
193
  const recursiveColumns = recursiveTableName ? mainSelectResult.columns
191
- .map((col, index) => { var _a; return (Object.assign(Object.assign({}, col), { table_name: recursiveTableName, column_name: (_a = recursiveColumnNames === null || recursiveColumnNames === void 0 ? void 0 : recursiveColumnNames[index]) !== null && _a !== void 0 ? _a : col.column_name })); }) : [];
194
+ .map((col, index) => { var _a; return (Object.assign(Object.assign({}, col), { table: recursiveTableName, column_name: (_a = recursiveColumnNames === null || recursiveColumnNames === void 0 ? void 0 : recursiveColumnNames[index]) !== null && _a !== void 0 ? _a : col.column_name })); }) : [];
192
195
  for (let index = 1; index < simple_select_intersect_list.length; index++) {
193
196
  const unionResult = traverse_simple_select_intersect(simple_select_intersect_list[index], Object.assign(Object.assign({}, context), { fromColumns: context.fromColumns.concat(recursiveColumns) }), traverseResult);
194
197
  columns = columns.map((value, columnIndex) => {
195
- const col = Object.assign({ column_name: value.column_name, is_nullable: value.is_nullable || unionResult.columns[columnIndex].is_nullable, table_name: '', table_schema: '', type: value.type }, (value.column_default && { column_default: value.column_default }));
198
+ const col = Object.assign({ column_name: value.column_name, is_nullable: value.is_nullable || unionResult.columns[columnIndex].is_nullable, table: '', schema: '', type: value.type }, (value.column_default && { column_default: value.column_default }));
196
199
  return col;
197
200
  });
198
201
  }
@@ -221,7 +224,7 @@ function traverse_simple_select_pramary(simple_select_pramary, context, traverse
221
224
  if (from_clause) {
222
225
  const where_clause = simple_select_pramary.where_clause();
223
226
  fromResult = traverse_from_clause(from_clause, context, traverseResult);
224
- fromResult.columns = where_clause != null ? fromResult.columns.map(field => checkIsNullable(where_clause, field)) : fromResult.columns;
227
+ fromResult.columns = where_clause != null ? fromResult.columns.map(field => (Object.assign(Object.assign({}, field), { is_nullable: !checkIsNotNull(where_clause, field, fromResult.columns) }))) : fromResult.columns;
225
228
  }
226
229
  const values_clause = simple_select_pramary.values_clause();
227
230
  if (values_clause) {
@@ -288,8 +291,8 @@ function computeNullability(values_result) {
288
291
  const result = values_result[0].map((_, i) => ({
289
292
  column_name: `column${i + 1}`,
290
293
  is_nullable: values_result.some(row => row[i].is_nullable),
291
- table_name: '',
292
- table_schema: '',
294
+ table: '',
295
+ schema: '',
293
296
  type: values_result[0][i].type
294
297
  }));
295
298
  return result;
@@ -327,9 +330,9 @@ function traverse_target_list(target_list, context, traverseResult) {
327
330
  columns.forEach(col => {
328
331
  var _a;
329
332
  (_a = traverseResult.dynamicQueryInfo) === null || _a === void 0 ? void 0 : _a.select.push({
330
- fragment: `${col.table_name}.${col.column_name}`,
331
- fragmentWitoutAlias: `${col.table_name}.${col.column_name}`,
332
- dependOnRelations: [col.table_name],
333
+ fragment: `${col.table}.${col.column_name}`,
334
+ fragmentWitoutAlias: `${col.table}.${col.column_name}`,
335
+ dependOnRelations: [col.table],
333
336
  parameters: []
334
337
  });
335
338
  });
@@ -354,7 +357,7 @@ function traverse_target_el(target_el, context, traverseResult) {
354
357
  const alias = colLabel != null ? get_colid_text(colLabel) : '';
355
358
  if (alias) {
356
359
  (_a = traverseResult.relations) === null || _a === void 0 ? void 0 : _a.forEach(relation => {
357
- if ((relation.name === exprResult.table_name || relation.alias === exprResult.table_name)
360
+ if ((relation.name === exprResult.table || relation.alias === exprResult.table)
358
361
  && relation.joinColumn === exprResult.column_name) {
359
362
  relation.joinColumn = alias;
360
363
  }
@@ -370,7 +373,7 @@ function traverse_target_el(target_el, context, traverseResult) {
370
373
  parameters
371
374
  });
372
375
  }
373
- return Object.assign(Object.assign(Object.assign({ column_name: alias || exprResult.column_name, is_nullable: exprResult.is_nullable, table_name: exprResult.table_name, table_schema: exprResult.table_schema, type: exprResult.type }, (exprResult.column_default != null) && { column_default: exprResult.column_default }), (exprResult.column_key != null && { column_key: exprResult.column_key })), (exprResult.jsonType != null && { jsonType: exprResult.jsonType }));
376
+ return Object.assign(Object.assign(Object.assign({ column_name: alias || exprResult.column_name, is_nullable: exprResult.is_nullable, table: exprResult.table, schema: exprResult.schema, type: exprResult.type }, (exprResult.column_default != null) && { column_default: exprResult.column_default }), (exprResult.column_key != null && { column_key: exprResult.column_key })), (exprResult.jsonType != null && { jsonType: exprResult.jsonType }));
374
377
  }
375
378
  throw Error('Column not found');
376
379
  }
@@ -383,8 +386,8 @@ function traverse_a_expr(a_expr, context, traverseResult) {
383
386
  return {
384
387
  column_name: '',
385
388
  is_nullable: true,
386
- table_name: '',
387
- table_schema: '',
389
+ table: '',
390
+ schema: '',
388
391
  type: 'unknown'
389
392
  };
390
393
  }
@@ -411,8 +414,8 @@ function traverse_expr_or(a_expr_or, context, traverseResult) {
411
414
  return {
412
415
  column_name: '?column?',
413
416
  is_nullable: result.some(col => col.is_nullable),
414
- table_name: '',
415
- table_schema: '',
417
+ table: '',
418
+ schema: '',
416
419
  type: 'bool'
417
420
  };
418
421
  }
@@ -424,8 +427,8 @@ function traverse_expr_and(a_expr_and, context, traverseResult) {
424
427
  return {
425
428
  column_name: '?column?',
426
429
  is_nullable: result.some(col => col.is_nullable),
427
- table_name: '',
428
- table_schema: '',
430
+ table: '',
431
+ schema: '',
429
432
  type: 'bool'
430
433
  };
431
434
  }
@@ -441,8 +444,8 @@ function traverse_expr_between(a_expr_between, context, traverseResult) {
441
444
  return {
442
445
  column_name: a_expr_between.getText(),
443
446
  is_nullable: false,
444
- table_name: '',
445
- table_schema: '',
447
+ table: '',
448
+ schema: '',
446
449
  type: 'bool'
447
450
  };
448
451
  }
@@ -464,8 +467,8 @@ function traverse_expr_in(a_expr_in, context, traverseResult) {
464
467
  //id in (...) -> is_nullable: false
465
468
  // value -> is_nullable = leftExprResult.is_nullable
466
469
  is_nullable: in_expr != null ? false : leftExprResult.is_nullable,
467
- table_name: '',
468
- table_schema: '',
470
+ table: '',
471
+ schema: '',
469
472
  type: 'bool'
470
473
  };
471
474
  }
@@ -516,7 +519,7 @@ function checkParamterNullability(column, traverseResult) {
516
519
  }
517
520
  }
518
521
  function getCheckConstraint(col, checkConstraints) {
519
- const key = `[${col.table_schema}][${col.table_name}][${col.column_name}]`;
522
+ const key = `[${col.schema}][${col.table}][${col.column_name}]`;
520
523
  return checkConstraints[key];
521
524
  }
522
525
  function traverse_expr_compare(a_expr_compare, context, traverseResult) {
@@ -539,8 +542,8 @@ function traverse_expr_compare(a_expr_compare, context, traverseResult) {
539
542
  return {
540
543
  column_name: '?column?',
541
544
  is_nullable: result.some(col => col.is_nullable),
542
- table_name: '',
543
- table_schema: '',
545
+ table: '',
546
+ schema: '',
544
547
  type: 'bool'
545
548
  };
546
549
  }
@@ -550,8 +553,8 @@ function traverse_expr_compare(a_expr_compare, context, traverseResult) {
550
553
  return {
551
554
  column_name: '?column?',
552
555
  is_nullable: result.columns.some(col => col.is_nullable),
553
- table_name: '',
554
- table_schema: '',
556
+ table: '',
557
+ schema: '',
555
558
  type: result.columns[0].type
556
559
  };
557
560
  }
@@ -561,8 +564,8 @@ function traverse_expr_compare(a_expr_compare, context, traverseResult) {
561
564
  return {
562
565
  column_name: '?column?',
563
566
  is_nullable: result.is_nullable,
564
- table_name: '',
565
- table_schema: '',
567
+ table: '',
568
+ schema: '',
566
569
  type: result.type
567
570
  };
568
571
  }
@@ -578,8 +581,8 @@ function traverse_expr_like(a_expr_like, context, traverseResult) {
578
581
  return {
579
582
  column_name: '?column?',
580
583
  is_nullable: result.some(col => col.is_nullable),
581
- table_name: '',
582
- table_schema: '',
584
+ table: '',
585
+ schema: '',
583
586
  type: 'unknown'
584
587
  };
585
588
  }
@@ -595,8 +598,8 @@ function traverse_expr_qual_op(a_expr_qual_op, context, traverseResult) {
595
598
  return {
596
599
  column_name: '?column?',
597
600
  is_nullable: result.some(col => col.is_nullable),
598
- table_name: '',
599
- table_schema: '',
601
+ table: '',
602
+ schema: '',
600
603
  type: 'unknown'
601
604
  };
602
605
  }
@@ -613,8 +616,8 @@ function traverse_expr_unary_qualop(a_expr_unary_qualop, context, traverseResult
613
616
  const result = {
614
617
  column_name: '?column?',
615
618
  is_nullable: exprResult.some(col => col.is_nullable),
616
- table_name: '',
617
- table_schema: '',
619
+ table: '',
620
+ schema: '',
618
621
  type: mapAddExprType(exprResult.map(exprResult => exprResult.type))
619
622
  };
620
623
  return result;
@@ -632,8 +635,8 @@ function traverse_expr_mul(a_expr_mul, context, traverseResult) {
632
635
  const result = {
633
636
  column_name: '?column?',
634
637
  is_nullable: exprResult.some(exprRes => exprRes.is_nullable),
635
- table_name: '',
636
- table_schema: '',
638
+ table: '',
639
+ schema: '',
637
640
  type: mapAddExprType(exprResult.map(exprResult => exprResult.type))
638
641
  };
639
642
  return result;
@@ -651,8 +654,8 @@ function traverse_expr_caret(a_expr_caret, context, traverseResult) {
651
654
  const result = {
652
655
  column_name: '?column?',
653
656
  is_nullable: notNullInfo.some(notNullInfo => notNullInfo.is_nullable),
654
- table_name: '',
655
- table_schema: '',
657
+ table: '',
658
+ schema: '',
656
659
  type: 'unknown'
657
660
  };
658
661
  return result;
@@ -689,8 +692,15 @@ function traverse_expr_typecast(a_expr_typecast, context, traverseResult) {
689
692
  }
690
693
  function traverseColumnRef(columnref, fromColumns) {
691
694
  const fieldName = getFieldName(columnref);
692
- const col = findColumn(fieldName, fromColumns);
693
- return Object.assign(Object.assign({}, col), { is_nullable: col.is_nullable });
695
+ const col = findColumnOrNull(fieldName, fromColumns);
696
+ if (col != null) {
697
+ return Object.assign(Object.assign({}, col), { is_nullable: col.is_nullable });
698
+ }
699
+ const record = findRecordOrNull(fieldName, fromColumns);
700
+ if (record != null) {
701
+ return record;
702
+ }
703
+ throw Error('Column not found: ' + fieldNameToString(fieldName));
694
704
  }
695
705
  function getFieldName(columnref) {
696
706
  const colid = get_colid_text(columnref.colid());
@@ -765,8 +775,8 @@ function traversec_expr(c_expr, context, traverseResult) {
765
775
  return {
766
776
  column_name: '?column?',
767
777
  is_nullable: false, //empty array
768
- table_schema: '',
769
- table_name: '',
778
+ schema: '',
779
+ table: '',
770
780
  type: 'unknown'
771
781
  };
772
782
  }
@@ -782,8 +792,8 @@ function traversec_expr(c_expr, context, traverseResult) {
782
792
  return {
783
793
  column_name: columnref.getText(),
784
794
  is_nullable: false,
785
- table_name: '',
786
- table_schema: '',
795
+ table: '',
796
+ schema: '',
787
797
  type: 'unknown'
788
798
  };
789
799
  }
@@ -793,8 +803,8 @@ function traversec_expr(c_expr, context, traverseResult) {
793
803
  return {
794
804
  column_name: columnref.getText(),
795
805
  is_nullable: false,
796
- table_name: '',
797
- table_schema: '',
806
+ table: '',
807
+ schema: '',
798
808
  type: 'record',
799
809
  recordTypes: columns
800
810
  };
@@ -811,8 +821,8 @@ function traversec_expr(c_expr, context, traverseResult) {
811
821
  return {
812
822
  column_name: name,
813
823
  is_nullable,
814
- table_name: '',
815
- table_schema: '',
824
+ table: '',
825
+ schema: '',
816
826
  type
817
827
  };
818
828
  }
@@ -824,8 +834,8 @@ function traversec_expr(c_expr, context, traverseResult) {
824
834
  return {
825
835
  column_name: c_expr.PARAM().getText(),
826
836
  is_nullable: !!context.propagatesNull,
827
- table_name: '',
828
- table_schema: '',
837
+ table: '',
838
+ schema: '',
829
839
  type: 'unknown'
830
840
  };
831
841
  }
@@ -847,7 +857,7 @@ function traversec_expr(c_expr, context, traverseResult) {
847
857
  const a_expr = filter_clause.a_expr();
848
858
  traverse_a_expr(a_expr, context, traverseResult);
849
859
  }
850
- return Object.assign(Object.assign({}, isNotNull), { table_name: '', table_schema: '' });
860
+ return Object.assign(Object.assign({}, isNotNull), { table: '', schema: '' });
851
861
  }
852
862
  const func_expr_common_subexpr = (_b = c_expr.func_expr()) === null || _b === void 0 ? void 0 : _b.func_expr_common_subexpr();
853
863
  if (func_expr_common_subexpr) {
@@ -863,8 +873,8 @@ function traversec_expr(c_expr, context, traverseResult) {
863
873
  return {
864
874
  column_name: '?column?',
865
875
  is_nullable,
866
- table_name: '',
867
- table_schema: '',
876
+ table: '',
877
+ schema: '',
868
878
  type: result.columns[0].type,
869
879
  jsonType: jsonType != null && jsonType.name === 'json' ? Object.assign(Object.assign({}, jsonType), { notNull: !is_nullable }) : jsonType
870
880
  };
@@ -880,8 +890,8 @@ function traversec_expr(c_expr, context, traverseResult) {
880
890
  return {
881
891
  column_name: '?column?',
882
892
  is_nullable: expr_list.some(col => col.is_nullable),
883
- table_name: '',
884
- table_schema: '',
893
+ table: '',
894
+ schema: '',
885
895
  type: 'record',
886
896
  recordTypes: expr_list.map(expr => (Object.assign(Object.assign({}, expr), { column_name: '' })))
887
897
  };
@@ -893,8 +903,8 @@ function traversec_expr(c_expr, context, traverseResult) {
893
903
  return {
894
904
  column_name: '?column?',
895
905
  is_nullable: expr_list.some(col => col.is_nullable),
896
- table_name: '',
897
- table_schema: '',
906
+ table: '',
907
+ schema: '',
898
908
  type: 'unknown'
899
909
  };
900
910
  }
@@ -909,17 +919,17 @@ function traversec_expr(c_expr, context, traverseResult) {
909
919
  return {
910
920
  column_name: '?column?',
911
921
  is_nullable: false,
912
- table_name: '',
913
- table_schema: '',
922
+ table: '',
923
+ schema: '',
914
924
  type: 'bool'
915
925
  };
916
926
  }
917
927
  throw Error('traversec_expr - Not expected:' + c_expr.getText());
918
928
  }
919
929
  function filterColumns(fromColumns, fieldName) {
920
- return fromColumns.filter(col => (fieldName.prefix === '' || col.table_name === fieldName.prefix)
930
+ return fromColumns.filter(col => (fieldName.prefix === '' || col.table === fieldName.prefix)
921
931
  && (fieldName.name === '*' || col.column_name === fieldName.name)).map(col => {
922
- const result = Object.assign(Object.assign(Object.assign({ column_name: col.column_name, is_nullable: col.is_nullable, table_name: col.table_name, table_schema: col.table_schema, type: col.type }, (col.column_key !== undefined) && { column_key: col.column_key }), (col.jsonType !== undefined) && { jsonType: col.jsonType }), (col.original_is_nullable !== undefined && { original_is_nullable: col.original_is_nullable }));
932
+ const result = Object.assign(Object.assign(Object.assign({ column_name: col.column_name, is_nullable: col.is_nullable, table: col.table, schema: col.schema, type: col.type }, (col.column_key !== undefined) && { column_key: col.column_key }), (col.jsonType !== undefined) && { jsonType: col.jsonType }), (col.original_is_nullable !== undefined && { original_is_nullable: col.original_is_nullable }));
923
933
  return result;
924
934
  });
925
935
  }
@@ -940,8 +950,8 @@ function traversec_expr_case(c_expr_case, context, traverseResult) {
940
950
  return {
941
951
  column_name: '?column?',
942
952
  is_nullable: !notNull,
943
- table_name: '',
944
- table_schema: '',
953
+ table: '',
954
+ schema: '',
945
955
  type: (_a = whenResult[0].type) !== null && _a !== void 0 ? _a : 'unknown',
946
956
  jsonType: allJsonTypesMatch(whenResult, elseResult) ? whenResult[0].jsonType : undefined
947
957
  };
@@ -979,8 +989,8 @@ function traversewhen_clause(when_clause, context, traverseResult) {
979
989
  return {
980
990
  column_name: '?column?',
981
991
  is_nullable: !notNull,
982
- table_name: '',
983
- table_schema: '',
992
+ table: '',
993
+ schema: '',
984
994
  type: whenExprResult[0].type,
985
995
  jsonType: whenExprResult[0].jsonType
986
996
  };
@@ -1027,10 +1037,10 @@ function mapJsonBuildArgsToJsonProperty(args, filterExpr) {
1027
1037
  }
1028
1038
  function inferJsonNullability(columns, filterExpr) {
1029
1039
  const tables = columns.filter(col => filterExpr && col.original_is_nullable === false
1030
- && isNotNull_a_expr({ name: col.column_name, prefix: col.table_name }, filterExpr))
1031
- .map(col => col.table_name);
1040
+ && isNotNull_a_expr({ name: col.column_name, prefix: col.table }, filterExpr))
1041
+ .map(col => col.table);
1032
1042
  const fields = columns.map(col => {
1033
- return col.original_is_nullable != null && tables.includes(col.table_name) ? !col.original_is_nullable : !col.is_nullable;
1043
+ return col.original_is_nullable != null && tables.includes(col.table) ? !col.original_is_nullable : !col.is_nullable;
1034
1044
  });
1035
1045
  return fields;
1036
1046
  }
@@ -1061,8 +1071,8 @@ function traverse_json_build_obj_func(func_application, context, traverseResult)
1061
1071
  const result = {
1062
1072
  column_name: columnName,
1063
1073
  is_nullable: false,
1064
- table_name: '',
1065
- table_schema: '',
1074
+ table: '',
1075
+ schema: '',
1066
1076
  type: 'json',
1067
1077
  jsonType: {
1068
1078
  name: 'json',
@@ -1080,8 +1090,8 @@ function traverse_json_agg(func_application, context, traverseResult) {
1080
1090
  const result = {
1081
1091
  column_name: columnName,
1082
1092
  is_nullable: context.filter_expr != null,
1083
- table_name: '',
1084
- table_schema: '',
1093
+ table: '',
1094
+ schema: '',
1085
1095
  type: 'json[]',
1086
1096
  jsonType: createJsonTypeForJsonAgg(argsResult[0], context.filter_expr)
1087
1097
  };
@@ -1117,8 +1127,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1117
1127
  return {
1118
1128
  column_name: functionName,
1119
1129
  is_nullable: false,
1120
- table_name: '',
1121
- table_schema: '',
1130
+ table: '',
1131
+ schema: '',
1122
1132
  type: 'json',
1123
1133
  jsonType
1124
1134
  };
@@ -1129,8 +1139,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1129
1139
  return {
1130
1140
  column_name: functionName,
1131
1141
  is_nullable: false,
1132
- table_name: '',
1133
- table_schema: '',
1142
+ table: '',
1143
+ schema: '',
1134
1144
  type: 'int8'
1135
1145
  };
1136
1146
  }
@@ -1139,8 +1149,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1139
1149
  return {
1140
1150
  column_name: functionName,
1141
1151
  is_nullable: argsResult.some(col => col.is_nullable),
1142
- table_name: '',
1143
- table_schema: '',
1152
+ table: '',
1153
+ schema: '',
1144
1154
  type: 'text'
1145
1155
  };
1146
1156
  }
@@ -1148,8 +1158,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1148
1158
  return {
1149
1159
  column_name: functionName,
1150
1160
  is_nullable: argsResult.some(col => col.is_nullable),
1151
- table_name: '',
1152
- table_schema: '',
1161
+ table: '',
1162
+ schema: '',
1153
1163
  type: 'tsvector'
1154
1164
  };
1155
1165
  }
@@ -1157,8 +1167,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1157
1167
  return {
1158
1168
  column_name: functionName,
1159
1169
  is_nullable: argsResult.some(col => col.is_nullable),
1160
- table_name: '',
1161
- table_schema: '',
1170
+ table: '',
1171
+ schema: '',
1162
1172
  type: 'float4'
1163
1173
  };
1164
1174
  }
@@ -1169,8 +1179,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1169
1179
  return {
1170
1180
  column_name: functionName,
1171
1181
  is_nullable: argsResult.some(col => col.is_nullable),
1172
- table_name: '',
1173
- table_schema: '',
1182
+ table: '',
1183
+ schema: '',
1174
1184
  type: 'tsquery'
1175
1185
  };
1176
1186
  }
@@ -1178,8 +1188,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1178
1188
  return {
1179
1189
  column_name: functionName,
1180
1190
  is_nullable: argsResult.some(col => col.is_nullable),
1181
- table_name: '',
1182
- table_schema: '',
1191
+ table: '',
1192
+ schema: '',
1183
1193
  type: 'date'
1184
1194
  };
1185
1195
  }
@@ -1187,8 +1197,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1187
1197
  return {
1188
1198
  column_name: functionName,
1189
1199
  is_nullable: false,
1190
- table_name: '',
1191
- table_schema: '',
1200
+ table: '',
1201
+ schema: '',
1192
1202
  type: 'unknown'
1193
1203
  };
1194
1204
  }
@@ -1198,8 +1208,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1198
1208
  return {
1199
1209
  column_name: functionName,
1200
1210
  is_nullable: false,
1201
- table_name: '',
1202
- table_schema: '',
1211
+ table: '',
1212
+ schema: '',
1203
1213
  type: 'int4'
1204
1214
  };
1205
1215
  }
@@ -1208,8 +1218,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1208
1218
  return {
1209
1219
  column_name: functionName,
1210
1220
  is_nullable: false,
1211
- table_name: '',
1212
- table_schema: '',
1221
+ table: '',
1222
+ schema: '',
1213
1223
  type: 'float8'
1214
1224
  };
1215
1225
  }
@@ -1224,8 +1234,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1224
1234
  return {
1225
1235
  column_name: functionName,
1226
1236
  is_nullable: false,
1227
- table_name: '',
1228
- table_schema: '',
1237
+ table: '',
1238
+ schema: '',
1229
1239
  type: 'json[]',
1230
1240
  jsonType: {
1231
1241
  name: 'json[]',
@@ -1237,8 +1247,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1237
1247
  return {
1238
1248
  column_name: functionName,
1239
1249
  is_nullable: true,
1240
- table_name: '',
1241
- table_schema: '',
1250
+ table: '',
1251
+ schema: '',
1242
1252
  type: 'json'
1243
1253
  };
1244
1254
  }
@@ -1249,8 +1259,8 @@ function traversefunc_application(func_application, context, traverseResult) {
1249
1259
  return {
1250
1260
  column_name: functionName,
1251
1261
  is_nullable: false,
1252
- table_name: '',
1253
- table_schema: '',
1262
+ table: '',
1263
+ schema: '',
1254
1264
  type: 'json',
1255
1265
  jsonType: {
1256
1266
  name: 'json_map',
@@ -1263,15 +1273,15 @@ function traversefunc_application(func_application, context, traverseResult) {
1263
1273
  column_name: functionName,
1264
1274
  is_nullable: argsResult[0].is_nullable,
1265
1275
  type: argsResult[0].type,
1266
- table_name: '',
1267
- table_schema: ''
1276
+ table: '',
1277
+ schema: ''
1268
1278
  };
1269
1279
  }
1270
1280
  return {
1271
1281
  column_name: functionName,
1272
1282
  is_nullable: true,
1273
- table_name: '',
1274
- table_schema: '',
1283
+ table: '',
1284
+ schema: '',
1275
1285
  type: 'unknown'
1276
1286
  };
1277
1287
  }
@@ -1294,7 +1304,7 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
1294
1304
  const paramResult = traverse_a_expr(func_arg_expr, Object.assign(Object.assign({}, context), { propagatesNull: true }), traverseResult);
1295
1305
  return paramResult;
1296
1306
  });
1297
- return Object.assign(Object.assign({}, result[0]), { is_nullable: result.every(col => col.is_nullable), table_name: '', table_schema: '' });
1307
+ return Object.assign(Object.assign({}, result[0]), { is_nullable: result.every(col => col.is_nullable), table: '', schema: '' });
1298
1308
  }
1299
1309
  if (func_expr_common_subexpr.EXTRACT()) {
1300
1310
  const a_expr = func_expr_common_subexpr.extract_list().a_expr();
@@ -1302,8 +1312,8 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
1302
1312
  return {
1303
1313
  column_name: 'extract',
1304
1314
  is_nullable: result.is_nullable,
1305
- table_name: '',
1306
- table_schema: '',
1315
+ table: '',
1316
+ schema: '',
1307
1317
  type: 'float8'
1308
1318
  };
1309
1319
  }
@@ -1313,8 +1323,8 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
1313
1323
  return {
1314
1324
  column_name: func_expr_common_subexpr.getText(),
1315
1325
  is_nullable: true,
1316
- table_name: '',
1317
- table_schema: '',
1326
+ table: '',
1327
+ schema: '',
1318
1328
  type: 'unknown'
1319
1329
  };
1320
1330
  }
@@ -1326,18 +1336,18 @@ function traverse_array_expr(array_expr, context, traverseResult) {
1326
1336
  const expr_list = array_expr.expr_list();
1327
1337
  if (expr_list) {
1328
1338
  const traverse_expr_list_result = traverse_expr_list(expr_list, context, traverseResult);
1329
- return Object.assign(Object.assign({}, traverse_expr_list_result[0]), { is_nullable: traverse_expr_list_result.some(expr => expr.is_nullable), column_name: '?column?', table_name: '', table_schema: '' });
1339
+ return Object.assign(Object.assign({}, traverse_expr_list_result[0]), { is_nullable: traverse_expr_list_result.some(expr => expr.is_nullable), column_name: '?column?', table: '', schema: '' });
1330
1340
  }
1331
1341
  const array_expr_list = array_expr.array_expr_list();
1332
1342
  if (array_expr_list) {
1333
1343
  const traverse_array_expr_list_result = traverse_array_expr_list(array_expr_list, context, traverseResult);
1334
- return Object.assign(Object.assign({}, traverse_array_expr_list_result[0]), { column_name: '?column?', table_name: '', table_schema: '' });
1344
+ return Object.assign(Object.assign({}, traverse_array_expr_list_result[0]), { column_name: '?column?', table: '', schema: '' });
1335
1345
  }
1336
1346
  return {
1337
1347
  column_name: array_expr.getText(),
1338
1348
  is_nullable: true,
1339
- table_name: '',
1340
- table_schema: '',
1349
+ table: '',
1350
+ schema: '',
1341
1351
  type: 'unknown'
1342
1352
  };
1343
1353
  }
@@ -1355,16 +1365,38 @@ function findColumn(fieldName, fromColumns) {
1355
1365
  return col;
1356
1366
  }
1357
1367
  function findColumnOrNull(fieldName, fromColumns) {
1358
- const col = fromColumns.find(col => (fieldName.prefix === '' || col.table_name.toLowerCase() === fieldName.prefix.toLowerCase()) && col.column_name.toLowerCase() === fieldName.name.toLowerCase());
1368
+ const col = fromColumns.find(col => (fieldName.prefix === '' || col.table.toLowerCase() === fieldName.prefix.toLowerCase()) && col.column_name.toLowerCase() === fieldName.name.toLowerCase());
1359
1369
  return col;
1360
1370
  }
1371
+ function findRecordOrNull(fieldName, fromColumns) {
1372
+ const table = fromColumns.filter(col => col.table.toLowerCase() === fieldName.name.toLowerCase()
1373
+ || fieldName.name === '*' && col.table === fieldName.prefix);
1374
+ if (table.length === 0) {
1375
+ return null;
1376
+ }
1377
+ return Object.assign(Object.assign({}, table[0]), { recordTypes: table });
1378
+ }
1361
1379
  function fieldNameToString(fieldName) {
1362
1380
  return fieldName.prefix !== '' ? `${fieldName.prefix}.${fieldName.name}` : fieldName.name;
1363
1381
  }
1364
- function checkIsNullable(where_clause, field) {
1365
- const isNotNullResult = !field.is_nullable || isNotNull({ name: field.column_name, prefix: field.table_name }, where_clause);
1366
- const col = Object.assign(Object.assign({}, field), { is_nullable: !isNotNullResult });
1367
- return col;
1382
+ function checkIsNotNull(where_clause, field, fromColumns) {
1383
+ if (!field.is_nullable) {
1384
+ return true;
1385
+ }
1386
+ const fieldName = { name: field.column_name, prefix: field.table };
1387
+ const isNotNullExpr = isNotNull(fieldName, where_clause);
1388
+ if (!isNotNullExpr) {
1389
+ return false; //notNull: true
1390
+ }
1391
+ const col = findColumnOrNull(fieldName, fromColumns);
1392
+ if (col != null) {
1393
+ return true; //notNull: true
1394
+ }
1395
+ const record = findRecordOrNull({ name: fieldName.prefix, prefix: '' }, fromColumns);
1396
+ if (record != null) {
1397
+ return true; //notNull: true
1398
+ }
1399
+ return false;
1368
1400
  }
1369
1401
  function traverse_from_clause(from_clause, context, traverseResult) {
1370
1402
  const from_list = from_clause.from_list();
@@ -1378,16 +1410,22 @@ function traverse_from_clause(from_clause, context, traverseResult) {
1378
1410
  };
1379
1411
  }
1380
1412
  function traverse_from_list(from_list, context, traverseResult) {
1381
- const fromListResult = from_list.table_ref_list().map(table_ref => traverse_table_ref(table_ref, context, traverseResult));
1382
- const columns = fromListResult.flatMap(tableRes => tableRes.columns);
1413
+ const tableRefs = from_list.table_ref_list();
1414
+ const columns = [];
1415
+ let singleRow = false;
1416
+ for (const table_ref of tableRefs) {
1417
+ const result = traverse_table_ref(table_ref, Object.assign(Object.assign({}, context), { parentColumns: columns }), traverseResult);
1418
+ columns.push(...result.columns);
1419
+ singleRow = result.singleRow;
1420
+ }
1383
1421
  return {
1384
1422
  columns: columns,
1385
- singleRow: fromListResult.length === 1 ? fromListResult[0].singleRow : false
1423
+ singleRow: tableRefs.length === 1 ? singleRow : false
1386
1424
  };
1387
1425
  }
1388
1426
  function getFromColumns(tableName, withColumns, dbSchema) {
1389
- const filteredWithColumns = withColumns.filter(col => col.table_name.toLowerCase() === tableName.name.toLowerCase());
1390
- const filteredSchema = filteredWithColumns.length > 0 ? filteredWithColumns : dbSchema.filter(col => col.table_name.toLowerCase() === tableName.name.toLowerCase());
1427
+ const filteredWithColumns = withColumns.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase());
1428
+ const filteredSchema = filteredWithColumns.length > 0 ? filteredWithColumns : dbSchema.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase());
1391
1429
  return filteredSchema;
1392
1430
  }
1393
1431
  function checkLeftJoinIsNullable(leftJoin, subsequentJoins, fromColumns) {
@@ -1432,7 +1470,7 @@ function traverse_table_ref(table_ref, context, traverseResult) {
1432
1470
  const tableName = traverse_relation_expr(relation_expr);
1433
1471
  const fromColumns = getFromColumns(tableName, context.fromColumns.concat(context.withColumns), context.dbSchema);
1434
1472
  const tableNameWithAlias = alias ? alias : tableName.name;
1435
- const fromColumnsResult = fromColumns.map(col => (Object.assign(Object.assign({}, col), { table_name: tableNameWithAlias.toLowerCase() })));
1473
+ const fromColumnsResult = fromColumns.map(col => (Object.assign(Object.assign({}, col), { table: tableNameWithAlias.toLowerCase() })));
1436
1474
  allColumns.push(...fromColumnsResult);
1437
1475
  singleRow = false;
1438
1476
  if (context.collectNestedInfo) {
@@ -1471,7 +1509,7 @@ function traverse_table_ref(table_ref, context, traverseResult) {
1471
1509
  const aliasClause = table_ref.alias_clause();
1472
1510
  if (aliasClause) {
1473
1511
  const alias = aliasClause.colid().getText();
1474
- joinColumns.forEach(col => col.table_name = alias.toLowerCase());
1512
+ joinColumns.forEach(col => col.table = alias.toLowerCase());
1475
1513
  }
1476
1514
  allColumns.push(...joinColumns);
1477
1515
  singleRow = false;
@@ -1517,7 +1555,7 @@ function traverse_select_with_parens_or_func_table(tableRef, context, traverseRe
1517
1555
  if (func_table) {
1518
1556
  const funcAlias = ((_c = (_b = (_a = tableRef.func_alias_clause()) === null || _a === void 0 ? void 0 : _a.alias_clause()) === null || _b === void 0 ? void 0 : _b.colid()) === null || _c === void 0 ? void 0 : _c.getText()) || '';
1519
1557
  const result = traverse_func_table(func_table, context, traverseResult);
1520
- const resultWithAlias = result.columns.map(col => (Object.assign(Object.assign({}, col), { table_name: funcAlias || col.table_name })));
1558
+ const resultWithAlias = result.columns.map(col => (Object.assign(Object.assign({}, col), { table: funcAlias || col.table })));
1521
1559
  return {
1522
1560
  columns: resultWithAlias,
1523
1561
  singleRow: result.singleRow
@@ -1528,7 +1566,7 @@ function traverse_select_with_parens_or_func_table(tableRef, context, traverseRe
1528
1566
  const columns = traverse_select_with_parens(select_with_parens, Object.assign(Object.assign({}, context), { collectDynamicQueryInfo: false }), traverseResult);
1529
1567
  const aliasNameList = (_f = (_e = (_d = tableRef.alias_clause()) === null || _d === void 0 ? void 0 : _d.name_list()) === null || _e === void 0 ? void 0 : _e.name_list()) === null || _f === void 0 ? void 0 : _f.map(name => name.getText());
1530
1568
  const alias = (_h = (_g = tableRef.alias_clause()) === null || _g === void 0 ? void 0 : _g.colid().getText()) !== null && _h !== void 0 ? _h : '';
1531
- const withAlias = columns.columns.map((col, i) => (Object.assign(Object.assign({}, col), { column_name: (aliasNameList === null || aliasNameList === void 0 ? void 0 : aliasNameList[i]) || col.column_name, table_name: alias || col.table_name })));
1569
+ const withAlias = columns.columns.map((col, i) => (Object.assign(Object.assign({}, col), { column_name: (aliasNameList === null || aliasNameList === void 0 ? void 0 : aliasNameList[i]) || col.column_name, table: alias || col.table })));
1532
1570
  return {
1533
1571
  columns: withAlias,
1534
1572
  singleRow: false
@@ -1659,38 +1697,79 @@ function parseReturnType(returnType) {
1659
1697
  if (setofMatch) {
1660
1698
  return { kind: 'setof', table: setofMatch[1] };
1661
1699
  }
1700
+ else {
1701
+ return { kind: 'table_name', table: trimmed };
1702
+ }
1662
1703
  throw new Error(`Unsupported return type format: ${returnType}`);
1663
1704
  }
1705
+ function handleFunctionReturn(dbSchema, returnType) {
1706
+ switch (returnType.kind) {
1707
+ case 'table':
1708
+ const columns = handleTableReturnType(returnType);
1709
+ return {
1710
+ columns,
1711
+ singleRow: false
1712
+ };
1713
+ case 'setof':
1714
+ case 'table_name':
1715
+ const tableName = (0, select_columns_1.splitName)(returnType.table);
1716
+ const setOfColumns = dbSchema.filter(col => col.table.toLowerCase() === tableName.name && tableName.prefix === '' || col.schema === tableName.prefix);
1717
+ return {
1718
+ columns: setOfColumns,
1719
+ singleRow: false
1720
+ };
1721
+ }
1722
+ }
1723
+ function handleTableReturnType(returnType) {
1724
+ const columns = returnType.columns.map(col => {
1725
+ const columnInfo = {
1726
+ column_name: col.name,
1727
+ type: col.type,
1728
+ is_nullable: true,
1729
+ table: '',
1730
+ schema: ''
1731
+ };
1732
+ return columnInfo;
1733
+ });
1734
+ return columns;
1735
+ }
1736
+ function parseArgumentList(argString) {
1737
+ return argString
1738
+ .split(',')
1739
+ .map(arg => arg.trim())
1740
+ .filter(arg => arg.length > 0)
1741
+ .map(arg => {
1742
+ const [name, ...typeParts] = arg.split(/\s+/);
1743
+ return {
1744
+ name,
1745
+ type: typeParts.join(' ') // Handles multi-word types like "character varying"
1746
+ };
1747
+ });
1748
+ }
1664
1749
  function traverse_func_expr_windowless(func_expr_windowless, context, traverseResult) {
1665
1750
  const func_application = func_expr_windowless.func_application();
1666
1751
  if (func_application) {
1667
- const func_name = func_application.func_name().getText().toLowerCase();
1668
- const funcSchema = context.userFunctions.find(func => func.function_name.toLowerCase() === func_name);
1752
+ const func_name = (0, select_columns_1.splitName)(func_application.func_name().getText().toLowerCase());
1753
+ const funcSchema = context.userFunctions.find(func => func.function_name.toLowerCase() === func_name.name && (func_name.prefix === '' || func_name.prefix === func.schema));
1669
1754
  if (funcSchema) {
1670
1755
  const definition = funcSchema.definition;
1671
1756
  const returnType = parseReturnType(funcSchema.return_type);
1672
- const functionColumns = returnType.kind === 'table' ? returnType.columns.map(col => {
1673
- const columnInfo = {
1674
- column_name: col.name,
1675
- type: col.type,
1676
- is_nullable: true,
1677
- table_name: '',
1678
- table_schema: ''
1679
- };
1680
- return columnInfo;
1681
- }) : context.dbSchema.filter(col => col.table_name.toLowerCase() === returnType.table);
1757
+ const argList = parseArgumentList(funcSchema.arguments);
1758
+ const functionResult = handleFunctionReturn(context.dbSchema, returnType);
1682
1759
  if (funcSchema.language.toLowerCase() === 'sql') {
1683
1760
  const parser = (0, postgres_1.parseSql)(definition);
1684
1761
  const selectstmt = parser.stmt().selectstmt();
1685
- const { columns, multipleRowsResult } = traverseSelectstmt(selectstmt, context, traverseResult);
1762
+ const params = argList.map(arg => ({ column_name: arg.name, type: arg.type, is_nullable: false, schema: funcSchema.schema, table: '$' }));
1763
+ const newFromColumns = params.concat(context.fromColumns);
1764
+ const { columns, multipleRowsResult } = traverseSelectstmt(selectstmt, Object.assign(Object.assign({}, context), { fromColumns: newFromColumns }), traverseResult);
1686
1765
  return {
1687
- columns: columns.map((c) => (Object.assign(Object.assign({}, c), { table_name: funcSchema.function_name }))),
1766
+ columns: columns.map((c) => (Object.assign(Object.assign({}, c), { table: funcSchema.function_name }))),
1688
1767
  singleRow: !multipleRowsResult
1689
1768
  };
1690
1769
  }
1691
1770
  else {
1692
1771
  return {
1693
- columns: functionColumns,
1772
+ columns: functionResult.columns.map((c) => (Object.assign(Object.assign({}, c), { table: funcSchema.function_name, schema: funcSchema.schema }))),
1694
1773
  singleRow: false
1695
1774
  };
1696
1775
  }
@@ -1737,6 +1816,9 @@ function get_indiretion_text(indirection) {
1737
1816
  if (colLabel) {
1738
1817
  return get_colid_text(colLabel);
1739
1818
  }
1819
+ if (indirection_el_list[0].STAR()) {
1820
+ return '*';
1821
+ }
1740
1822
  }
1741
1823
  return '';
1742
1824
  }
@@ -1787,8 +1869,8 @@ function traverseInsertstmt(insertstmt, dbSchema) {
1787
1869
  parameters: []
1788
1870
  };
1789
1871
  const insert_target = insertstmt.insert_target();
1790
- const tableName = insert_target.getText();
1791
- const insertColumns = dbSchema.filter(col => col.table_name.toLowerCase() === tableName.toLowerCase());
1872
+ const tableName = (0, select_columns_1.splitName)(insert_target.getText());
1873
+ const insertColumns = filterSchemaColumns(dbSchema, tableName);
1792
1874
  const insert_rest = insertstmt.insert_rest();
1793
1875
  const insertColumnsList = insert_rest.insert_column_list()
1794
1876
  .insert_column_item_list()
@@ -1828,8 +1910,8 @@ function traverseInsertstmt(insertstmt, dbSchema) {
1828
1910
  function traverseDeletestmt(deleteStmt, dbSchema, traverseResult) {
1829
1911
  var _a;
1830
1912
  const relation_expr = deleteStmt.relation_expr_opt_alias().relation_expr();
1831
- const tableName = relation_expr.getText();
1832
- const deleteColumns = dbSchema.filter(col => col.table_name.toLowerCase() === tableName.toLowerCase());
1913
+ const tableName = (0, select_columns_1.splitName)(relation_expr.getText());
1914
+ const deleteColumns = filterSchemaColumns(dbSchema, tableName);
1833
1915
  const paramIsListResult = getInParameterList(deleteStmt);
1834
1916
  const returning_clause = deleteStmt.returning_clause();
1835
1917
  const context = {
@@ -1862,13 +1944,17 @@ function traverseDeletestmt(deleteStmt, dbSchema, traverseResult) {
1862
1944
  function addConstraintIfNotNull(checkConstraint) {
1863
1945
  return checkConstraint !== undefined ? { checkConstraint } : undefined;
1864
1946
  }
1947
+ function filterSchemaColumns(dbSchema, tableName) {
1948
+ return dbSchema.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase()
1949
+ && (tableName.prefix === '' || col.schema.toLowerCase() === tableName.prefix.toLowerCase()));
1950
+ }
1865
1951
  function traverseUpdatestmt(updatestmt, traverseContext, traverseResult) {
1866
1952
  var _a;
1867
1953
  const relation_expr_opt_alias = updatestmt.relation_expr_opt_alias();
1868
- const tableName = relation_expr_opt_alias.relation_expr().getText();
1954
+ const tableName = (0, select_columns_1.splitName)(relation_expr_opt_alias.relation_expr().getText());
1869
1955
  const tableAlias = ((_a = relation_expr_opt_alias.colid()) === null || _a === void 0 ? void 0 : _a.getText()) || '';
1870
- const updateColumns = traverseContext.dbSchema.filter(col => col.table_name.toLowerCase() === tableName.toLowerCase())
1871
- .map(col => (Object.assign(Object.assign({}, col), { table_name: tableAlias || col.table_name })));
1956
+ const updateColumns = filterSchemaColumns(traverseContext.dbSchema, tableName)
1957
+ .map(col => (Object.assign(Object.assign({}, col), { table: tableAlias || col.table })));
1872
1958
  const context = Object.assign(Object.assign({}, traverseContext), { fromColumns: updateColumns, collectNestedInfo: false, collectDynamicQueryInfo: false });
1873
1959
  updatestmt.set_clause_list().set_clause_list()
1874
1960
  .forEach(set_clause => traverse_set_clause(set_clause, context, traverseResult));
@@ -1902,7 +1988,7 @@ function traverse_set_clause(set_clause, context, traverseResult) {
1902
1988
  const columnName = (0, select_columns_1.splitName)(set_target.getText());
1903
1989
  const column = findColumn(columnName, context.fromColumns);
1904
1990
  const a_expr = set_clause.a_expr();
1905
- const excludedColumns = context.fromColumns.map((col) => (Object.assign(Object.assign({}, col), { table_name: 'excluded' })));
1991
+ const excludedColumns = context.fromColumns.map((col) => (Object.assign(Object.assign({}, col), { table: 'excluded' })));
1906
1992
  const a_exprResult = traverse_a_expr(a_expr, Object.assign(Object.assign({}, context), { fromColumns: context.fromColumns.concat(excludedColumns) }), traverseResult);
1907
1993
  if (isParameter(a_exprResult.column_name)) {
1908
1994
  traverseResult.parameters.at(-1).isNotNull = !column.is_nullable;
@@ -1985,7 +2071,7 @@ function isNotNull_a_expr_in(a_expr_in, field) {
1985
2071
  }
1986
2072
  function isNotNull_a_expr_unary_not(a_expr_unary_not, field) {
1987
2073
  const a_expr_isnull = a_expr_unary_not.a_expr_isnull();
1988
- if (a_expr_isnull) {
2074
+ if (!a_expr_unary_not.NOT() && a_expr_isnull) {
1989
2075
  return isNotNull_a_expr_isnull(a_expr_isnull, field);
1990
2076
  }
1991
2077
  return false;
@@ -2124,7 +2210,9 @@ function isNotNull_c_expr(c_expr, field) {
2124
2210
  const columnref = c_expr.columnref();
2125
2211
  if (columnref) {
2126
2212
  const fieldName = getFieldName(columnref);
2127
- return (fieldName.name === field.name && (fieldName.prefix === '' || field.prefix === fieldName.prefix));
2213
+ const fieldIsNotNull = (fieldName.name === field.name && (fieldName.prefix === '' || field.prefix === fieldName.prefix));
2214
+ const tableIsNotNull = (fieldName.name === '*' && fieldName.prefix === field.prefix) || fieldName.name === field.prefix;
2215
+ return fieldIsNotNull || tableIsNotNull;
2128
2216
  }
2129
2217
  const aexprconst = c_expr.aexprconst();
2130
2218
  if (aexprconst) {
@@ -2441,7 +2529,7 @@ function checkLimit(selectstmt) {
2441
2529
  function traverseCopystmt(copyStmt, dbSchema, traverseResult) {
2442
2530
  var _a, _b;
2443
2531
  const tableName = copyStmt.qualified_name().getText();
2444
- const copyColumns = dbSchema.filter(col => col.table_name.toLowerCase() === tableName.toLowerCase());
2532
+ const copyColumns = dbSchema.filter(col => col.table.toLowerCase() === tableName.toLowerCase());
2445
2533
  const columnlist = (_b = (_a = copyStmt.column_list_()) === null || _a === void 0 ? void 0 : _a.columnlist()) === null || _b === void 0 ? void 0 : _b.columnElem_list().map(columnElem => traverse_columnElem(columnElem, copyColumns, traverseResult));
2446
2534
  return {
2447
2535
  queryType: 'Copy',