prostgles-server 4.2.448 → 4.2.449
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/dist/DboBuilder/DboBuilderTypes.d.ts +6 -2
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions/COMPUTED_FIELDS.js +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions/COMPUTED_FIELDS.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions/Functions.d.ts +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions/Functions.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions/Functions.js +31 -31
- package/dist/DboBuilder/QueryBuilder/Functions/Functions.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts +5 -5
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.d.ts +2 -1
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.js +12 -10
- package/dist/DboBuilder/QueryBuilder/getJoinQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts +2 -2
- package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js +2 -2
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -12
- package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
- package/dist/DboBuilder/TableRules/getValidatedRules.js +3 -3
- package/dist/DboBuilder/TableRules/getValidatedRules.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseComplexFilter.d.ts +2 -2
- package/dist/DboBuilder/ViewHandler/parseComplexFilter.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/parseComplexFilter.js +3 -3
- package/dist/DboBuilder/ViewHandler/parseComplexFilter.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts +2 -2
- package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js +6 -4
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts +2 -2
- package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.d.ts +2 -2
- package/dist/DboBuilder/getCondition.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.js +6 -6
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.js +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
- package/dist/Filtering.d.ts +1 -1
- package/dist/Filtering.d.ts.map +1 -1
- package/dist/Filtering.js +3 -3
- package/dist/Filtering.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/eslint.config.mjs +2 -2
- package/lib/DboBuilder/DboBuilderTypes.ts +7 -2
- package/lib/DboBuilder/QueryBuilder/Functions/COMPUTED_FIELDS.ts +1 -1
- package/lib/DboBuilder/QueryBuilder/Functions/Functions.ts +66 -62
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +6 -6
- package/lib/DboBuilder/QueryBuilder/getJoinQuery.ts +16 -12
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +5 -5
- package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +11 -17
- package/lib/DboBuilder/TableRules/getValidatedRules.ts +9 -9
- package/lib/DboBuilder/ViewHandler/parseComplexFilter.ts +4 -4
- package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +14 -12
- package/lib/DboBuilder/ViewHandler/prepareWhere.ts +6 -6
- package/lib/DboBuilder/getCondition.ts +8 -12
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +1 -1
- package/lib/Filtering.ts +11 -13
- package/lib/PublishParser/getSchemaFromPublish.ts +1 -1
- package/package.json +18 -18
|
@@ -16,7 +16,7 @@ type GetQueryArgs = {
|
|
|
16
16
|
allColumns: ColumnInfo[];
|
|
17
17
|
allowedFields: string[];
|
|
18
18
|
args: any[];
|
|
19
|
-
|
|
19
|
+
tableAliasRaw?: string;
|
|
20
20
|
ctidField?: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -81,7 +81,7 @@ const parseUnix = (
|
|
|
81
81
|
colName: string,
|
|
82
82
|
tableAlias: string | undefined,
|
|
83
83
|
allColumns: ColumnInfo[],
|
|
84
|
-
opts: { timeZone: boolean | string } | undefined
|
|
84
|
+
opts: { timeZone: boolean | string } | undefined,
|
|
85
85
|
) => {
|
|
86
86
|
let tz = "";
|
|
87
87
|
if (opts) {
|
|
@@ -116,7 +116,7 @@ const JSON_Funcs: FunctionSpec[] = [
|
|
|
116
116
|
getFields: ([column]) => column,
|
|
117
117
|
getQuery: ({
|
|
118
118
|
args: [colName, path = [], new_value, create_missing = true],
|
|
119
|
-
tableAlias,
|
|
119
|
+
tableAliasRaw: tableAlias,
|
|
120
120
|
allowedFields,
|
|
121
121
|
}) => {
|
|
122
122
|
if (!allowedFields.includes(colName)) {
|
|
@@ -143,7 +143,11 @@ const JSON_Funcs: FunctionSpec[] = [
|
|
|
143
143
|
numArgs: 4,
|
|
144
144
|
type: "function",
|
|
145
145
|
getFields: ([column]) => column,
|
|
146
|
-
getQuery: ({
|
|
146
|
+
getQuery: ({
|
|
147
|
+
args: [colName, jsonPath, ...otherArgs],
|
|
148
|
+
tableAliasRaw: tableAlias,
|
|
149
|
+
allowedFields,
|
|
150
|
+
}) => {
|
|
147
151
|
if (!includes(allowedFields, colName)) {
|
|
148
152
|
throw `Unexpected: column ${colName} not found`;
|
|
149
153
|
}
|
|
@@ -187,11 +191,11 @@ const JSON_Funcs: FunctionSpec[] = [
|
|
|
187
191
|
numArgs: 1,
|
|
188
192
|
type: "function",
|
|
189
193
|
getFields: ([col]) => col,
|
|
190
|
-
getQuery: ({ args: [colName], tableAlias }) => {
|
|
194
|
+
getQuery: ({ args: [colName], tableAliasRaw: tableAlias }) => {
|
|
191
195
|
const escapedName = asNameAlias(colName, tableAlias);
|
|
192
196
|
return `${name}(${escapedName})`;
|
|
193
197
|
},
|
|
194
|
-
}) as FunctionSpec
|
|
198
|
+
}) as FunctionSpec,
|
|
195
199
|
),
|
|
196
200
|
];
|
|
197
201
|
|
|
@@ -283,7 +287,7 @@ let PostGIS_Funcs: FunctionSpec[] = (
|
|
|
283
287
|
numArgs: 1,
|
|
284
288
|
canBeUsedForFilter: fname === "ST_DWithin",
|
|
285
289
|
getFields: (args: any[]) => [args[0]],
|
|
286
|
-
getQuery: ({ allColumns, args: [columnName, arg2], tableAlias }) => {
|
|
290
|
+
getQuery: ({ allColumns, args: [columnName, arg2], tableAliasRaw: tableAlias }) => {
|
|
287
291
|
const mErr = () => {
|
|
288
292
|
throw `${fname}: Expecting a second argument like: { lat?: number; lng?: number; geojson?: object; srid?: number; use_spheroid?: boolean }`;
|
|
289
293
|
};
|
|
@@ -381,14 +385,14 @@ let PostGIS_Funcs: FunctionSpec[] = (
|
|
|
381
385
|
colCast = colIsGeog ? "::geography" : "::geometry";
|
|
382
386
|
geomQCast = colIsGeog ? "::geography" : "::geometry";
|
|
383
387
|
const q = pgp.as.format(
|
|
384
|
-
`${asNameAlias(columnName, tableAlias)}${colCast} <-> ${geomQ}${geomQCast}
|
|
388
|
+
`${asNameAlias(columnName, tableAlias)}${colCast} <-> ${geomQ}${geomQCast}`,
|
|
385
389
|
);
|
|
386
390
|
if (debug) throw q;
|
|
387
391
|
return q;
|
|
388
392
|
}
|
|
389
393
|
|
|
390
394
|
const query = pgp.as.format(
|
|
391
|
-
`${fname}(${asNameAlias(columnName, tableAlias)}${colCast} , ${geomQ}${geomQCast} ${extraParams})
|
|
395
|
+
`${fname}(${asNameAlias(columnName, tableAlias)}${colCast} , ${geomQ}${geomQCast} ${extraParams})`,
|
|
392
396
|
);
|
|
393
397
|
if (debug) {
|
|
394
398
|
throw query;
|
|
@@ -418,12 +422,12 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
418
422
|
singleColArg: true,
|
|
419
423
|
numArgs: 1,
|
|
420
424
|
getFields: (args: any[]) => [args[0]],
|
|
421
|
-
getQuery: ({ args: [colName, ...otherArgs], tableAlias }) => {
|
|
425
|
+
getQuery: ({ args: [colName, ...otherArgs], tableAliasRaw: tableAlias }) => {
|
|
422
426
|
let secondArg = "";
|
|
423
427
|
if (otherArgs.length) secondArg = ", " + otherArgs.map((arg) => asValue(arg)).join(", ");
|
|
424
428
|
const escTabelName = asNameAlias(colName, tableAlias) + "::geometry";
|
|
425
429
|
const result = pgp.as.format(
|
|
426
|
-
fname + "(" + escTabelName + secondArg + (fname === "ST_AsGeoJSON" ? ")::jsonb" : ")")
|
|
430
|
+
fname + "(" + escTabelName + secondArg + (fname === "ST_AsGeoJSON" ? ")::jsonb" : ")"),
|
|
427
431
|
);
|
|
428
432
|
if (["ST_Centroid", "ST_SnapToGrid", "ST_Simplify"].includes(fname)) {
|
|
429
433
|
const r = `ST_AsGeoJSON(${result})::jsonb`;
|
|
@@ -433,7 +437,7 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
433
437
|
},
|
|
434
438
|
};
|
|
435
439
|
return res;
|
|
436
|
-
})
|
|
440
|
+
}),
|
|
437
441
|
);
|
|
438
442
|
|
|
439
443
|
PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
@@ -456,7 +460,7 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
456
460
|
singleColArg: true,
|
|
457
461
|
numArgs: 1,
|
|
458
462
|
getFields: (args: any[]) => [args[0]],
|
|
459
|
-
getQuery: ({ args, tableAlias }) => {
|
|
463
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
460
464
|
const escTabelName = asNameAlias(args[0], tableAlias) + "::geometry";
|
|
461
465
|
if (fname.includes("Extent")) {
|
|
462
466
|
return `${fname}(${escTabelName})`;
|
|
@@ -465,7 +469,7 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
465
469
|
},
|
|
466
470
|
};
|
|
467
471
|
return res;
|
|
468
|
-
})
|
|
472
|
+
}),
|
|
469
473
|
);
|
|
470
474
|
|
|
471
475
|
PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
@@ -475,7 +479,7 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
475
479
|
singleColArg: true,
|
|
476
480
|
numArgs: 1,
|
|
477
481
|
getFields: (args: any[]) => [args[0]],
|
|
478
|
-
getQuery: ({ allColumns, args, tableAlias }) => {
|
|
482
|
+
getQuery: ({ allColumns, args, tableAliasRaw: tableAlias }) => {
|
|
479
483
|
const colName = args[0];
|
|
480
484
|
const escapedColName = asNameAlias(colName, tableAlias);
|
|
481
485
|
const col = allColumns.find((c) => c.name === colName);
|
|
@@ -483,7 +487,7 @@ PostGIS_Funcs = PostGIS_Funcs.concat(
|
|
|
483
487
|
|
|
484
488
|
return `${fname}(${escapedColName})`;
|
|
485
489
|
},
|
|
486
|
-
}))
|
|
490
|
+
})),
|
|
487
491
|
);
|
|
488
492
|
|
|
489
493
|
/**
|
|
@@ -498,13 +502,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
498
502
|
singleColArg: false,
|
|
499
503
|
numArgs: MAX_COL_NUM,
|
|
500
504
|
getFields: (args: any[]) => args,
|
|
501
|
-
getQuery: ({ args, tableAlias }) => {
|
|
505
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
502
506
|
const q = pgp.as.format(
|
|
503
507
|
"md5(" +
|
|
504
508
|
args
|
|
505
509
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + "::text, '' )")
|
|
506
510
|
.join(" || ") +
|
|
507
|
-
")"
|
|
511
|
+
")",
|
|
508
512
|
);
|
|
509
513
|
return q;
|
|
510
514
|
},
|
|
@@ -516,13 +520,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
516
520
|
singleColArg: false,
|
|
517
521
|
numArgs: MAX_COL_NUM,
|
|
518
522
|
getFields: (args: any[]) => args,
|
|
519
|
-
getQuery: ({ args, tableAlias }) => {
|
|
523
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
520
524
|
const q = pgp.as.format(
|
|
521
525
|
"md5(string_agg(" +
|
|
522
526
|
args
|
|
523
527
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + "::text, '' )")
|
|
524
528
|
.join(" || ") +
|
|
525
|
-
", ','))"
|
|
529
|
+
", ','))",
|
|
526
530
|
);
|
|
527
531
|
return q;
|
|
528
532
|
},
|
|
@@ -535,13 +539,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
535
539
|
singleColArg: false,
|
|
536
540
|
numArgs: MAX_COL_NUM,
|
|
537
541
|
getFields: (args: any[]) => args,
|
|
538
|
-
getQuery: ({ args, tableAlias }) => {
|
|
542
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
539
543
|
const q = pgp.as.format(
|
|
540
544
|
"encode(sha256((" +
|
|
541
545
|
args
|
|
542
546
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + ", '' )")
|
|
543
547
|
.join(" || ") +
|
|
544
|
-
")::text::bytea), 'hex')"
|
|
548
|
+
")::text::bytea), 'hex')",
|
|
545
549
|
);
|
|
546
550
|
return q;
|
|
547
551
|
},
|
|
@@ -553,13 +557,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
553
557
|
singleColArg: false,
|
|
554
558
|
numArgs: MAX_COL_NUM,
|
|
555
559
|
getFields: (args: any[]) => args,
|
|
556
|
-
getQuery: ({ args, tableAlias }) => {
|
|
560
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
557
561
|
const q = pgp.as.format(
|
|
558
562
|
"encode(sha256(string_agg(" +
|
|
559
563
|
args
|
|
560
564
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + ", '' )")
|
|
561
565
|
.join(" || ") +
|
|
562
|
-
", ',')::text::bytea), 'hex')"
|
|
566
|
+
", ',')::text::bytea), 'hex')",
|
|
563
567
|
);
|
|
564
568
|
return q;
|
|
565
569
|
},
|
|
@@ -571,13 +575,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
571
575
|
singleColArg: false,
|
|
572
576
|
numArgs: MAX_COL_NUM,
|
|
573
577
|
getFields: (args: any[]) => args,
|
|
574
|
-
getQuery: ({ args, tableAlias }) => {
|
|
578
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
575
579
|
const q = pgp.as.format(
|
|
576
580
|
"encode(sha512((" +
|
|
577
581
|
args
|
|
578
582
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + ", '' )")
|
|
579
583
|
.join(" || ") +
|
|
580
|
-
")::text::bytea), 'hex')"
|
|
584
|
+
")::text::bytea), 'hex')",
|
|
581
585
|
);
|
|
582
586
|
return q;
|
|
583
587
|
},
|
|
@@ -589,13 +593,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
589
593
|
singleColArg: false,
|
|
590
594
|
numArgs: MAX_COL_NUM,
|
|
591
595
|
getFields: (args: any[]) => args,
|
|
592
|
-
getQuery: ({ args, tableAlias }) => {
|
|
596
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
593
597
|
const q = pgp.as.format(
|
|
594
598
|
"encode(sha512(string_agg(" +
|
|
595
599
|
args
|
|
596
600
|
.map((fname) => "COALESCE( " + asNameAlias(fname, tableAlias) + ", '' )")
|
|
597
601
|
.join(" || ") +
|
|
598
|
-
", ',')::text::bytea), 'hex')"
|
|
602
|
+
", ',')::text::bytea), 'hex')",
|
|
599
603
|
);
|
|
600
604
|
return q;
|
|
601
605
|
},
|
|
@@ -614,7 +618,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
614
618
|
numArgs: 2,
|
|
615
619
|
singleColArg: false,
|
|
616
620
|
getFields: (args: any[]) => [args[0]],
|
|
617
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
621
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
618
622
|
return pgp.as.format("LEFT(" + asNameAlias(args[0], tableAlias) + ", $1)", [args[1]]);
|
|
619
623
|
},
|
|
620
624
|
},
|
|
@@ -625,7 +629,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
625
629
|
numArgs: 1,
|
|
626
630
|
singleColArg: false,
|
|
627
631
|
getFields: (args: any[]) => [args[0]],
|
|
628
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
632
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
629
633
|
const aliasedColumnName = args[0];
|
|
630
634
|
if (!aliasedColumnName) {
|
|
631
635
|
throw `$column: column_name is required`;
|
|
@@ -640,9 +644,9 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
640
644
|
numArgs: 1,
|
|
641
645
|
singleColArg: true,
|
|
642
646
|
getFields: (args: any[]) => [args[0]],
|
|
643
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
647
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
644
648
|
return pgp.as.format(
|
|
645
|
-
"unnest(string_to_array(" + asNameAlias(args[0], tableAlias) + "::TEXT , ' '))"
|
|
649
|
+
"unnest(string_to_array(" + asNameAlias(args[0], tableAlias) + "::TEXT , ' '))",
|
|
646
650
|
); //, [args[1]]
|
|
647
651
|
},
|
|
648
652
|
},
|
|
@@ -653,7 +657,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
653
657
|
numArgs: 2,
|
|
654
658
|
singleColArg: false,
|
|
655
659
|
getFields: (args: any[]) => [args[0]],
|
|
656
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
660
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
657
661
|
return pgp.as.format("RIGHT(" + asNameAlias(args[0], tableAlias) + ", $1)", [args[1]]);
|
|
658
662
|
},
|
|
659
663
|
},
|
|
@@ -665,7 +669,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
665
669
|
singleColArg: false,
|
|
666
670
|
numArgs: 2,
|
|
667
671
|
getFields: (args: any[]) => [args[0]],
|
|
668
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
672
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
669
673
|
if (args.length === 3) {
|
|
670
674
|
return pgp.as.format("to_char(" + asNameAlias(args[0], tableAlias) + ", $2, $3)", [
|
|
671
675
|
args[0],
|
|
@@ -741,7 +745,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
741
745
|
singleColArg: true,
|
|
742
746
|
numArgs: 2,
|
|
743
747
|
getFields: (args: any[]) => [args[0]],
|
|
744
|
-
getQuery: ({ allColumns, args, tableAlias }) => {
|
|
748
|
+
getQuery: ({ allColumns, args, tableAliasRaw: tableAlias }) => {
|
|
745
749
|
/** Timestamp added to ensure filters work correctly (psql will loose the string value timezone when comparing to a non tz column) */
|
|
746
750
|
const col = parseUnix(args[0], tableAlias, allColumns, args[1]);
|
|
747
751
|
if (!val) return `date_trunc(${asValue(unit)}, ${col})`;
|
|
@@ -768,7 +772,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
768
772
|
// console.log(res);
|
|
769
773
|
return res;
|
|
770
774
|
},
|
|
771
|
-
}) as FunctionSpec
|
|
775
|
+
}) as FunctionSpec,
|
|
772
776
|
),
|
|
773
777
|
|
|
774
778
|
/* Date funcs date_part */
|
|
@@ -786,10 +790,10 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
786
790
|
` E.g. ['hour', col] `,
|
|
787
791
|
singleColArg: false,
|
|
788
792
|
getFields: (args: any[]) => [args[1]],
|
|
789
|
-
getQuery: ({ allColumns, args, tableAlias }) => {
|
|
793
|
+
getQuery: ({ allColumns, args, tableAliasRaw: tableAlias }) => {
|
|
790
794
|
return `${funcName}(${asValue(args[0])}, ${parseUnix(args[1], tableAlias, allColumns, args[2])})`;
|
|
791
795
|
},
|
|
792
|
-
}) as FunctionSpec
|
|
796
|
+
}) as FunctionSpec,
|
|
793
797
|
),
|
|
794
798
|
|
|
795
799
|
/* Handy date funcs */
|
|
@@ -838,13 +842,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
838
842
|
singleColArg: true,
|
|
839
843
|
numArgs: 1,
|
|
840
844
|
getFields: (args: any[]) => [args[0]],
|
|
841
|
-
getQuery: ({ allColumns, args, tableAlias }) => {
|
|
845
|
+
getQuery: ({ allColumns, args, tableAliasRaw: tableAlias }) => {
|
|
842
846
|
return pgp.as.format(
|
|
843
847
|
"trim(to_char(" + parseUnix(args[0], tableAlias, allColumns, args[1]) + ", $2))",
|
|
844
|
-
[args[0], txt]
|
|
848
|
+
[args[0], txt],
|
|
845
849
|
);
|
|
846
850
|
},
|
|
847
|
-
}) as FunctionSpec
|
|
851
|
+
}) as FunctionSpec,
|
|
848
852
|
),
|
|
849
853
|
|
|
850
854
|
/* Basic 1 arg col funcs */
|
|
@@ -853,13 +857,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
853
857
|
["upper", "lower", "length", "reverse", "trim", "initcap"].map((funcName) => ({
|
|
854
858
|
cast,
|
|
855
859
|
funcName,
|
|
856
|
-
}))
|
|
860
|
+
})),
|
|
857
861
|
),
|
|
858
862
|
...[""].flatMap((cast) =>
|
|
859
863
|
["round", "ceil", "floor", "sign", "md5"].map((funcName) => ({
|
|
860
864
|
cast,
|
|
861
865
|
funcName,
|
|
862
|
-
}))
|
|
866
|
+
})),
|
|
863
867
|
),
|
|
864
868
|
].map(
|
|
865
869
|
({ funcName, cast }) =>
|
|
@@ -869,10 +873,10 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
869
873
|
numArgs: 1,
|
|
870
874
|
singleColArg: true,
|
|
871
875
|
getFields: (args: any[]) => [args[0]],
|
|
872
|
-
getQuery: ({ args, tableAlias }) => {
|
|
876
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
873
877
|
return `${funcName}(${asNameAlias(args[0], tableAlias)}${cast ? `::${cast}` : ""})`;
|
|
874
878
|
},
|
|
875
|
-
}) as FunctionSpec
|
|
879
|
+
}) as FunctionSpec,
|
|
876
880
|
),
|
|
877
881
|
|
|
878
882
|
/**
|
|
@@ -888,13 +892,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
888
892
|
singleColArg: true,
|
|
889
893
|
// Filtered because the second arg is optional
|
|
890
894
|
getFields: (args: any[]) => args.slice(0, 2).filter((a) => typeof a === "string"),
|
|
891
|
-
getQuery: ({ args, tableAlias, allColumns }) => {
|
|
895
|
+
getQuery: ({ args, tableAliasRaw: tableAlias, allColumns }) => {
|
|
892
896
|
const validColCount = args.slice(0, 2).filter((a) => typeof a === "string").length;
|
|
893
897
|
const trunc = args[2];
|
|
894
898
|
const allowedTruncs = ["second", "minute", "hour", "day", "month", "year"];
|
|
895
899
|
if (trunc && !allowedTruncs.includes(trunc))
|
|
896
900
|
throw new Error(
|
|
897
|
-
"Incorrect trunc provided. Allowed values: " + allowedTruncs.join(", ")
|
|
901
|
+
"Incorrect trunc provided. Allowed values: " + allowedTruncs.join(", "),
|
|
898
902
|
);
|
|
899
903
|
if (funcName === "difference" && validColCount !== 2)
|
|
900
904
|
throw new Error("Must have two column names");
|
|
@@ -914,7 +918,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
914
918
|
}
|
|
915
919
|
return trunc ? `date_trunc(${asValue(trunc)}, ${query})` : query;
|
|
916
920
|
},
|
|
917
|
-
}) as FunctionSpec
|
|
921
|
+
}) as FunctionSpec,
|
|
918
922
|
),
|
|
919
923
|
|
|
920
924
|
/* pgcrypto funcs */
|
|
@@ -926,13 +930,13 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
926
930
|
numArgs: 1,
|
|
927
931
|
singleColArg: false,
|
|
928
932
|
getFields: (args: any[]) => [args[1]],
|
|
929
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
933
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
930
934
|
const value = asValue(args[0]) + "",
|
|
931
935
|
seedColumnName = asNameAlias(args[1], tableAlias);
|
|
932
936
|
|
|
933
937
|
return `crypt(${value}, ${seedColumnName}::text)`;
|
|
934
938
|
},
|
|
935
|
-
}) as FunctionSpec
|
|
939
|
+
}) as FunctionSpec,
|
|
936
940
|
),
|
|
937
941
|
|
|
938
942
|
/* Text col and value funcs */
|
|
@@ -944,7 +948,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
944
948
|
numArgs: 1,
|
|
945
949
|
singleColArg: false,
|
|
946
950
|
getFields: (args: any[]) => [args[1]],
|
|
947
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
951
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
948
952
|
let a1 = asValue(args[0]),
|
|
949
953
|
a2 = asNameAlias(args[1], tableAlias);
|
|
950
954
|
if (funcName === "position_lower") {
|
|
@@ -953,7 +957,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
953
957
|
}
|
|
954
958
|
return `position( ${a1} IN ${a2} )`;
|
|
955
959
|
},
|
|
956
|
-
}) as FunctionSpec
|
|
960
|
+
}) as FunctionSpec,
|
|
957
961
|
),
|
|
958
962
|
...["template_string"].map(
|
|
959
963
|
(funcName) =>
|
|
@@ -964,7 +968,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
964
968
|
minCols: 0,
|
|
965
969
|
singleColArg: false,
|
|
966
970
|
getFields: (args: any[]) => [] as string[], // Fields not validated because we'll use the allowed ones anyway
|
|
967
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
971
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
968
972
|
if (typeof args[0] !== "string")
|
|
969
973
|
throw "First argument must be a string. E.g.: '{col1} ..text {col2} ...' ";
|
|
970
974
|
|
|
@@ -982,7 +986,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
982
986
|
|
|
983
987
|
return `format(${finalValue})`;
|
|
984
988
|
},
|
|
985
|
-
}) as FunctionSpec
|
|
989
|
+
}) as FunctionSpec,
|
|
986
990
|
),
|
|
987
991
|
|
|
988
992
|
/** Custom highlight -> myterm => ['some text and', ['myterm'], ' and some other text']
|
|
@@ -998,7 +1002,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
998
1002
|
singleColArg: true,
|
|
999
1003
|
canBeUsedForFilter: true,
|
|
1000
1004
|
getFields: (args: any[]) => args[0],
|
|
1001
|
-
getQuery: ({ allowedFields, args, tableAlias, allColumns }) => {
|
|
1005
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias, allColumns }) => {
|
|
1002
1006
|
const cols = parseFieldFilter(args[0], false, allowedFields);
|
|
1003
1007
|
let term = args[1];
|
|
1004
1008
|
const rawTerm = args[1];
|
|
@@ -1056,7 +1060,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1056
1060
|
cols
|
|
1057
1061
|
.map(
|
|
1058
1062
|
(c) =>
|
|
1059
|
-
`${noFields ? "" : asValue(c + ": ") + " || "} COALESCE(${asNameAlias(c, tableAlias)}::TEXT, '')
|
|
1063
|
+
`${noFields ? "" : asValue(c + ": ") + " || "} COALESCE(${asNameAlias(c, tableAlias)}::TEXT, '')`,
|
|
1060
1064
|
)
|
|
1061
1065
|
.join(" || ', ' || ") +
|
|
1062
1066
|
" )";
|
|
@@ -1096,7 +1100,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1096
1100
|
const _cols = validCols.filter(
|
|
1097
1101
|
(c) =>
|
|
1098
1102
|
/** Exclude numeric columns when the search tern contains a character */
|
|
1099
|
-
!hasChars || postgresToTsType(c.colInfo!.udt_name) !== "number"
|
|
1103
|
+
!hasChars || postgresToTsType(c.colInfo!.udt_name) !== "number",
|
|
1100
1104
|
);
|
|
1101
1105
|
|
|
1102
1106
|
/** This will break GROUP BY (non-integer constant in GROUP BY) */
|
|
@@ -1165,14 +1169,14 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1165
1169
|
numArgs: 1,
|
|
1166
1170
|
singleColArg: true,
|
|
1167
1171
|
getFields: (args: any[]) => [args[0]],
|
|
1168
|
-
getQuery: ({ args, tableAlias }) => {
|
|
1172
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
1169
1173
|
let extraArgs = "";
|
|
1170
1174
|
if (args.length > 1) {
|
|
1171
1175
|
extraArgs = pgp.as.format(", $1:csv", args.slice(1));
|
|
1172
1176
|
}
|
|
1173
1177
|
return aggName + "(" + asNameAlias(args[0], tableAlias) + `${extraArgs})`;
|
|
1174
1178
|
},
|
|
1175
|
-
}) satisfies FunctionSpec
|
|
1179
|
+
}) satisfies FunctionSpec,
|
|
1176
1180
|
),
|
|
1177
1181
|
|
|
1178
1182
|
{
|
|
@@ -1182,7 +1186,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1182
1186
|
minCols: 1,
|
|
1183
1187
|
singleColArg: false,
|
|
1184
1188
|
getFields: (args) => args,
|
|
1185
|
-
getQuery: ({ args, tableAlias }) => {
|
|
1189
|
+
getQuery: ({ args, tableAliasRaw: tableAlias }) => {
|
|
1186
1190
|
return `jsonb_build_object(${args.flatMap((arg) => [asValue(arg), asNameAlias(arg, tableAlias)]).join(", ")})`;
|
|
1187
1191
|
},
|
|
1188
1192
|
},
|
|
@@ -1195,7 +1199,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1195
1199
|
singleColArg: true,
|
|
1196
1200
|
numArgs: 0,
|
|
1197
1201
|
getFields: (args: any[]) => [],
|
|
1198
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
1202
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
1199
1203
|
return "COUNT(*)";
|
|
1200
1204
|
},
|
|
1201
1205
|
} as FunctionSpec,
|
|
@@ -1205,7 +1209,7 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
1205
1209
|
numArgs: 1,
|
|
1206
1210
|
singleColArg: true,
|
|
1207
1211
|
getFields: (args: any[]) => [args[0]],
|
|
1208
|
-
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
1212
|
+
getQuery: ({ allowedFields, args, tableAliasRaw: tableAlias }) => {
|
|
1209
1213
|
const col = asNameAlias(args[0], tableAlias);
|
|
1210
1214
|
return `round( ( ( MAX(${col}) - MIN(${col}) )::float/MIN(${col}) ) * 100, 2)`;
|
|
1211
1215
|
},
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
ValidatedColumnInfo,
|
|
12
12
|
} from "prostgles-types";
|
|
13
13
|
import { getKeys, isEmpty, isObject, postgresToTsType } from "prostgles-types";
|
|
14
|
-
import type { SortItem } from "../DboBuilder";
|
|
14
|
+
import type { PGIdentifier, SortItem } from "../DboBuilder";
|
|
15
15
|
|
|
16
16
|
import type { ParsedJoinPath } from "../ViewHandler/parseJoinPath";
|
|
17
17
|
import type { ViewHandler } from "../ViewHandler/ViewHandler";
|
|
@@ -22,7 +22,7 @@ import { asNameAlias } from "../../utils/asNameAlias";
|
|
|
22
22
|
|
|
23
23
|
export type SelectItem = {
|
|
24
24
|
getFields: (args: any[]) => string[] | "*";
|
|
25
|
-
getQuery: (
|
|
25
|
+
getQuery: (tableAliasRaw?: string) => string;
|
|
26
26
|
columnPGDataType?: string;
|
|
27
27
|
column_udt_type?: PG_COLUMN_UDT_DATA_TYPE;
|
|
28
28
|
tsDataType?: ValidatedColumnInfo["tsDataType"];
|
|
@@ -54,7 +54,7 @@ export type NewQueryRoot = {
|
|
|
54
54
|
*/
|
|
55
55
|
select: SelectItemValidated[];
|
|
56
56
|
|
|
57
|
-
table:
|
|
57
|
+
table: PGIdentifier;
|
|
58
58
|
where: string;
|
|
59
59
|
whereOpts: WhereOptions;
|
|
60
60
|
orderByItems: SortItem[];
|
|
@@ -62,12 +62,12 @@ export type NewQueryRoot = {
|
|
|
62
62
|
limit: number | null;
|
|
63
63
|
offset: number;
|
|
64
64
|
isLeftJoin: boolean;
|
|
65
|
-
tableAlias?:
|
|
65
|
+
tableAlias?: PGIdentifier;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export type NewQueryJoin = NewQuery & {
|
|
69
69
|
joinPath: ParsedJoinPath[];
|
|
70
|
-
joinAlias:
|
|
70
|
+
joinAlias: PGIdentifier;
|
|
71
71
|
};
|
|
72
72
|
export type NewQuery = NewQueryRoot & {
|
|
73
73
|
joins?: NewQueryJoin[];
|
|
@@ -183,7 +183,7 @@ export class SelectItemBuilder {
|
|
|
183
183
|
allColumns: this.columns,
|
|
184
184
|
allowedFields: this.allowedFields,
|
|
185
185
|
args,
|
|
186
|
-
tableAlias,
|
|
186
|
+
tableAliasRaw: tableAlias,
|
|
187
187
|
ctidField: undefined,
|
|
188
188
|
|
|
189
189
|
/* CTID not available in AFTER trigger */
|
|
@@ -6,7 +6,7 @@ import { type SelectItemValidated } from "./QueryBuilder";
|
|
|
6
6
|
import { ROOT_TABLE_ALIAS, ROOT_TABLE_ROW_NUM_ID, indentLines } from "./getSelectQuery";
|
|
7
7
|
import type { ViewHandler } from "../ViewHandler/ViewHandler";
|
|
8
8
|
import { getJoinOnCondition } from "../ViewHandler/getTableJoinQuery";
|
|
9
|
-
import { prepareOrderByQuery } from "../DboBuilder";
|
|
9
|
+
import { prepareOrderByQuery, type PGIdentifier } from "../DboBuilder";
|
|
10
10
|
import { asNameAlias } from "../../utils/asNameAlias";
|
|
11
11
|
|
|
12
12
|
type Args = {
|
|
@@ -47,7 +47,7 @@ const getJoinTable = (
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
type GetJoinQueryResult = {
|
|
50
|
-
resultAlias:
|
|
50
|
+
resultAlias: PGIdentifier;
|
|
51
51
|
firstJoinTableJoinFields: string[];
|
|
52
52
|
isOrJoin: boolean;
|
|
53
53
|
type: "cte";
|
|
@@ -68,7 +68,7 @@ type GetJoinQueryResult = {
|
|
|
68
68
|
*/
|
|
69
69
|
export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoinQueryResult => {
|
|
70
70
|
const paths = parseJoinPath({
|
|
71
|
-
rootTable: q1.table,
|
|
71
|
+
rootTable: q1.table.raw,
|
|
72
72
|
rawPath: q2.joinPath,
|
|
73
73
|
viewHandler: viewHandler,
|
|
74
74
|
allowMultiOrJoin: true,
|
|
@@ -78,7 +78,7 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
78
78
|
if (q2.joins?.length) {
|
|
79
79
|
throw new Error("Nested joins not supported yet");
|
|
80
80
|
}
|
|
81
|
-
const targetTableAliasRaw = q2.tableAlias || q2.table;
|
|
81
|
+
const targetTableAliasRaw = q2.tableAlias?.raw || q2.table.raw;
|
|
82
82
|
const targetTableAlias = asName(targetTableAliasRaw);
|
|
83
83
|
|
|
84
84
|
const firstJoinTablePath = paths[0]!;
|
|
@@ -101,7 +101,7 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
101
101
|
|
|
102
102
|
const joinCondition = getJoinOnCondition({
|
|
103
103
|
on: firstJoinTablePath.on,
|
|
104
|
-
leftAlias:
|
|
104
|
+
leftAlias: q1.tableAlias?.escaped || q1.table.escaped,
|
|
105
105
|
rightAlias: targetTableAlias,
|
|
106
106
|
getRightColName: (col) => getJoinCol(col).alias,
|
|
107
107
|
});
|
|
@@ -110,7 +110,9 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
110
110
|
const selectedFields = rootSelectItems
|
|
111
111
|
.filter((s) => s.selected)
|
|
112
112
|
.map((s) => asNameAlias(s.alias, targetTableAliasRaw));
|
|
113
|
-
const rootNestedSort = q1.orderByItems.filter(
|
|
113
|
+
const rootNestedSort = q1.orderByItems.filter(
|
|
114
|
+
(d) => d.nested?.joinAlias.raw === q2.joinAlias.raw,
|
|
115
|
+
);
|
|
114
116
|
const jsonAgg = `json_agg((SELECT x FROM (SELECT ${selectedFields.join(", ")}) as x )${jsonAggSort}) ${jsonAggLimit} as ${JSON_AGG_FIELD_NAME}`;
|
|
115
117
|
|
|
116
118
|
const { innerQuery } = getInnerJoinQuery({
|
|
@@ -151,7 +153,7 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
151
153
|
];
|
|
152
154
|
return {
|
|
153
155
|
type: "cte",
|
|
154
|
-
resultAlias: JSON_AGG_FIELD_NAME,
|
|
156
|
+
resultAlias: { raw: JSON_AGG_FIELD_NAME, escaped: JSON_AGG_FIELD_NAME },
|
|
155
157
|
joinLines,
|
|
156
158
|
cteLines: [],
|
|
157
159
|
isOrJoin,
|
|
@@ -171,7 +173,9 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
171
173
|
`FROM (`,
|
|
172
174
|
...indentLines(innerQuery),
|
|
173
175
|
`) ${targetTableAlias}`,
|
|
174
|
-
...(isOrJoin ?
|
|
176
|
+
...(isOrJoin ?
|
|
177
|
+
[`LEFT JOIN ${q1.table.escaped} ${ROOT_TABLE_ALIAS}`, `ON ${joinCondition}`]
|
|
178
|
+
: []),
|
|
175
179
|
`GROUP BY ${isOrJoin ? rootTableIdField : requiredJoinFields.join(", ")}`,
|
|
176
180
|
];
|
|
177
181
|
|
|
@@ -190,7 +194,7 @@ export const getJoinQuery = (viewHandler: ViewHandler, { q1, q2 }: Args): GetJoi
|
|
|
190
194
|
|
|
191
195
|
return {
|
|
192
196
|
type: "cte",
|
|
193
|
-
resultAlias: JSON_AGG_FIELD_NAME,
|
|
197
|
+
resultAlias: { raw: JSON_AGG_FIELD_NAME, escaped: JSON_AGG_FIELD_NAME },
|
|
194
198
|
joinLines,
|
|
195
199
|
cteLines,
|
|
196
200
|
isOrJoin,
|
|
@@ -218,8 +222,8 @@ const getInnerJoinQuery = ({
|
|
|
218
222
|
const prevTable = getJoinTable(
|
|
219
223
|
!i ?
|
|
220
224
|
q1.tableAlias ?
|
|
221
|
-
|
|
222
|
-
: q1.table
|
|
225
|
+
q1.tableAlias.escaped
|
|
226
|
+
: q1.table.escaped
|
|
223
227
|
: paths[i - 1]!.table,
|
|
224
228
|
i - 1,
|
|
225
229
|
undefined,
|
|
@@ -302,7 +306,7 @@ const getNestedSelectFields = ({
|
|
|
302
306
|
.map((s) => ({
|
|
303
307
|
...s,
|
|
304
308
|
isJoinCol: false,
|
|
305
|
-
query: s.getQuery(targetTableAlias) + " AS " + asName(s.alias),
|
|
309
|
+
query: s.getQuery(targetTableAlias.raw) + " AS " + asName(s.alias),
|
|
306
310
|
}))
|
|
307
311
|
.concat(
|
|
308
312
|
requiredJoinFields.map((f) => ({
|
|
@@ -6,9 +6,9 @@ import type {
|
|
|
6
6
|
SelectParams,
|
|
7
7
|
SimpleJoinSelect,
|
|
8
8
|
} from "prostgles-types";
|
|
9
|
-
import { getKeys, includes, isEmpty, omitKeys } from "prostgles-types";
|
|
9
|
+
import { asName, getKeys, includes, isEmpty, omitKeys } from "prostgles-types";
|
|
10
10
|
import type { ParsedTableRule } from "../../PublishParser/PublishParser";
|
|
11
|
-
import type { Filter, LocalParams, ValidatedTableRules } from "../DboBuilder";
|
|
11
|
+
import type { Filter, LocalParams, PGIdentifier, ValidatedTableRules } from "../DboBuilder";
|
|
12
12
|
import type { ViewHandler } from "../ViewHandler/ViewHandler";
|
|
13
13
|
import { parseJoinPath } from "../ViewHandler/parseJoinPath";
|
|
14
14
|
import { prepareSortItems } from "../ViewHandler/prepareSortItems";
|
|
@@ -91,7 +91,7 @@ const parseJoinSelect = (joinParams: JoinSelect): ParsedJoin => {
|
|
|
91
91
|
export async function getNewQuery(
|
|
92
92
|
_this: ViewHandler,
|
|
93
93
|
filter: Filter,
|
|
94
|
-
selectParams: SelectParams & { joinExpressionAlias?:
|
|
94
|
+
selectParams: SelectParams & { joinExpressionAlias?: PGIdentifier } = {},
|
|
95
95
|
param3_unused = null,
|
|
96
96
|
tableRules: ParsedTableRule | undefined,
|
|
97
97
|
localParams: LocalParams | undefined,
|
|
@@ -133,7 +133,7 @@ export async function getNewQuery(
|
|
|
133
133
|
throwErr(parsedJoin.error);
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
const joinExpressionAlias = joinColumnName;
|
|
136
|
+
const joinExpressionAlias = { raw: joinColumnName, escaped: asName(joinColumnName) };
|
|
137
137
|
const j_path = parseJoinPath({
|
|
138
138
|
rawPath: parsedJoin.type === "simple" ? joinColumnName : parsedJoin.params.path,
|
|
139
139
|
rootTable: _this.name,
|
|
@@ -247,7 +247,7 @@ export async function getNewQuery(
|
|
|
247
247
|
const resQuery: NewQuery = {
|
|
248
248
|
allFields: _this.column_names.slice(0),
|
|
249
249
|
select,
|
|
250
|
-
table: _this.name,
|
|
250
|
+
table: { raw: _this.name, escaped: _this.name },
|
|
251
251
|
joins: joinQueries,
|
|
252
252
|
where,
|
|
253
253
|
whereOpts: filterOpts,
|