typesql-cli 0.19.1 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +23 -19
- package/cli.js.map +1 -1
- package/code-generator.d.ts +3 -2
- package/code-generator.d.ts.map +1 -1
- package/code-generator.js +27 -20
- package/code-generator.js.map +1 -1
- package/code-generator2.d.ts +5 -4
- package/code-generator2.d.ts.map +1 -1
- package/code-generator2.js +13 -13
- package/code-generator2.js.map +1 -1
- package/dialects/postgres.d.ts +1 -0
- package/dialects/postgres.d.ts.map +1 -1
- package/dialects/postgres.js +25 -8
- package/dialects/postgres.js.map +1 -1
- package/drivers/postgres.d.ts +2 -4
- package/drivers/postgres.d.ts.map +1 -1
- package/drivers/postgres.js +44 -55
- package/drivers/postgres.js.map +1 -1
- package/drivers/types.d.ts +4 -8
- package/drivers/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/postgres-query-analyzer/describe.d.ts +2 -1
- package/postgres-query-analyzer/describe.d.ts.map +1 -1
- package/postgres-query-analyzer/describe.js +18 -23
- package/postgres-query-analyzer/describe.js.map +1 -1
- package/postgres-query-analyzer/traverse.d.ts +7 -3
- package/postgres-query-analyzer/traverse.d.ts.map +1 -1
- package/postgres-query-analyzer/traverse.js +191 -143
- package/postgres-query-analyzer/traverse.js.map +1 -1
- package/postgres-query-analyzer/types.d.ts +1 -0
- package/postgres-query-analyzer/types.d.ts.map +1 -1
- package/schema-info.d.ts +13 -5
- package/schema-info.d.ts.map +1 -1
- package/schema-info.js +26 -52
- package/schema-info.js.map +1 -1
- package/sqlite-query-analyzer/code-generator.d.ts +2 -2
- package/sqlite-query-analyzer/code-generator.d.ts.map +1 -1
- package/sqlite-query-analyzer/code-generator.js.map +1 -1
- package/sqlite-query-analyzer/types.d.ts +1 -1
- package/sqlite-query-analyzer/types.d.ts.map +1 -1
- package/types.d.ts +6 -0
- 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), {
|
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), {
|
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,
|
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
|
}
|
@@ -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
|
-
|
292
|
-
|
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.
|
331
|
-
fragmentWitoutAlias: `${col.
|
332
|
-
dependOnRelations: [col.
|
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.
|
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,
|
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
|
-
|
387
|
-
|
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
|
-
|
415
|
-
|
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
|
-
|
428
|
-
|
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
|
-
|
445
|
-
|
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
|
-
|
468
|
-
|
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.
|
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
|
-
|
543
|
-
|
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
|
-
|
554
|
-
|
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
|
-
|
565
|
-
|
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
|
-
|
582
|
-
|
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
|
-
|
599
|
-
|
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
|
-
|
617
|
-
|
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
|
-
|
636
|
-
|
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
|
-
|
655
|
-
|
657
|
+
table: '',
|
658
|
+
schema: '',
|
656
659
|
type: 'unknown'
|
657
660
|
};
|
658
661
|
return result;
|
@@ -765,8 +768,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
765
768
|
return {
|
766
769
|
column_name: '?column?',
|
767
770
|
is_nullable: false, //empty array
|
768
|
-
|
769
|
-
|
771
|
+
schema: '',
|
772
|
+
table: '',
|
770
773
|
type: 'unknown'
|
771
774
|
};
|
772
775
|
}
|
@@ -782,8 +785,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
782
785
|
return {
|
783
786
|
column_name: columnref.getText(),
|
784
787
|
is_nullable: false,
|
785
|
-
|
786
|
-
|
788
|
+
table: '',
|
789
|
+
schema: '',
|
787
790
|
type: 'unknown'
|
788
791
|
};
|
789
792
|
}
|
@@ -793,8 +796,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
793
796
|
return {
|
794
797
|
column_name: columnref.getText(),
|
795
798
|
is_nullable: false,
|
796
|
-
|
797
|
-
|
799
|
+
table: '',
|
800
|
+
schema: '',
|
798
801
|
type: 'record',
|
799
802
|
recordTypes: columns
|
800
803
|
};
|
@@ -811,8 +814,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
811
814
|
return {
|
812
815
|
column_name: name,
|
813
816
|
is_nullable,
|
814
|
-
|
815
|
-
|
817
|
+
table: '',
|
818
|
+
schema: '',
|
816
819
|
type
|
817
820
|
};
|
818
821
|
}
|
@@ -824,8 +827,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
824
827
|
return {
|
825
828
|
column_name: c_expr.PARAM().getText(),
|
826
829
|
is_nullable: !!context.propagatesNull,
|
827
|
-
|
828
|
-
|
830
|
+
table: '',
|
831
|
+
schema: '',
|
829
832
|
type: 'unknown'
|
830
833
|
};
|
831
834
|
}
|
@@ -847,7 +850,7 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
847
850
|
const a_expr = filter_clause.a_expr();
|
848
851
|
traverse_a_expr(a_expr, context, traverseResult);
|
849
852
|
}
|
850
|
-
return Object.assign(Object.assign({}, isNotNull), {
|
853
|
+
return Object.assign(Object.assign({}, isNotNull), { table: '', schema: '' });
|
851
854
|
}
|
852
855
|
const func_expr_common_subexpr = (_b = c_expr.func_expr()) === null || _b === void 0 ? void 0 : _b.func_expr_common_subexpr();
|
853
856
|
if (func_expr_common_subexpr) {
|
@@ -863,8 +866,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
863
866
|
return {
|
864
867
|
column_name: '?column?',
|
865
868
|
is_nullable,
|
866
|
-
|
867
|
-
|
869
|
+
table: '',
|
870
|
+
schema: '',
|
868
871
|
type: result.columns[0].type,
|
869
872
|
jsonType: jsonType != null && jsonType.name === 'json' ? Object.assign(Object.assign({}, jsonType), { notNull: !is_nullable }) : jsonType
|
870
873
|
};
|
@@ -880,8 +883,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
880
883
|
return {
|
881
884
|
column_name: '?column?',
|
882
885
|
is_nullable: expr_list.some(col => col.is_nullable),
|
883
|
-
|
884
|
-
|
886
|
+
table: '',
|
887
|
+
schema: '',
|
885
888
|
type: 'record',
|
886
889
|
recordTypes: expr_list.map(expr => (Object.assign(Object.assign({}, expr), { column_name: '' })))
|
887
890
|
};
|
@@ -893,8 +896,8 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
893
896
|
return {
|
894
897
|
column_name: '?column?',
|
895
898
|
is_nullable: expr_list.some(col => col.is_nullable),
|
896
|
-
|
897
|
-
|
899
|
+
table: '',
|
900
|
+
schema: '',
|
898
901
|
type: 'unknown'
|
899
902
|
};
|
900
903
|
}
|
@@ -909,17 +912,17 @@ function traversec_expr(c_expr, context, traverseResult) {
|
|
909
912
|
return {
|
910
913
|
column_name: '?column?',
|
911
914
|
is_nullable: false,
|
912
|
-
|
913
|
-
|
915
|
+
table: '',
|
916
|
+
schema: '',
|
914
917
|
type: 'bool'
|
915
918
|
};
|
916
919
|
}
|
917
920
|
throw Error('traversec_expr - Not expected:' + c_expr.getText());
|
918
921
|
}
|
919
922
|
function filterColumns(fromColumns, fieldName) {
|
920
|
-
return fromColumns.filter(col => (fieldName.prefix === '' || col.
|
923
|
+
return fromColumns.filter(col => (fieldName.prefix === '' || col.table === fieldName.prefix)
|
921
924
|
&& (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,
|
925
|
+
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
926
|
return result;
|
924
927
|
});
|
925
928
|
}
|
@@ -940,8 +943,8 @@ function traversec_expr_case(c_expr_case, context, traverseResult) {
|
|
940
943
|
return {
|
941
944
|
column_name: '?column?',
|
942
945
|
is_nullable: !notNull,
|
943
|
-
|
944
|
-
|
946
|
+
table: '',
|
947
|
+
schema: '',
|
945
948
|
type: (_a = whenResult[0].type) !== null && _a !== void 0 ? _a : 'unknown',
|
946
949
|
jsonType: allJsonTypesMatch(whenResult, elseResult) ? whenResult[0].jsonType : undefined
|
947
950
|
};
|
@@ -979,8 +982,8 @@ function traversewhen_clause(when_clause, context, traverseResult) {
|
|
979
982
|
return {
|
980
983
|
column_name: '?column?',
|
981
984
|
is_nullable: !notNull,
|
982
|
-
|
983
|
-
|
985
|
+
table: '',
|
986
|
+
schema: '',
|
984
987
|
type: whenExprResult[0].type,
|
985
988
|
jsonType: whenExprResult[0].jsonType
|
986
989
|
};
|
@@ -1027,10 +1030,10 @@ function mapJsonBuildArgsToJsonProperty(args, filterExpr) {
|
|
1027
1030
|
}
|
1028
1031
|
function inferJsonNullability(columns, filterExpr) {
|
1029
1032
|
const tables = columns.filter(col => filterExpr && col.original_is_nullable === false
|
1030
|
-
&& isNotNull_a_expr({ name: col.column_name, prefix: col.
|
1031
|
-
.map(col => col.
|
1033
|
+
&& isNotNull_a_expr({ name: col.column_name, prefix: col.table }, filterExpr))
|
1034
|
+
.map(col => col.table);
|
1032
1035
|
const fields = columns.map(col => {
|
1033
|
-
return col.original_is_nullable != null && tables.includes(col.
|
1036
|
+
return col.original_is_nullable != null && tables.includes(col.table) ? !col.original_is_nullable : !col.is_nullable;
|
1034
1037
|
});
|
1035
1038
|
return fields;
|
1036
1039
|
}
|
@@ -1061,8 +1064,8 @@ function traverse_json_build_obj_func(func_application, context, traverseResult)
|
|
1061
1064
|
const result = {
|
1062
1065
|
column_name: columnName,
|
1063
1066
|
is_nullable: false,
|
1064
|
-
|
1065
|
-
|
1067
|
+
table: '',
|
1068
|
+
schema: '',
|
1066
1069
|
type: 'json',
|
1067
1070
|
jsonType: {
|
1068
1071
|
name: 'json',
|
@@ -1080,8 +1083,8 @@ function traverse_json_agg(func_application, context, traverseResult) {
|
|
1080
1083
|
const result = {
|
1081
1084
|
column_name: columnName,
|
1082
1085
|
is_nullable: context.filter_expr != null,
|
1083
|
-
|
1084
|
-
|
1086
|
+
table: '',
|
1087
|
+
schema: '',
|
1085
1088
|
type: 'json[]',
|
1086
1089
|
jsonType: createJsonTypeForJsonAgg(argsResult[0], context.filter_expr)
|
1087
1090
|
};
|
@@ -1117,8 +1120,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1117
1120
|
return {
|
1118
1121
|
column_name: functionName,
|
1119
1122
|
is_nullable: false,
|
1120
|
-
|
1121
|
-
|
1123
|
+
table: '',
|
1124
|
+
schema: '',
|
1122
1125
|
type: 'json',
|
1123
1126
|
jsonType
|
1124
1127
|
};
|
@@ -1129,8 +1132,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1129
1132
|
return {
|
1130
1133
|
column_name: functionName,
|
1131
1134
|
is_nullable: false,
|
1132
|
-
|
1133
|
-
|
1135
|
+
table: '',
|
1136
|
+
schema: '',
|
1134
1137
|
type: 'int8'
|
1135
1138
|
};
|
1136
1139
|
}
|
@@ -1139,8 +1142,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1139
1142
|
return {
|
1140
1143
|
column_name: functionName,
|
1141
1144
|
is_nullable: argsResult.some(col => col.is_nullable),
|
1142
|
-
|
1143
|
-
|
1145
|
+
table: '',
|
1146
|
+
schema: '',
|
1144
1147
|
type: 'text'
|
1145
1148
|
};
|
1146
1149
|
}
|
@@ -1148,8 +1151,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1148
1151
|
return {
|
1149
1152
|
column_name: functionName,
|
1150
1153
|
is_nullable: argsResult.some(col => col.is_nullable),
|
1151
|
-
|
1152
|
-
|
1154
|
+
table: '',
|
1155
|
+
schema: '',
|
1153
1156
|
type: 'tsvector'
|
1154
1157
|
};
|
1155
1158
|
}
|
@@ -1157,8 +1160,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1157
1160
|
return {
|
1158
1161
|
column_name: functionName,
|
1159
1162
|
is_nullable: argsResult.some(col => col.is_nullable),
|
1160
|
-
|
1161
|
-
|
1163
|
+
table: '',
|
1164
|
+
schema: '',
|
1162
1165
|
type: 'float4'
|
1163
1166
|
};
|
1164
1167
|
}
|
@@ -1169,8 +1172,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1169
1172
|
return {
|
1170
1173
|
column_name: functionName,
|
1171
1174
|
is_nullable: argsResult.some(col => col.is_nullable),
|
1172
|
-
|
1173
|
-
|
1175
|
+
table: '',
|
1176
|
+
schema: '',
|
1174
1177
|
type: 'tsquery'
|
1175
1178
|
};
|
1176
1179
|
}
|
@@ -1178,8 +1181,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1178
1181
|
return {
|
1179
1182
|
column_name: functionName,
|
1180
1183
|
is_nullable: argsResult.some(col => col.is_nullable),
|
1181
|
-
|
1182
|
-
|
1184
|
+
table: '',
|
1185
|
+
schema: '',
|
1183
1186
|
type: 'date'
|
1184
1187
|
};
|
1185
1188
|
}
|
@@ -1187,8 +1190,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1187
1190
|
return {
|
1188
1191
|
column_name: functionName,
|
1189
1192
|
is_nullable: false,
|
1190
|
-
|
1191
|
-
|
1193
|
+
table: '',
|
1194
|
+
schema: '',
|
1192
1195
|
type: 'unknown'
|
1193
1196
|
};
|
1194
1197
|
}
|
@@ -1198,8 +1201,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1198
1201
|
return {
|
1199
1202
|
column_name: functionName,
|
1200
1203
|
is_nullable: false,
|
1201
|
-
|
1202
|
-
|
1204
|
+
table: '',
|
1205
|
+
schema: '',
|
1203
1206
|
type: 'int4'
|
1204
1207
|
};
|
1205
1208
|
}
|
@@ -1208,8 +1211,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1208
1211
|
return {
|
1209
1212
|
column_name: functionName,
|
1210
1213
|
is_nullable: false,
|
1211
|
-
|
1212
|
-
|
1214
|
+
table: '',
|
1215
|
+
schema: '',
|
1213
1216
|
type: 'float8'
|
1214
1217
|
};
|
1215
1218
|
}
|
@@ -1224,8 +1227,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1224
1227
|
return {
|
1225
1228
|
column_name: functionName,
|
1226
1229
|
is_nullable: false,
|
1227
|
-
|
1228
|
-
|
1230
|
+
table: '',
|
1231
|
+
schema: '',
|
1229
1232
|
type: 'json[]',
|
1230
1233
|
jsonType: {
|
1231
1234
|
name: 'json[]',
|
@@ -1237,8 +1240,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1237
1240
|
return {
|
1238
1241
|
column_name: functionName,
|
1239
1242
|
is_nullable: true,
|
1240
|
-
|
1241
|
-
|
1243
|
+
table: '',
|
1244
|
+
schema: '',
|
1242
1245
|
type: 'json'
|
1243
1246
|
};
|
1244
1247
|
}
|
@@ -1249,8 +1252,8 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1249
1252
|
return {
|
1250
1253
|
column_name: functionName,
|
1251
1254
|
is_nullable: false,
|
1252
|
-
|
1253
|
-
|
1255
|
+
table: '',
|
1256
|
+
schema: '',
|
1254
1257
|
type: 'json',
|
1255
1258
|
jsonType: {
|
1256
1259
|
name: 'json_map',
|
@@ -1263,15 +1266,15 @@ function traversefunc_application(func_application, context, traverseResult) {
|
|
1263
1266
|
column_name: functionName,
|
1264
1267
|
is_nullable: argsResult[0].is_nullable,
|
1265
1268
|
type: argsResult[0].type,
|
1266
|
-
|
1267
|
-
|
1269
|
+
table: '',
|
1270
|
+
schema: ''
|
1268
1271
|
};
|
1269
1272
|
}
|
1270
1273
|
return {
|
1271
1274
|
column_name: functionName,
|
1272
1275
|
is_nullable: true,
|
1273
|
-
|
1274
|
-
|
1276
|
+
table: '',
|
1277
|
+
schema: '',
|
1275
1278
|
type: 'unknown'
|
1276
1279
|
};
|
1277
1280
|
}
|
@@ -1294,7 +1297,7 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
|
|
1294
1297
|
const paramResult = traverse_a_expr(func_arg_expr, Object.assign(Object.assign({}, context), { propagatesNull: true }), traverseResult);
|
1295
1298
|
return paramResult;
|
1296
1299
|
});
|
1297
|
-
return Object.assign(Object.assign({}, result[0]), { is_nullable: result.every(col => col.is_nullable),
|
1300
|
+
return Object.assign(Object.assign({}, result[0]), { is_nullable: result.every(col => col.is_nullable), table: '', schema: '' });
|
1298
1301
|
}
|
1299
1302
|
if (func_expr_common_subexpr.EXTRACT()) {
|
1300
1303
|
const a_expr = func_expr_common_subexpr.extract_list().a_expr();
|
@@ -1302,8 +1305,8 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
|
|
1302
1305
|
return {
|
1303
1306
|
column_name: 'extract',
|
1304
1307
|
is_nullable: result.is_nullable,
|
1305
|
-
|
1306
|
-
|
1308
|
+
table: '',
|
1309
|
+
schema: '',
|
1307
1310
|
type: 'float8'
|
1308
1311
|
};
|
1309
1312
|
}
|
@@ -1313,8 +1316,8 @@ function traversefunc_expr_common_subexpr(func_expr_common_subexpr, context, tra
|
|
1313
1316
|
return {
|
1314
1317
|
column_name: func_expr_common_subexpr.getText(),
|
1315
1318
|
is_nullable: true,
|
1316
|
-
|
1317
|
-
|
1319
|
+
table: '',
|
1320
|
+
schema: '',
|
1318
1321
|
type: 'unknown'
|
1319
1322
|
};
|
1320
1323
|
}
|
@@ -1326,18 +1329,18 @@ function traverse_array_expr(array_expr, context, traverseResult) {
|
|
1326
1329
|
const expr_list = array_expr.expr_list();
|
1327
1330
|
if (expr_list) {
|
1328
1331
|
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?',
|
1332
|
+
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
1333
|
}
|
1331
1334
|
const array_expr_list = array_expr.array_expr_list();
|
1332
1335
|
if (array_expr_list) {
|
1333
1336
|
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?',
|
1337
|
+
return Object.assign(Object.assign({}, traverse_array_expr_list_result[0]), { column_name: '?column?', table: '', schema: '' });
|
1335
1338
|
}
|
1336
1339
|
return {
|
1337
1340
|
column_name: array_expr.getText(),
|
1338
1341
|
is_nullable: true,
|
1339
|
-
|
1340
|
-
|
1342
|
+
table: '',
|
1343
|
+
schema: '',
|
1341
1344
|
type: 'unknown'
|
1342
1345
|
};
|
1343
1346
|
}
|
@@ -1355,14 +1358,14 @@ function findColumn(fieldName, fromColumns) {
|
|
1355
1358
|
return col;
|
1356
1359
|
}
|
1357
1360
|
function findColumnOrNull(fieldName, fromColumns) {
|
1358
|
-
const col = fromColumns.find(col => (fieldName.prefix === '' || col.
|
1361
|
+
const col = fromColumns.find(col => (fieldName.prefix === '' || col.table.toLowerCase() === fieldName.prefix.toLowerCase()) && col.column_name.toLowerCase() === fieldName.name.toLowerCase());
|
1359
1362
|
return col;
|
1360
1363
|
}
|
1361
1364
|
function fieldNameToString(fieldName) {
|
1362
1365
|
return fieldName.prefix !== '' ? `${fieldName.prefix}.${fieldName.name}` : fieldName.name;
|
1363
1366
|
}
|
1364
1367
|
function checkIsNullable(where_clause, field) {
|
1365
|
-
const isNotNullResult = !field.is_nullable || isNotNull({ name: field.column_name, prefix: field.
|
1368
|
+
const isNotNullResult = !field.is_nullable || isNotNull({ name: field.column_name, prefix: field.table }, where_clause);
|
1366
1369
|
const col = Object.assign(Object.assign({}, field), { is_nullable: !isNotNullResult });
|
1367
1370
|
return col;
|
1368
1371
|
}
|
@@ -1386,8 +1389,8 @@ function traverse_from_list(from_list, context, traverseResult) {
|
|
1386
1389
|
};
|
1387
1390
|
}
|
1388
1391
|
function getFromColumns(tableName, withColumns, dbSchema) {
|
1389
|
-
const filteredWithColumns = withColumns.filter(col => col.
|
1390
|
-
const filteredSchema = filteredWithColumns.length > 0 ? filteredWithColumns : dbSchema.filter(col => col.
|
1392
|
+
const filteredWithColumns = withColumns.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase());
|
1393
|
+
const filteredSchema = filteredWithColumns.length > 0 ? filteredWithColumns : dbSchema.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase());
|
1391
1394
|
return filteredSchema;
|
1392
1395
|
}
|
1393
1396
|
function checkLeftJoinIsNullable(leftJoin, subsequentJoins, fromColumns) {
|
@@ -1432,7 +1435,7 @@ function traverse_table_ref(table_ref, context, traverseResult) {
|
|
1432
1435
|
const tableName = traverse_relation_expr(relation_expr);
|
1433
1436
|
const fromColumns = getFromColumns(tableName, context.fromColumns.concat(context.withColumns), context.dbSchema);
|
1434
1437
|
const tableNameWithAlias = alias ? alias : tableName.name;
|
1435
|
-
const fromColumnsResult = fromColumns.map(col => (Object.assign(Object.assign({}, col), {
|
1438
|
+
const fromColumnsResult = fromColumns.map(col => (Object.assign(Object.assign({}, col), { table: tableNameWithAlias.toLowerCase() })));
|
1436
1439
|
allColumns.push(...fromColumnsResult);
|
1437
1440
|
singleRow = false;
|
1438
1441
|
if (context.collectNestedInfo) {
|
@@ -1471,7 +1474,7 @@ function traverse_table_ref(table_ref, context, traverseResult) {
|
|
1471
1474
|
const aliasClause = table_ref.alias_clause();
|
1472
1475
|
if (aliasClause) {
|
1473
1476
|
const alias = aliasClause.colid().getText();
|
1474
|
-
joinColumns.forEach(col => col.
|
1477
|
+
joinColumns.forEach(col => col.table = alias.toLowerCase());
|
1475
1478
|
}
|
1476
1479
|
allColumns.push(...joinColumns);
|
1477
1480
|
singleRow = false;
|
@@ -1517,7 +1520,7 @@ function traverse_select_with_parens_or_func_table(tableRef, context, traverseRe
|
|
1517
1520
|
if (func_table) {
|
1518
1521
|
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
1522
|
const result = traverse_func_table(func_table, context, traverseResult);
|
1520
|
-
const resultWithAlias = result.columns.map(col => (Object.assign(Object.assign({}, col), {
|
1523
|
+
const resultWithAlias = result.columns.map(col => (Object.assign(Object.assign({}, col), { table: funcAlias || col.table })));
|
1521
1524
|
return {
|
1522
1525
|
columns: resultWithAlias,
|
1523
1526
|
singleRow: result.singleRow
|
@@ -1528,7 +1531,7 @@ function traverse_select_with_parens_or_func_table(tableRef, context, traverseRe
|
|
1528
1531
|
const columns = traverse_select_with_parens(select_with_parens, Object.assign(Object.assign({}, context), { collectDynamicQueryInfo: false }), traverseResult);
|
1529
1532
|
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
1533
|
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,
|
1534
|
+
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
1535
|
return {
|
1533
1536
|
columns: withAlias,
|
1534
1537
|
singleRow: false
|
@@ -1659,38 +1662,79 @@ function parseReturnType(returnType) {
|
|
1659
1662
|
if (setofMatch) {
|
1660
1663
|
return { kind: 'setof', table: setofMatch[1] };
|
1661
1664
|
}
|
1665
|
+
else {
|
1666
|
+
return { kind: 'table_name', table: trimmed };
|
1667
|
+
}
|
1662
1668
|
throw new Error(`Unsupported return type format: ${returnType}`);
|
1663
1669
|
}
|
1670
|
+
function handleFunctionReturn(dbSchema, returnType) {
|
1671
|
+
switch (returnType.kind) {
|
1672
|
+
case 'table':
|
1673
|
+
const columns = handleTableReturnType(returnType);
|
1674
|
+
return {
|
1675
|
+
columns,
|
1676
|
+
singleRow: false
|
1677
|
+
};
|
1678
|
+
case 'setof':
|
1679
|
+
case 'table_name':
|
1680
|
+
const tableName = (0, select_columns_1.splitName)(returnType.table);
|
1681
|
+
const setOfColumns = dbSchema.filter(col => col.table.toLowerCase() === tableName.name && tableName.prefix === '' || col.schema === tableName.prefix);
|
1682
|
+
return {
|
1683
|
+
columns: setOfColumns,
|
1684
|
+
singleRow: false
|
1685
|
+
};
|
1686
|
+
}
|
1687
|
+
}
|
1688
|
+
function handleTableReturnType(returnType) {
|
1689
|
+
const columns = returnType.columns.map(col => {
|
1690
|
+
const columnInfo = {
|
1691
|
+
column_name: col.name,
|
1692
|
+
type: col.type,
|
1693
|
+
is_nullable: true,
|
1694
|
+
table: '',
|
1695
|
+
schema: ''
|
1696
|
+
};
|
1697
|
+
return columnInfo;
|
1698
|
+
});
|
1699
|
+
return columns;
|
1700
|
+
}
|
1701
|
+
function parseArgumentList(argString) {
|
1702
|
+
return argString
|
1703
|
+
.split(',')
|
1704
|
+
.map(arg => arg.trim())
|
1705
|
+
.filter(arg => arg.length > 0)
|
1706
|
+
.map(arg => {
|
1707
|
+
const [name, ...typeParts] = arg.split(/\s+/);
|
1708
|
+
return {
|
1709
|
+
name,
|
1710
|
+
type: typeParts.join(' ') // Handles multi-word types like "character varying"
|
1711
|
+
};
|
1712
|
+
});
|
1713
|
+
}
|
1664
1714
|
function traverse_func_expr_windowless(func_expr_windowless, context, traverseResult) {
|
1665
1715
|
const func_application = func_expr_windowless.func_application();
|
1666
1716
|
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);
|
1717
|
+
const func_name = (0, select_columns_1.splitName)(func_application.func_name().getText().toLowerCase());
|
1718
|
+
const funcSchema = context.userFunctions.find(func => func.function_name.toLowerCase() === func_name.name && (func_name.prefix === '' || func_name.prefix === func.schema));
|
1669
1719
|
if (funcSchema) {
|
1670
1720
|
const definition = funcSchema.definition;
|
1671
1721
|
const returnType = parseReturnType(funcSchema.return_type);
|
1672
|
-
const
|
1673
|
-
|
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);
|
1722
|
+
const argList = parseArgumentList(funcSchema.arguments);
|
1723
|
+
const functionResult = handleFunctionReturn(context.dbSchema, returnType);
|
1682
1724
|
if (funcSchema.language.toLowerCase() === 'sql') {
|
1683
1725
|
const parser = (0, postgres_1.parseSql)(definition);
|
1684
1726
|
const selectstmt = parser.stmt().selectstmt();
|
1685
|
-
const {
|
1727
|
+
const params = argList.map(arg => ({ column_name: arg.name, type: arg.type, is_nullable: false, schema: funcSchema.schema, table: '$' }));
|
1728
|
+
const newFromColumns = params.concat(context.fromColumns);
|
1729
|
+
const { columns, multipleRowsResult } = traverseSelectstmt(selectstmt, Object.assign(Object.assign({}, context), { fromColumns: newFromColumns }), traverseResult);
|
1686
1730
|
return {
|
1687
|
-
columns: columns.map((c) => (Object.assign(Object.assign({}, c), {
|
1731
|
+
columns: columns.map((c) => (Object.assign(Object.assign({}, c), { table: funcSchema.function_name }))),
|
1688
1732
|
singleRow: !multipleRowsResult
|
1689
1733
|
};
|
1690
1734
|
}
|
1691
1735
|
else {
|
1692
1736
|
return {
|
1693
|
-
columns:
|
1737
|
+
columns: functionResult.columns.map((c) => (Object.assign(Object.assign({}, c), { table: funcSchema.function_name, schema: funcSchema.schema }))),
|
1694
1738
|
singleRow: false
|
1695
1739
|
};
|
1696
1740
|
}
|
@@ -1787,8 +1831,8 @@ function traverseInsertstmt(insertstmt, dbSchema) {
|
|
1787
1831
|
parameters: []
|
1788
1832
|
};
|
1789
1833
|
const insert_target = insertstmt.insert_target();
|
1790
|
-
const tableName = insert_target.getText();
|
1791
|
-
const insertColumns = dbSchema
|
1834
|
+
const tableName = (0, select_columns_1.splitName)(insert_target.getText());
|
1835
|
+
const insertColumns = filterSchemaColumns(dbSchema, tableName);
|
1792
1836
|
const insert_rest = insertstmt.insert_rest();
|
1793
1837
|
const insertColumnsList = insert_rest.insert_column_list()
|
1794
1838
|
.insert_column_item_list()
|
@@ -1828,8 +1872,8 @@ function traverseInsertstmt(insertstmt, dbSchema) {
|
|
1828
1872
|
function traverseDeletestmt(deleteStmt, dbSchema, traverseResult) {
|
1829
1873
|
var _a;
|
1830
1874
|
const relation_expr = deleteStmt.relation_expr_opt_alias().relation_expr();
|
1831
|
-
const tableName = relation_expr.getText();
|
1832
|
-
const deleteColumns = dbSchema
|
1875
|
+
const tableName = (0, select_columns_1.splitName)(relation_expr.getText());
|
1876
|
+
const deleteColumns = filterSchemaColumns(dbSchema, tableName);
|
1833
1877
|
const paramIsListResult = getInParameterList(deleteStmt);
|
1834
1878
|
const returning_clause = deleteStmt.returning_clause();
|
1835
1879
|
const context = {
|
@@ -1862,13 +1906,17 @@ function traverseDeletestmt(deleteStmt, dbSchema, traverseResult) {
|
|
1862
1906
|
function addConstraintIfNotNull(checkConstraint) {
|
1863
1907
|
return checkConstraint !== undefined ? { checkConstraint } : undefined;
|
1864
1908
|
}
|
1909
|
+
function filterSchemaColumns(dbSchema, tableName) {
|
1910
|
+
return dbSchema.filter(col => col.table.toLowerCase() === tableName.name.toLowerCase()
|
1911
|
+
&& (tableName.prefix === '' || col.schema.toLowerCase() === tableName.prefix.toLowerCase()));
|
1912
|
+
}
|
1865
1913
|
function traverseUpdatestmt(updatestmt, traverseContext, traverseResult) {
|
1866
1914
|
var _a;
|
1867
1915
|
const relation_expr_opt_alias = updatestmt.relation_expr_opt_alias();
|
1868
|
-
const tableName = relation_expr_opt_alias.relation_expr().getText();
|
1916
|
+
const tableName = (0, select_columns_1.splitName)(relation_expr_opt_alias.relation_expr().getText());
|
1869
1917
|
const tableAlias = ((_a = relation_expr_opt_alias.colid()) === null || _a === void 0 ? void 0 : _a.getText()) || '';
|
1870
|
-
const updateColumns = traverseContext.dbSchema
|
1871
|
-
.map(col => (Object.assign(Object.assign({}, col), {
|
1918
|
+
const updateColumns = filterSchemaColumns(traverseContext.dbSchema, tableName)
|
1919
|
+
.map(col => (Object.assign(Object.assign({}, col), { table: tableAlias || col.table })));
|
1872
1920
|
const context = Object.assign(Object.assign({}, traverseContext), { fromColumns: updateColumns, collectNestedInfo: false, collectDynamicQueryInfo: false });
|
1873
1921
|
updatestmt.set_clause_list().set_clause_list()
|
1874
1922
|
.forEach(set_clause => traverse_set_clause(set_clause, context, traverseResult));
|
@@ -1902,7 +1950,7 @@ function traverse_set_clause(set_clause, context, traverseResult) {
|
|
1902
1950
|
const columnName = (0, select_columns_1.splitName)(set_target.getText());
|
1903
1951
|
const column = findColumn(columnName, context.fromColumns);
|
1904
1952
|
const a_expr = set_clause.a_expr();
|
1905
|
-
const excludedColumns = context.fromColumns.map((col) => (Object.assign(Object.assign({}, col), {
|
1953
|
+
const excludedColumns = context.fromColumns.map((col) => (Object.assign(Object.assign({}, col), { table: 'excluded' })));
|
1906
1954
|
const a_exprResult = traverse_a_expr(a_expr, Object.assign(Object.assign({}, context), { fromColumns: context.fromColumns.concat(excludedColumns) }), traverseResult);
|
1907
1955
|
if (isParameter(a_exprResult.column_name)) {
|
1908
1956
|
traverseResult.parameters.at(-1).isNotNull = !column.is_nullable;
|
@@ -2441,7 +2489,7 @@ function checkLimit(selectstmt) {
|
|
2441
2489
|
function traverseCopystmt(copyStmt, dbSchema, traverseResult) {
|
2442
2490
|
var _a, _b;
|
2443
2491
|
const tableName = copyStmt.qualified_name().getText();
|
2444
|
-
const copyColumns = dbSchema.filter(col => col.
|
2492
|
+
const copyColumns = dbSchema.filter(col => col.table.toLowerCase() === tableName.toLowerCase());
|
2445
2493
|
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
2494
|
return {
|
2447
2495
|
queryType: 'Copy',
|