pqb 0.68.0 → 0.68.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -1
- package/dist/index.js +77 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -128
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5835,6 +5835,8 @@ interface Base$1<Value> {
|
|
|
5835
5835
|
__hasSelect: true;
|
|
5836
5836
|
equals: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
|
|
5837
5837
|
not: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
|
|
5838
|
+
isDistinctFrom: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
|
|
5839
|
+
isNotDistinctFrom: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
|
|
5838
5840
|
in: Operator<Value[] | IsQuery | Expression, BooleanQueryColumn>;
|
|
5839
5841
|
notIn: Operator<Value[] | IsQuery | Expression, BooleanQueryColumn>;
|
|
5840
5842
|
}
|
|
@@ -6613,7 +6615,7 @@ declare namespace Column {
|
|
|
6613
6615
|
unique: Name;
|
|
6614
6616
|
};
|
|
6615
6617
|
};
|
|
6616
|
-
export type Nullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema> = { [K in keyof T]: K extends '__type' ? T['__type'] | null : K extends '__inputType' ? T['__inputType'] | null : K extends 'inputSchema' ? InputSchema : K extends '__outputType' ? T['__outputType'] | (unknown extends T['__nullType'] ? null : T['__nullType']) : K extends 'outputSchema' ? OutputSchema : K extends '__queryType' ? T['__queryType'] | null : K extends 'querySchema' ? QuerySchema : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? { [K in keyof T['operators']]: K extends 'equals' | 'not' ? Operator<T | null> : T['operators'][K] } : T[K] };
|
|
6618
|
+
export type Nullable<T extends Column.Pick.ForNullable, InputSchema, OutputSchema, QuerySchema> = { [K in keyof T]: K extends '__type' ? T['__type'] | null : K extends '__inputType' ? T['__inputType'] | null : K extends 'inputSchema' ? InputSchema : K extends '__outputType' ? T['__outputType'] | (unknown extends T['__nullType'] ? null : T['__nullType']) : K extends 'outputSchema' ? OutputSchema : K extends '__queryType' ? T['__queryType'] | null : K extends 'querySchema' ? QuerySchema : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? { [K in keyof T['operators']]: K extends 'equals' | 'not' | 'isDistinctFrom' | 'isNotDistinctFrom' ? Operator<T | null> : T['operators'][K] } : T[K] };
|
|
6617
6619
|
export type QueryColumnToNullable<C> = { [K in keyof C]: K extends '__outputType' | '__queryType' ? C[K] | null : C[K] };
|
|
6618
6620
|
export type QueryColumnToOptional<C> = { [K in keyof C]: K extends '__outputType' ? C[K] | undefined : C[K] };
|
|
6619
6621
|
interface DataNullable {
|
|
@@ -6623,6 +6625,8 @@ declare namespace Column {
|
|
|
6623
6625
|
export interface OperatorsNullable<T> {
|
|
6624
6626
|
equals: Operator<T | null>;
|
|
6625
6627
|
not: Operator<T | null>;
|
|
6628
|
+
isDistinctFrom: Operator<T | null>;
|
|
6629
|
+
isNotDistinctFrom: Operator<T | null>;
|
|
6626
6630
|
}
|
|
6627
6631
|
export type Encode<T, InputSchema, Input> = { [K in keyof T]: K extends '__inputType' ? Input : K extends 'inputSchema' ? InputSchema : T[K] };
|
|
6628
6632
|
export type Parse<T extends Pick.ForParse, OutputSchema, Output> = { [K in keyof T]: K extends '__outputType' ? null extends T['__type'] ? (Output extends null ? never : Output) | (unknown extends T['__nullType'] ? null : T['__nullType']) : Output : K extends 'outputSchema' ? null extends T['__type'] ? OutputSchema | T['nullSchema'] : OutputSchema : T[K] };
|
package/dist/index.js
CHANGED
|
@@ -1865,6 +1865,8 @@ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
1865
1865
|
const base = {
|
|
1866
1866
|
equals: make((key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue(value, ctx, quotedAs)}`),
|
|
1867
1867
|
not: make((key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`),
|
|
1868
|
+
isDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS DISTINCT FROM ${quoteValue(value, ctx, quotedAs)}`),
|
|
1869
|
+
isNotDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS NOT DISTINCT FROM ${quoteValue(value, ctx, quotedAs)}`),
|
|
1868
1870
|
in: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "false" : `${key} IN ${quoteValue(value, ctx, quotedAs, true)}`),
|
|
1869
1871
|
notIn: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "true" : `NOT ${key} IN ${quoteValue(value, ctx, quotedAs, true)}`)
|
|
1870
1872
|
};
|
|
@@ -1925,6 +1927,8 @@ const Operators = {
|
|
|
1925
1927
|
...ord,
|
|
1926
1928
|
equals: make((key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NULL` : `${key} = ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1927
1929
|
not: make((key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NOT NULL` : `${key} != ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1930
|
+
isDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS DISTINCT FROM ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1931
|
+
isNotDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS NOT DISTINCT FROM ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1928
1932
|
in: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "false" : `${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`),
|
|
1929
1933
|
notIn: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "true" : `NOT ${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`),
|
|
1930
1934
|
jsonPathQueryFirst: Object.assign(function(path, options) {
|
|
@@ -6540,130 +6544,75 @@ const resolveSubQueryCallback = (q, cb) => {
|
|
|
6540
6544
|
_setSubQueryAliases(arg);
|
|
6541
6545
|
return cb(arg);
|
|
6542
6546
|
};
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
const { data } = column;
|
|
6553
|
-
return data.computed ? `(${data.computed.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
6554
|
-
}
|
|
6555
|
-
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
6556
|
-
let index = column.indexOf(".");
|
|
6557
|
-
if (index === -1) {
|
|
6558
|
-
const joinAs = data.valuesJoinedAs?.[column];
|
|
6559
|
-
if (joinAs) {
|
|
6560
|
-
column = joinAs + "." + column;
|
|
6561
|
-
index = joinAs.length;
|
|
6562
|
-
}
|
|
6563
|
-
}
|
|
6564
|
-
if (index !== -1) return columnWithDotToSql(ctx, data, shape, column, index, quotedAs, select);
|
|
6565
|
-
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
6566
|
-
};
|
|
6567
|
-
const selectedColumnToSql = (ctx, data, shape, column, quotedAs) => {
|
|
6568
|
-
const index = column.indexOf(".");
|
|
6569
|
-
return index !== -1 ? selectedColumnWithDotToSql(ctx, data, shape, column, index, quotedAs) : selectedSimpleColumnToSql(ctx, column, shape[column], quotedAs);
|
|
6570
|
-
};
|
|
6571
|
-
const selectedSimpleColumnToSql = (ctx, key, column, quotedAs) => {
|
|
6572
|
-
if (!column) return `"${key}"`;
|
|
6573
|
-
const { data } = column;
|
|
6574
|
-
return data.selectSql ? `(${data.selectSql.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
6575
|
-
};
|
|
6576
|
-
/**
|
|
6577
|
-
* in a case when ordering or grouping by a column which was selected as expression:
|
|
6578
|
-
* ```ts
|
|
6579
|
-
* table.select({ x: (q) => q.sum('x') }).group('x').order('x')
|
|
6580
|
-
* ```
|
|
6581
|
-
* the column must not be prefixed with a table name.
|
|
6582
|
-
*/
|
|
6583
|
-
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
6584
|
-
const index = column.indexOf(".");
|
|
6585
|
-
if (index !== -1) return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
|
|
6586
|
-
else {
|
|
6587
|
-
if (data.joinedShapes?.[column]) return `"${column}"."${column}"`;
|
|
6588
|
-
if (data.select) {
|
|
6589
|
-
for (const s of data.select) if (typeof s === "object" && "selectAs" in s) {
|
|
6590
|
-
if (column in s.selectAs) return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
6547
|
+
function simpleColumnToSQL(ctx, queryData, shape, key, column, quotedAs, select, as, jsonList, useSelectList, skipSelectSql) {
|
|
6548
|
+
let sql;
|
|
6549
|
+
let dontAlias;
|
|
6550
|
+
if (useSelectList && queryData.select) {
|
|
6551
|
+
for (const s of queryData.select) if (typeof s === "object" && "selectAs" in s) {
|
|
6552
|
+
if (key in s.selectAs) {
|
|
6553
|
+
dontAlias = true;
|
|
6554
|
+
sql = simpleColumnToSQL(ctx, queryData, shape, key, shape[key]);
|
|
6555
|
+
break;
|
|
6591
6556
|
}
|
|
6592
6557
|
}
|
|
6593
|
-
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
6594
|
-
}
|
|
6595
|
-
};
|
|
6596
|
-
const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
|
|
6597
|
-
const table = column.slice(0, index);
|
|
6598
|
-
const key = column.slice(index + 1);
|
|
6599
|
-
if (key === "*") {
|
|
6600
|
-
const shape = data.joinedShapes?.[table];
|
|
6601
|
-
return shape ? select ? makeRowToJson(ctx, table, shape, true) : `"${table}".*` : column;
|
|
6602
|
-
}
|
|
6603
|
-
const tableName = _getQueryAliasOrName(data, table);
|
|
6604
|
-
const quoted = `"${table}"`;
|
|
6605
|
-
const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
|
|
6606
|
-
if (col) {
|
|
6607
|
-
if (col.data.name) return `"${tableName}"."${col.data.name}"`;
|
|
6608
|
-
if (col.data.computed) return `(${col.data.computed.toSQL(ctx, quoted)})`;
|
|
6609
|
-
return `"${tableName}"."${key}"`;
|
|
6610
6558
|
}
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)})`;
|
|
6625
|
-
if (col.data.name) return `"${tableName}"."${col.data.name}"`;
|
|
6559
|
+
if (!sql) if (!column) {
|
|
6560
|
+
dontAlias = key === as;
|
|
6561
|
+
sql = `${quotedAs ? `${quotedAs}.` : ""}"${key}"`;
|
|
6562
|
+
} else {
|
|
6563
|
+
if (jsonList && as) jsonList[as] = column && getSelectedColumnData(column);
|
|
6564
|
+
const { data } = column;
|
|
6565
|
+
if (select && data.selectSql && !skipSelectSql) sql = `(${data.selectSql.toSQL(ctx, quotedAs)})`;
|
|
6566
|
+
else if (data.computed) sql = `(${data.computed.toSQL(ctx, quotedAs)})`;
|
|
6567
|
+
else {
|
|
6568
|
+
const name = data.name || key;
|
|
6569
|
+
dontAlias = name === as;
|
|
6570
|
+
sql = `${quotedAs ? `${quotedAs}.` : ""}"${name}"`;
|
|
6571
|
+
}
|
|
6626
6572
|
}
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select, jsonList) => {
|
|
6573
|
+
if (as && !dontAlias) sql = `${sql} "${as}"`;
|
|
6574
|
+
return sql;
|
|
6575
|
+
}
|
|
6576
|
+
const tableColumnToSql = (ctx, data, shape, table, key, quotedAs, select, as, jsonList) => {
|
|
6577
|
+
let sql;
|
|
6578
|
+
let dontAlias;
|
|
6634
6579
|
if (key === "*") {
|
|
6635
|
-
if (jsonList) jsonList[as] = void 0;
|
|
6580
|
+
if (jsonList && as) jsonList[as] = void 0;
|
|
6636
6581
|
const shape = data.joinedShapes?.[table];
|
|
6637
|
-
if (shape) {
|
|
6638
|
-
|
|
6639
|
-
|
|
6582
|
+
if (shape) sql = select ? makeRowToJson(ctx, table, shape, true) : `"${table}".*`;
|
|
6583
|
+
else {
|
|
6584
|
+
sql = `"${table}"."${key}"`;
|
|
6585
|
+
dontAlias = true;
|
|
6586
|
+
}
|
|
6587
|
+
} else {
|
|
6588
|
+
const tableName = _getQueryAliasOrName(data, table);
|
|
6589
|
+
const quoted = `"${table}"`;
|
|
6590
|
+
const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
|
|
6591
|
+
if (jsonList && as) jsonList[as] = col && getSelectedColumnData(col);
|
|
6592
|
+
if (col?.data.selectSql) sql = `(${col.data.selectSql.toSQL(ctx, quoted)})`;
|
|
6593
|
+
else if (col?.data.name) sql = `"${tableName}"."${col.data.name}"`;
|
|
6594
|
+
else if (col?.data.computed) sql = `(${col.data.computed.toSQL(ctx, quoted)})`;
|
|
6595
|
+
else {
|
|
6596
|
+
sql = `"${tableName}"."${key}"`;
|
|
6597
|
+
dontAlias = key === as;
|
|
6640
6598
|
}
|
|
6641
|
-
return column;
|
|
6642
|
-
}
|
|
6643
|
-
const tableName = _getQueryAliasOrName(data, table);
|
|
6644
|
-
const quoted = `"${table}"`;
|
|
6645
|
-
const col = quoted === quotedAs ? data.shape[key] : data.joinedShapes?.[tableName][key];
|
|
6646
|
-
if (jsonList) jsonList[as] = col && getSelectedColumnData(col);
|
|
6647
|
-
if (col) {
|
|
6648
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)}) "${as}"`;
|
|
6649
|
-
if (col.data.name && col.data.name !== key) return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
6650
6599
|
}
|
|
6651
|
-
|
|
6600
|
+
if (as && !dontAlias) sql = `${sql} "${as}"`;
|
|
6601
|
+
return sql;
|
|
6652
6602
|
};
|
|
6653
|
-
const
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quotedAs)}) "${as}"`;
|
|
6662
|
-
if (col.data.name && col.data.name !== column) return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
6603
|
+
const columnToSql = (ctx, data, shape, column, quotedAs, select, as, jsonList, useSelectList) => {
|
|
6604
|
+
let index = column.indexOf(".");
|
|
6605
|
+
if (index === -1 && !select) {
|
|
6606
|
+
const joinAs = data.valuesJoinedAs?.[column];
|
|
6607
|
+
if (joinAs) {
|
|
6608
|
+
column = joinAs + "." + column;
|
|
6609
|
+
index = joinAs.length;
|
|
6610
|
+
}
|
|
6663
6611
|
}
|
|
6664
|
-
return
|
|
6612
|
+
if (index !== -1) return tableColumnToSql(ctx, data, shape, column.slice(0, index), column.slice(index + 1), quotedAs, select, as, jsonList);
|
|
6613
|
+
return simpleColumnToSQL(ctx, data, shape, column, shape[column], quotedAs, select, as, jsonList, useSelectList);
|
|
6665
6614
|
};
|
|
6666
|
-
const rawOrColumnToSql = (ctx, data, expr, quotedAs,
|
|
6615
|
+
const rawOrColumnToSql = (ctx, data, shape, expr, quotedAs, select) => {
|
|
6667
6616
|
return typeof expr === "string" ? columnToSql(ctx, data, shape, expr, quotedAs, select) : expr.toSQL(ctx, quotedAs);
|
|
6668
6617
|
};
|
|
6669
6618
|
const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
@@ -6773,7 +6722,7 @@ const getConditionsFor3Or4LengthItem = (ctx, query, target, quotedAs, args, join
|
|
|
6773
6722
|
const [leftColumn, opOrRightColumn, maybeRightColumn] = args;
|
|
6774
6723
|
const op = maybeRightColumn ? opOrRightColumn : "=";
|
|
6775
6724
|
const rightColumn = maybeRightColumn ? maybeRightColumn : opOrRightColumn;
|
|
6776
|
-
return `${rawOrColumnToSql(ctx, query, leftColumn, target
|
|
6725
|
+
return `${rawOrColumnToSql(ctx, query, joinShape, leftColumn, target)} ${op} ${rawOrColumnToSql(ctx, query, query.shape, rightColumn, quotedAs)}`;
|
|
6777
6726
|
};
|
|
6778
6727
|
const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape) => {
|
|
6779
6728
|
if (data === true) return "true";
|
|
@@ -6783,7 +6732,7 @@ const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape)
|
|
|
6783
6732
|
const shape = query.shape;
|
|
6784
6733
|
for (const key in data) {
|
|
6785
6734
|
const value = data[key];
|
|
6786
|
-
pairs.push(`${columnToSql(ctx, query, joinShape, key, joinAs)} = ${rawOrColumnToSql(ctx, query, value, quotedAs
|
|
6735
|
+
pairs.push(`${columnToSql(ctx, query, joinShape, key, joinAs)} = ${rawOrColumnToSql(ctx, query, shape, value, quotedAs)}`);
|
|
6787
6736
|
}
|
|
6788
6737
|
return pairs.join(", ");
|
|
6789
6738
|
}
|
|
@@ -6815,7 +6764,7 @@ var SelectItemExpression = class extends Expression {
|
|
|
6815
6764
|
}
|
|
6816
6765
|
makeSQL(ctx, quotedAs) {
|
|
6817
6766
|
const q = this.q;
|
|
6818
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(q, quotedAs, void 0, ctx).join(", ") :
|
|
6767
|
+
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(q, quotedAs, void 0, ctx).join(", ") : columnToSql(ctx, q, q.shape, this.item, quotedAs, true) : this.item.toSQL(ctx, quotedAs);
|
|
6819
6768
|
}
|
|
6820
6769
|
};
|
|
6821
6770
|
const _getSelectableColumn = (q, arg) => {
|
|
@@ -7108,13 +7057,13 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7108
7057
|
(selected ??= {})[key] = `"${tableName}"`;
|
|
7109
7058
|
(selectedAs ??= {})[key] = key;
|
|
7110
7059
|
}
|
|
7111
|
-
sql =
|
|
7060
|
+
sql = tableColumnToSql(ctx, table.q, table.q.shape, tableName, key, quotedAs, true, key === "*" ? tableName : key, jsonList);
|
|
7112
7061
|
} else {
|
|
7113
7062
|
if (hookSelect?.get(item)) {
|
|
7114
7063
|
(selected ??= {})[item] = quotedAs;
|
|
7115
7064
|
(selectedAs ??= {})[item] = item;
|
|
7116
7065
|
}
|
|
7117
|
-
sql =
|
|
7066
|
+
sql = simpleColumnToSQL(ctx, table.q, table.q.shape, item, table.q.shape[item], quotedAs, true, item, jsonList);
|
|
7118
7067
|
}
|
|
7119
7068
|
}
|
|
7120
7069
|
list.push(sql);
|
|
@@ -7136,7 +7085,7 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7136
7085
|
}
|
|
7137
7086
|
else if (value) {
|
|
7138
7087
|
if (hookSelect) (selectedAs ??= {})[value] = as;
|
|
7139
|
-
list.push(
|
|
7088
|
+
list.push(columnToSql(ctx, table.q, table.q.shape, value, quotedAs, true, as, jsonList));
|
|
7140
7089
|
aliases?.push(as);
|
|
7141
7090
|
}
|
|
7142
7091
|
}
|
|
@@ -7172,12 +7121,12 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7172
7121
|
quotedTable = `"${tableName}"`;
|
|
7173
7122
|
columnName = select.slice(index + 1);
|
|
7174
7123
|
col = table.q.joinedShapes?.[tableName]?.[columnName];
|
|
7175
|
-
sql =
|
|
7124
|
+
sql = columnToSql(ctx, table.q, table.q.shape, select, void 0, true);
|
|
7176
7125
|
} else {
|
|
7177
7126
|
quotedTable = quotedAs;
|
|
7178
7127
|
columnName = select;
|
|
7179
7128
|
col = query.shape[select];
|
|
7180
|
-
sql =
|
|
7129
|
+
sql = columnToSql(ctx, table.q, query.shape, select, quotedAs, true);
|
|
7181
7130
|
}
|
|
7182
7131
|
} else {
|
|
7183
7132
|
columnName = column;
|
|
@@ -7451,7 +7400,7 @@ const whereExprOrQuery = (ctx, ands, query, key, value, quotedAs) => {
|
|
|
7451
7400
|
else {
|
|
7452
7401
|
let column = query.shape[key];
|
|
7453
7402
|
let quotedColumn;
|
|
7454
|
-
if (column) quotedColumn =
|
|
7403
|
+
if (column) quotedColumn = simpleColumnToSQL(ctx, query, query.shape, key, column, quotedAs);
|
|
7455
7404
|
else if (!column) {
|
|
7456
7405
|
const index = key.indexOf(".");
|
|
7457
7406
|
if (index !== -1) {
|
|
@@ -7459,7 +7408,7 @@ const whereExprOrQuery = (ctx, ands, query, key, value, quotedAs) => {
|
|
|
7459
7408
|
const quoted = `"${table}"`;
|
|
7460
7409
|
const name = key.slice(index + 1);
|
|
7461
7410
|
column = quotedAs === quoted ? query.shape[name] : query.joinedShapes?.[table]?.[name];
|
|
7462
|
-
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
7411
|
+
quotedColumn = simpleColumnToSQL(ctx, query, query.shape, name, column, quoted);
|
|
7463
7412
|
} else {
|
|
7464
7413
|
column = query.joinedShapes?.[key]?.value;
|
|
7465
7414
|
quotedColumn = `"${key}"."${key}"`;
|
|
@@ -8019,13 +7968,13 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
|
|
|
8019
7968
|
const order = dir || (!search.order || search.order === true ? emptyObject : search.order);
|
|
8020
7969
|
return `${order.coverDensity ? "ts_rank_cd" : "ts_rank"}(${order.weights ? `${addValue(ctx.values, `{${order.weights}}`)}, ` : ""}${search.vectorSQL}, "${column}"${order.normalization !== void 0 ? `, ${addValue(ctx.values, order.normalization)}` : ""}) ${order.dir || "DESC"}`;
|
|
8021
7970
|
}
|
|
8022
|
-
return `${
|
|
7971
|
+
return `${columnToSql(ctx, data, data.shape, column, quotedAs, void 0, void 0, void 0, true)} ${dir || "ASC"}`;
|
|
8023
7972
|
};
|
|
8024
7973
|
const windowToSql = (ctx, data, window, quotedAs) => {
|
|
8025
7974
|
if (typeof window === "string") return `"${window}"`;
|
|
8026
7975
|
if (isExpression(window)) return `(${window.toSQL(ctx, quotedAs)})`;
|
|
8027
7976
|
const sql = [];
|
|
8028
|
-
if (window.partitionBy) sql.push(`PARTITION BY ${Array.isArray(window.partitionBy) ? window.partitionBy.map((partitionBy) => rawOrColumnToSql(ctx, data, partitionBy, quotedAs)).join(", ") : rawOrColumnToSql(ctx, data, window.partitionBy, quotedAs)}`);
|
|
7977
|
+
if (window.partitionBy) sql.push(`PARTITION BY ${Array.isArray(window.partitionBy) ? window.partitionBy.map((partitionBy) => rawOrColumnToSql(ctx, data, data.shape, partitionBy, quotedAs)).join(", ") : rawOrColumnToSql(ctx, data, data.shape, window.partitionBy, quotedAs)}`);
|
|
8029
7978
|
if (window.order) sql.push(`ORDER BY ${orderByToSql(ctx, data, window.order, quotedAs)}`);
|
|
8030
7979
|
return `(${sql.join(" ")})`;
|
|
8031
7980
|
};
|
|
@@ -8092,7 +8041,7 @@ var FnExpression = class extends Expression {
|
|
|
8092
8041
|
const fnArgToSql = (ctx, data, arg, quotedAs) => {
|
|
8093
8042
|
if (typeof arg === "string") {
|
|
8094
8043
|
if (arg.endsWith(".*") || data.valuesJoinedAs?.[arg]) return columnToSql(ctx, data, data.shape, arg, quotedAs);
|
|
8095
|
-
return
|
|
8044
|
+
return columnToSql(ctx, data, data.shape, arg, quotedAs, true);
|
|
8096
8045
|
}
|
|
8097
8046
|
return arg.toSQL(ctx, quotedAs);
|
|
8098
8047
|
};
|
|
@@ -9447,7 +9396,7 @@ var OnConflictQueryBuilder = class {
|
|
|
9447
9396
|
const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
|
|
9448
9397
|
ctx.sql.push("DISTINCT");
|
|
9449
9398
|
if (distinct.length) {
|
|
9450
|
-
const columns = distinct?.map((item) => rawOrColumnToSql(ctx, table.q, item, quotedAs));
|
|
9399
|
+
const columns = distinct?.map((item) => rawOrColumnToSql(ctx, table.q, table.q.shape, item, quotedAs));
|
|
9451
9400
|
ctx.sql.push(`ON (${columns?.join(", ") || ""})`);
|
|
9452
9401
|
}
|
|
9453
9402
|
};
|
|
@@ -12357,7 +12306,7 @@ var ColumnRefExpression = class extends Expression {
|
|
|
12357
12306
|
Object.assign(this, value.operators);
|
|
12358
12307
|
}
|
|
12359
12308
|
makeSQL(ctx, quotedAs) {
|
|
12360
|
-
return
|
|
12309
|
+
return simpleColumnToSQL(ctx, emptyObject, emptyObject, this.name, this.result.value, quotedAs, void 0, void 0, void 0, void 0, true);
|
|
12361
12310
|
}
|
|
12362
12311
|
};
|
|
12363
12312
|
var OrExpression = class extends Expression {
|