pqb 0.67.7 → 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 +69 -6
- package/dist/index.js +105 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +105 -129
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +66 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -315,6 +315,29 @@ const templateLiteralSQLToCode = (sql) => {
|
|
|
315
315
|
code += parts[i];
|
|
316
316
|
return code + "`";
|
|
317
317
|
};
|
|
318
|
+
var SqlJoinExpression = class extends Expression {
|
|
319
|
+
constructor(items, separator) {
|
|
320
|
+
super();
|
|
321
|
+
this.items = items;
|
|
322
|
+
this.separator = separator;
|
|
323
|
+
this.result = { value: emptyObject };
|
|
324
|
+
this.q = { expr: this };
|
|
325
|
+
}
|
|
326
|
+
makeSQL(ctx, quotedAs) {
|
|
327
|
+
let sql = "";
|
|
328
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
329
|
+
if (i > 0) sql += this.separator ? this.separator.toSQL(ctx, quotedAs) : ", ";
|
|
330
|
+
const item = this.items[i];
|
|
331
|
+
if (item instanceof Expression) sql += item.toSQL(ctx, quotedAs);
|
|
332
|
+
else {
|
|
333
|
+
ctx.values.push(item);
|
|
334
|
+
sql += `$${ctx.values.length}`;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return sql;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
SqlJoinExpression.prototype.type = ExpressionTypeMethod.prototype.type;
|
|
318
341
|
/**
|
|
319
342
|
* Expression for a SQL identifier reference.
|
|
320
343
|
* Used to safely quote identifiers in raw SQL queries.
|
|
@@ -435,6 +458,7 @@ const sqlFn = ((...args) => {
|
|
|
435
458
|
return (...args) => new RawSql(args, arg);
|
|
436
459
|
});
|
|
437
460
|
sqlFn.ref = (name) => new SqlRefExpression(name);
|
|
461
|
+
sqlFn.join = (items, separator) => new SqlJoinExpression(items, separator);
|
|
438
462
|
sqlFn.unsafe = (sql) => new UnsafeSqlExpression(sql);
|
|
439
463
|
var UnsafeSqlExpression = class extends Expression {
|
|
440
464
|
constructor(sql) {
|
|
@@ -1818,6 +1842,8 @@ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
1818
1842
|
const base = {
|
|
1819
1843
|
equals: make((key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue(value, ctx, quotedAs)}`),
|
|
1820
1844
|
not: make((key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`),
|
|
1845
|
+
isDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS DISTINCT FROM ${quoteValue(value, ctx, quotedAs)}`),
|
|
1846
|
+
isNotDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS NOT DISTINCT FROM ${quoteValue(value, ctx, quotedAs)}`),
|
|
1821
1847
|
in: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "false" : `${key} IN ${quoteValue(value, ctx, quotedAs, true)}`),
|
|
1822
1848
|
notIn: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "true" : `NOT ${key} IN ${quoteValue(value, ctx, quotedAs, true)}`)
|
|
1823
1849
|
};
|
|
@@ -1849,9 +1875,11 @@ const ordinalText = {
|
|
|
1849
1875
|
};
|
|
1850
1876
|
const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1851
1877
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${options?.vars ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
|
|
1878
|
+
const shouldEncodeJson = (ctx) => ctx.q.adapter.driverAdapter.schemaConfig?.jsonEncodedByDriver === false;
|
|
1852
1879
|
const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
|
|
1853
1880
|
if (arg && typeof arg === "object") {
|
|
1854
|
-
if (IN && Array.isArray(arg)) return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value))
|
|
1881
|
+
if (IN && Array.isArray(arg)) return `(${arg.map((value) => shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(value)) : addValue(ctx.values, value)).join(", ")})`;
|
|
1882
|
+
if (Array.isArray(arg)) return shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(arg)) : addValue(ctx.values, arg);
|
|
1855
1883
|
if (isExpression(arg)) return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
|
|
1856
1884
|
if ("toSQL" in arg) return `to_jsonb((${moveMutativeQueryToCte$1(ctx, arg)}))`;
|
|
1857
1885
|
}
|
|
@@ -1876,6 +1904,8 @@ const Operators = {
|
|
|
1876
1904
|
...ord,
|
|
1877
1905
|
equals: make((key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NULL` : `${key} = ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1878
1906
|
not: make((key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NOT NULL` : `${key} != ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1907
|
+
isDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS DISTINCT FROM ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1908
|
+
isNotDistinctFrom: make((key, value, ctx, quotedAs) => `${key} IS NOT DISTINCT FROM ${quoteJsonValue(value, ctx, quotedAs)}`),
|
|
1879
1909
|
in: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "false" : `${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`),
|
|
1880
1910
|
notIn: make((key, value, ctx, quotedAs) => Array.isArray(value) && !value.length ? "true" : `NOT ${key} IN ${quoteJsonValue(value, ctx, quotedAs, true)}`),
|
|
1881
1911
|
jsonPathQueryFirst: Object.assign(function(path, options) {
|
|
@@ -6491,130 +6521,75 @@ const resolveSubQueryCallback = (q, cb) => {
|
|
|
6491
6521
|
_setSubQueryAliases(arg);
|
|
6492
6522
|
return cb(arg);
|
|
6493
6523
|
};
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
const { data } = column;
|
|
6504
|
-
return data.computed ? `(${data.computed.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
6505
|
-
}
|
|
6506
|
-
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
6507
|
-
let index = column.indexOf(".");
|
|
6508
|
-
if (index === -1) {
|
|
6509
|
-
const joinAs = data.valuesJoinedAs?.[column];
|
|
6510
|
-
if (joinAs) {
|
|
6511
|
-
column = joinAs + "." + column;
|
|
6512
|
-
index = joinAs.length;
|
|
6513
|
-
}
|
|
6514
|
-
}
|
|
6515
|
-
if (index !== -1) return columnWithDotToSql(ctx, data, shape, column, index, quotedAs, select);
|
|
6516
|
-
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
6517
|
-
};
|
|
6518
|
-
const selectedColumnToSql = (ctx, data, shape, column, quotedAs) => {
|
|
6519
|
-
const index = column.indexOf(".");
|
|
6520
|
-
return index !== -1 ? selectedColumnWithDotToSql(ctx, data, shape, column, index, quotedAs) : selectedSimpleColumnToSql(ctx, column, shape[column], quotedAs);
|
|
6521
|
-
};
|
|
6522
|
-
const selectedSimpleColumnToSql = (ctx, key, column, quotedAs) => {
|
|
6523
|
-
if (!column) return `"${key}"`;
|
|
6524
|
-
const { data } = column;
|
|
6525
|
-
return data.selectSql ? `(${data.selectSql.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
6526
|
-
};
|
|
6527
|
-
/**
|
|
6528
|
-
* in a case when ordering or grouping by a column which was selected as expression:
|
|
6529
|
-
* ```ts
|
|
6530
|
-
* table.select({ x: (q) => q.sum('x') }).group('x').order('x')
|
|
6531
|
-
* ```
|
|
6532
|
-
* the column must not be prefixed with a table name.
|
|
6533
|
-
*/
|
|
6534
|
-
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
6535
|
-
const index = column.indexOf(".");
|
|
6536
|
-
if (index !== -1) return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
|
|
6537
|
-
else {
|
|
6538
|
-
if (data.joinedShapes?.[column]) return `"${column}"."${column}"`;
|
|
6539
|
-
if (data.select) {
|
|
6540
|
-
for (const s of data.select) if (typeof s === "object" && "selectAs" in s) {
|
|
6541
|
-
if (column in s.selectAs) return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
6524
|
+
function simpleColumnToSQL(ctx, queryData, shape, key, column, quotedAs, select, as, jsonList, useSelectList, skipSelectSql) {
|
|
6525
|
+
let sql;
|
|
6526
|
+
let dontAlias;
|
|
6527
|
+
if (useSelectList && queryData.select) {
|
|
6528
|
+
for (const s of queryData.select) if (typeof s === "object" && "selectAs" in s) {
|
|
6529
|
+
if (key in s.selectAs) {
|
|
6530
|
+
dontAlias = true;
|
|
6531
|
+
sql = simpleColumnToSQL(ctx, queryData, shape, key, shape[key]);
|
|
6532
|
+
break;
|
|
6542
6533
|
}
|
|
6543
6534
|
}
|
|
6544
|
-
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
6545
6535
|
}
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
const
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
if (col.data.computed) return `(${col.data.computed.toSQL(ctx, quoted)})`;
|
|
6560
|
-
return `"${tableName}"."${key}"`;
|
|
6561
|
-
}
|
|
6562
|
-
return `"${tableName}"."${key}"`;
|
|
6563
|
-
};
|
|
6564
|
-
const selectedColumnWithDotToSql = (ctx, data, shape, column, index, quotedAs) => {
|
|
6565
|
-
const table = column.slice(0, index);
|
|
6566
|
-
const key = column.slice(index + 1);
|
|
6567
|
-
if (key === "*") {
|
|
6568
|
-
const shape = data.joinedShapes?.[table];
|
|
6569
|
-
return shape ? makeRowToJson(ctx, table, shape, true) : column;
|
|
6570
|
-
}
|
|
6571
|
-
const tableName = _getQueryAliasOrName(data, table);
|
|
6572
|
-
const quoted = `"${table}"`;
|
|
6573
|
-
const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
|
|
6574
|
-
if (col) {
|
|
6575
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)})`;
|
|
6576
|
-
if (col.data.name) return `"${tableName}"."${col.data.name}"`;
|
|
6536
|
+
if (!sql) if (!column) {
|
|
6537
|
+
dontAlias = key === as;
|
|
6538
|
+
sql = `${quotedAs ? `${quotedAs}.` : ""}"${key}"`;
|
|
6539
|
+
} else {
|
|
6540
|
+
if (jsonList && as) jsonList[as] = column && getSelectedColumnData(column);
|
|
6541
|
+
const { data } = column;
|
|
6542
|
+
if (select && data.selectSql && !skipSelectSql) sql = `(${data.selectSql.toSQL(ctx, quotedAs)})`;
|
|
6543
|
+
else if (data.computed) sql = `(${data.computed.toSQL(ctx, quotedAs)})`;
|
|
6544
|
+
else {
|
|
6545
|
+
const name = data.name || key;
|
|
6546
|
+
dontAlias = name === as;
|
|
6547
|
+
sql = `${quotedAs ? `${quotedAs}.` : ""}"${name}"`;
|
|
6548
|
+
}
|
|
6577
6549
|
}
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select, jsonList) => {
|
|
6550
|
+
if (as && !dontAlias) sql = `${sql} "${as}"`;
|
|
6551
|
+
return sql;
|
|
6552
|
+
}
|
|
6553
|
+
const tableColumnToSql = (ctx, data, shape, table, key, quotedAs, select, as, jsonList) => {
|
|
6554
|
+
let sql;
|
|
6555
|
+
let dontAlias;
|
|
6585
6556
|
if (key === "*") {
|
|
6586
|
-
if (jsonList) jsonList[as] = void 0;
|
|
6557
|
+
if (jsonList && as) jsonList[as] = void 0;
|
|
6587
6558
|
const shape = data.joinedShapes?.[table];
|
|
6588
|
-
if (shape) {
|
|
6589
|
-
|
|
6590
|
-
|
|
6559
|
+
if (shape) sql = select ? makeRowToJson(ctx, table, shape, true) : `"${table}".*`;
|
|
6560
|
+
else {
|
|
6561
|
+
sql = `"${table}"."${key}"`;
|
|
6562
|
+
dontAlias = true;
|
|
6563
|
+
}
|
|
6564
|
+
} else {
|
|
6565
|
+
const tableName = _getQueryAliasOrName(data, table);
|
|
6566
|
+
const quoted = `"${table}"`;
|
|
6567
|
+
const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
|
|
6568
|
+
if (jsonList && as) jsonList[as] = col && getSelectedColumnData(col);
|
|
6569
|
+
if (col?.data.selectSql) sql = `(${col.data.selectSql.toSQL(ctx, quoted)})`;
|
|
6570
|
+
else if (col?.data.name) sql = `"${tableName}"."${col.data.name}"`;
|
|
6571
|
+
else if (col?.data.computed) sql = `(${col.data.computed.toSQL(ctx, quoted)})`;
|
|
6572
|
+
else {
|
|
6573
|
+
sql = `"${tableName}"."${key}"`;
|
|
6574
|
+
dontAlias = key === as;
|
|
6591
6575
|
}
|
|
6592
|
-
return column;
|
|
6593
|
-
}
|
|
6594
|
-
const tableName = _getQueryAliasOrName(data, table);
|
|
6595
|
-
const quoted = `"${table}"`;
|
|
6596
|
-
const col = quoted === quotedAs ? data.shape[key] : data.joinedShapes?.[tableName][key];
|
|
6597
|
-
if (jsonList) jsonList[as] = col && getSelectedColumnData(col);
|
|
6598
|
-
if (col) {
|
|
6599
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)}) "${as}"`;
|
|
6600
|
-
if (col.data.name && col.data.name !== key) return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
6601
6576
|
}
|
|
6602
|
-
|
|
6577
|
+
if (as && !dontAlias) sql = `${sql} "${as}"`;
|
|
6578
|
+
return sql;
|
|
6603
6579
|
};
|
|
6604
|
-
const
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quotedAs)}) "${as}"`;
|
|
6613
|
-
if (col.data.name && col.data.name !== column) return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
6580
|
+
const columnToSql = (ctx, data, shape, column, quotedAs, select, as, jsonList, useSelectList) => {
|
|
6581
|
+
let index = column.indexOf(".");
|
|
6582
|
+
if (index === -1 && !select) {
|
|
6583
|
+
const joinAs = data.valuesJoinedAs?.[column];
|
|
6584
|
+
if (joinAs) {
|
|
6585
|
+
column = joinAs + "." + column;
|
|
6586
|
+
index = joinAs.length;
|
|
6587
|
+
}
|
|
6614
6588
|
}
|
|
6615
|
-
return
|
|
6589
|
+
if (index !== -1) return tableColumnToSql(ctx, data, shape, column.slice(0, index), column.slice(index + 1), quotedAs, select, as, jsonList);
|
|
6590
|
+
return simpleColumnToSQL(ctx, data, shape, column, shape[column], quotedAs, select, as, jsonList, useSelectList);
|
|
6616
6591
|
};
|
|
6617
|
-
const rawOrColumnToSql = (ctx, data, expr, quotedAs,
|
|
6592
|
+
const rawOrColumnToSql = (ctx, data, shape, expr, quotedAs, select) => {
|
|
6618
6593
|
return typeof expr === "string" ? columnToSql(ctx, data, shape, expr, quotedAs, select) : expr.toSQL(ctx, quotedAs);
|
|
6619
6594
|
};
|
|
6620
6595
|
const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
@@ -6724,7 +6699,7 @@ const getConditionsFor3Or4LengthItem = (ctx, query, target, quotedAs, args, join
|
|
|
6724
6699
|
const [leftColumn, opOrRightColumn, maybeRightColumn] = args;
|
|
6725
6700
|
const op = maybeRightColumn ? opOrRightColumn : "=";
|
|
6726
6701
|
const rightColumn = maybeRightColumn ? maybeRightColumn : opOrRightColumn;
|
|
6727
|
-
return `${rawOrColumnToSql(ctx, query, leftColumn, target
|
|
6702
|
+
return `${rawOrColumnToSql(ctx, query, joinShape, leftColumn, target)} ${op} ${rawOrColumnToSql(ctx, query, query.shape, rightColumn, quotedAs)}`;
|
|
6728
6703
|
};
|
|
6729
6704
|
const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape) => {
|
|
6730
6705
|
if (data === true) return "true";
|
|
@@ -6734,7 +6709,7 @@ const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape)
|
|
|
6734
6709
|
const shape = query.shape;
|
|
6735
6710
|
for (const key in data) {
|
|
6736
6711
|
const value = data[key];
|
|
6737
|
-
pairs.push(`${columnToSql(ctx, query, joinShape, key, joinAs)} = ${rawOrColumnToSql(ctx, query, value, quotedAs
|
|
6712
|
+
pairs.push(`${columnToSql(ctx, query, joinShape, key, joinAs)} = ${rawOrColumnToSql(ctx, query, shape, value, quotedAs)}`);
|
|
6738
6713
|
}
|
|
6739
6714
|
return pairs.join(", ");
|
|
6740
6715
|
}
|
|
@@ -6766,7 +6741,7 @@ var SelectItemExpression = class extends Expression {
|
|
|
6766
6741
|
}
|
|
6767
6742
|
makeSQL(ctx, quotedAs) {
|
|
6768
6743
|
const q = this.q;
|
|
6769
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(q, quotedAs, void 0, ctx).join(", ") :
|
|
6744
|
+
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);
|
|
6770
6745
|
}
|
|
6771
6746
|
};
|
|
6772
6747
|
const _getSelectableColumn = (q, arg) => {
|
|
@@ -7059,13 +7034,13 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7059
7034
|
(selected ??= {})[key] = `"${tableName}"`;
|
|
7060
7035
|
(selectedAs ??= {})[key] = key;
|
|
7061
7036
|
}
|
|
7062
|
-
sql =
|
|
7037
|
+
sql = tableColumnToSql(ctx, table.q, table.q.shape, tableName, key, quotedAs, true, key === "*" ? tableName : key, jsonList);
|
|
7063
7038
|
} else {
|
|
7064
7039
|
if (hookSelect?.get(item)) {
|
|
7065
7040
|
(selected ??= {})[item] = quotedAs;
|
|
7066
7041
|
(selectedAs ??= {})[item] = item;
|
|
7067
7042
|
}
|
|
7068
|
-
sql =
|
|
7043
|
+
sql = simpleColumnToSQL(ctx, table.q, table.q.shape, item, table.q.shape[item], quotedAs, true, item, jsonList);
|
|
7069
7044
|
}
|
|
7070
7045
|
}
|
|
7071
7046
|
list.push(sql);
|
|
@@ -7087,7 +7062,7 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7087
7062
|
}
|
|
7088
7063
|
else if (value) {
|
|
7089
7064
|
if (hookSelect) (selectedAs ??= {})[value] = as;
|
|
7090
|
-
list.push(
|
|
7065
|
+
list.push(columnToSql(ctx, table.q, table.q.shape, value, quotedAs, true, as, jsonList));
|
|
7091
7066
|
aliases?.push(as);
|
|
7092
7067
|
}
|
|
7093
7068
|
}
|
|
@@ -7123,12 +7098,12 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7123
7098
|
quotedTable = `"${tableName}"`;
|
|
7124
7099
|
columnName = select.slice(index + 1);
|
|
7125
7100
|
col = table.q.joinedShapes?.[tableName]?.[columnName];
|
|
7126
|
-
sql =
|
|
7101
|
+
sql = columnToSql(ctx, table.q, table.q.shape, select, void 0, true);
|
|
7127
7102
|
} else {
|
|
7128
7103
|
quotedTable = quotedAs;
|
|
7129
7104
|
columnName = select;
|
|
7130
7105
|
col = query.shape[select];
|
|
7131
|
-
sql =
|
|
7106
|
+
sql = columnToSql(ctx, table.q, query.shape, select, quotedAs, true);
|
|
7132
7107
|
}
|
|
7133
7108
|
} else {
|
|
7134
7109
|
columnName = column;
|
|
@@ -7402,7 +7377,7 @@ const whereExprOrQuery = (ctx, ands, query, key, value, quotedAs) => {
|
|
|
7402
7377
|
else {
|
|
7403
7378
|
let column = query.shape[key];
|
|
7404
7379
|
let quotedColumn;
|
|
7405
|
-
if (column) quotedColumn =
|
|
7380
|
+
if (column) quotedColumn = simpleColumnToSQL(ctx, query, query.shape, key, column, quotedAs);
|
|
7406
7381
|
else if (!column) {
|
|
7407
7382
|
const index = key.indexOf(".");
|
|
7408
7383
|
if (index !== -1) {
|
|
@@ -7410,7 +7385,7 @@ const whereExprOrQuery = (ctx, ands, query, key, value, quotedAs) => {
|
|
|
7410
7385
|
const quoted = `"${table}"`;
|
|
7411
7386
|
const name = key.slice(index + 1);
|
|
7412
7387
|
column = quotedAs === quoted ? query.shape[name] : query.joinedShapes?.[table]?.[name];
|
|
7413
|
-
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
7388
|
+
quotedColumn = simpleColumnToSQL(ctx, query, query.shape, name, column, quoted);
|
|
7414
7389
|
} else {
|
|
7415
7390
|
column = query.joinedShapes?.[key]?.value;
|
|
7416
7391
|
quotedColumn = `"${key}"."${key}"`;
|
|
@@ -7970,13 +7945,13 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
|
|
|
7970
7945
|
const order = dir || (!search.order || search.order === true ? emptyObject : search.order);
|
|
7971
7946
|
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"}`;
|
|
7972
7947
|
}
|
|
7973
|
-
return `${
|
|
7948
|
+
return `${columnToSql(ctx, data, data.shape, column, quotedAs, void 0, void 0, void 0, true)} ${dir || "ASC"}`;
|
|
7974
7949
|
};
|
|
7975
7950
|
const windowToSql = (ctx, data, window, quotedAs) => {
|
|
7976
7951
|
if (typeof window === "string") return `"${window}"`;
|
|
7977
7952
|
if (isExpression(window)) return `(${window.toSQL(ctx, quotedAs)})`;
|
|
7978
7953
|
const sql = [];
|
|
7979
|
-
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)}`);
|
|
7954
|
+
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)}`);
|
|
7980
7955
|
if (window.order) sql.push(`ORDER BY ${orderByToSql(ctx, data, window.order, quotedAs)}`);
|
|
7981
7956
|
return `(${sql.join(" ")})`;
|
|
7982
7957
|
};
|
|
@@ -8043,7 +8018,7 @@ var FnExpression = class extends Expression {
|
|
|
8043
8018
|
const fnArgToSql = (ctx, data, arg, quotedAs) => {
|
|
8044
8019
|
if (typeof arg === "string") {
|
|
8045
8020
|
if (arg.endsWith(".*") || data.valuesJoinedAs?.[arg]) return columnToSql(ctx, data, data.shape, arg, quotedAs);
|
|
8046
|
-
return
|
|
8021
|
+
return columnToSql(ctx, data, data.shape, arg, quotedAs, true);
|
|
8047
8022
|
}
|
|
8048
8023
|
return arg.toSQL(ctx, quotedAs);
|
|
8049
8024
|
};
|
|
@@ -9398,7 +9373,7 @@ var OnConflictQueryBuilder = class {
|
|
|
9398
9373
|
const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
|
|
9399
9374
|
ctx.sql.push("DISTINCT");
|
|
9400
9375
|
if (distinct.length) {
|
|
9401
|
-
const columns = distinct?.map((item) => rawOrColumnToSql(ctx, table.q, item, quotedAs));
|
|
9376
|
+
const columns = distinct?.map((item) => rawOrColumnToSql(ctx, table.q, table.q.shape, item, quotedAs));
|
|
9402
9377
|
ctx.sql.push(`ON (${columns?.join(", ") || ""})`);
|
|
9403
9378
|
}
|
|
9404
9379
|
};
|
|
@@ -12308,7 +12283,7 @@ var ColumnRefExpression = class extends Expression {
|
|
|
12308
12283
|
Object.assign(this, value.operators);
|
|
12309
12284
|
}
|
|
12310
12285
|
makeSQL(ctx, quotedAs) {
|
|
12311
|
-
return
|
|
12286
|
+
return simpleColumnToSQL(ctx, emptyObject, emptyObject, this.name, this.result.value, quotedAs, void 0, void 0, void 0, void 0, true);
|
|
12312
12287
|
}
|
|
12313
12288
|
};
|
|
12314
12289
|
var OrExpression = class extends Expression {
|
|
@@ -14237,6 +14212,7 @@ function _createDbSqlMethod(columnTypes) {
|
|
|
14237
14212
|
return sql;
|
|
14238
14213
|
});
|
|
14239
14214
|
fn.ref = sqlFn.ref;
|
|
14215
|
+
fn.join = sqlFn.join;
|
|
14240
14216
|
fn.unsafe = sqlFn.unsafe;
|
|
14241
14217
|
return fn;
|
|
14242
14218
|
}
|