pqb 0.31.4 → 0.31.6
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.js +75 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1776,35 +1776,68 @@ function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
|
|
|
1776
1776
|
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
1777
1777
|
}
|
|
1778
1778
|
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
1779
|
-
var _a
|
|
1779
|
+
var _a;
|
|
1780
1780
|
const index = column.indexOf(".");
|
|
1781
1781
|
if (index !== -1) {
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1782
|
+
return columnWithDotToSql(
|
|
1783
|
+
ctx,
|
|
1784
|
+
data,
|
|
1785
|
+
shape,
|
|
1786
|
+
column,
|
|
1787
|
+
index,
|
|
1788
|
+
quotedAs,
|
|
1789
|
+
select
|
|
1790
|
+
);
|
|
1791
|
+
}
|
|
1792
|
+
if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
|
|
1793
|
+
return `"${column}".r`;
|
|
1794
|
+
}
|
|
1795
|
+
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
1796
|
+
};
|
|
1797
|
+
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
1798
|
+
var _a;
|
|
1799
|
+
const index = column.indexOf(".");
|
|
1800
|
+
if (index !== -1) {
|
|
1801
|
+
return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
|
|
1802
|
+
} else {
|
|
1803
|
+
if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
|
|
1804
|
+
return `"${column}".r`;
|
|
1805
|
+
}
|
|
1806
|
+
if (data.select) {
|
|
1807
|
+
for (const s of data.select) {
|
|
1808
|
+
if (typeof s === "object" && "selectAs" in s) {
|
|
1809
|
+
if (column in s.selectAs) {
|
|
1810
|
+
return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1787
1813
|
}
|
|
1788
|
-
return column;
|
|
1789
1814
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
}
|
|
1800
|
-
return `"${tableName}"."${key}"`;
|
|
1815
|
+
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
|
|
1819
|
+
var _a, _b, _c, _d;
|
|
1820
|
+
const table = column.slice(0, index);
|
|
1821
|
+
const key = column.slice(index + 1);
|
|
1822
|
+
if (key === "*") {
|
|
1823
|
+
if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
|
|
1824
|
+
return select ? `row_to_json("${table}".*)` : `"${table}".r`;
|
|
1801
1825
|
}
|
|
1802
|
-
return
|
|
1826
|
+
return column;
|
|
1803
1827
|
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1828
|
+
const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
|
|
1829
|
+
const quoted = `"${table}"`;
|
|
1830
|
+
const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
|
|
1831
|
+
if (col) {
|
|
1832
|
+
if (col.data.name) {
|
|
1833
|
+
return `"${tableName}"."${col.data.name}"`;
|
|
1834
|
+
}
|
|
1835
|
+
if (col.data.computed) {
|
|
1836
|
+
return `${col.data.computed.toSQL(ctx, quoted)}`;
|
|
1837
|
+
}
|
|
1838
|
+
return `"${tableName}"."${key}"`;
|
|
1806
1839
|
}
|
|
1807
|
-
return
|
|
1840
|
+
return `"${tableName}"."${key}"`;
|
|
1808
1841
|
};
|
|
1809
1842
|
const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
|
|
1810
1843
|
var _a, _b, _c, _d;
|
|
@@ -4036,7 +4069,7 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
|
|
|
4036
4069
|
const order = dir || (!search.order || search.order === true ? orchidCore.emptyObject : search.order);
|
|
4037
4070
|
return `${order.coverDensity ? "ts_rank_cd" : "ts_rank"}(${order.weights ? `${orchidCore.addValue(ctx.values, `{${order.weights}}`)}, ` : ""}${search.vectorSQL}, "${column}"${order.normalization !== void 0 ? `, ${orchidCore.addValue(ctx.values, order.normalization)}` : ""}) ${order.dir || "DESC"}`;
|
|
4038
4071
|
}
|
|
4039
|
-
return `${
|
|
4072
|
+
return `${maybeSelectedColumnToSql(ctx, data, column, quotedAs)} ${dir || "ASC"}`;
|
|
4040
4073
|
};
|
|
4041
4074
|
|
|
4042
4075
|
const windowToSql = (ctx, data, window, quotedAs) => {
|
|
@@ -4354,14 +4387,7 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
4354
4387
|
const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
|
|
4355
4388
|
sql = `"${name}" = excluded."${name}"`;
|
|
4356
4389
|
} else if ("except" in merge) {
|
|
4357
|
-
|
|
4358
|
-
const except = orchidCore.toArray(merge.except);
|
|
4359
|
-
for (let i = 0; i < columns.length; i++) {
|
|
4360
|
-
if (!except.includes(columns[i])) {
|
|
4361
|
-
notExcluded.push(quotedColumns[i]);
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
sql = mergeColumnsSql(notExcluded);
|
|
4390
|
+
sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
|
|
4365
4391
|
} else {
|
|
4366
4392
|
sql = merge.reduce((sql2, item, i) => {
|
|
4367
4393
|
var _a2;
|
|
@@ -4370,7 +4396,7 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
4370
4396
|
}, "");
|
|
4371
4397
|
}
|
|
4372
4398
|
} else {
|
|
4373
|
-
sql = mergeColumnsSql(quotedColumns);
|
|
4399
|
+
sql = mergeColumnsSql(columns, quotedColumns, target);
|
|
4374
4400
|
}
|
|
4375
4401
|
ctx.sql.push("DO UPDATE SET", sql);
|
|
4376
4402
|
} else if (query.onConflict.set) {
|
|
@@ -4398,8 +4424,22 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
4398
4424
|
pushWhereStatementSql(ctx, q, query, quotedAs);
|
|
4399
4425
|
return pushReturningSql(ctx, q, query, quotedAs, query.afterCreateSelect);
|
|
4400
4426
|
};
|
|
4401
|
-
const mergeColumnsSql = (quotedColumns2) => {
|
|
4402
|
-
|
|
4427
|
+
const mergeColumnsSql = (columns, quotedColumns2, target, except) => {
|
|
4428
|
+
const notExcluded = [];
|
|
4429
|
+
const exclude = typeof target === "string" ? [target] : Array.isArray(target) ? [...target] : [];
|
|
4430
|
+
if (except) {
|
|
4431
|
+
if (typeof except === "string") {
|
|
4432
|
+
exclude.push(except);
|
|
4433
|
+
} else {
|
|
4434
|
+
exclude.push(...except);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
for (let i = 0; i < columns.length; i++) {
|
|
4438
|
+
if (!exclude.includes(columns[i])) {
|
|
4439
|
+
notExcluded.push(quotedColumns2[i]);
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4442
|
+
return notExcluded.map((column) => `${column} = excluded.${column}`).join(", ");
|
|
4403
4443
|
};
|
|
4404
4444
|
const encodeRow = (ctx, q, QueryClass, row, runtimeDefaults, quotedAs) => {
|
|
4405
4445
|
const arr = row.map((value) => {
|
|
@@ -4786,7 +4826,7 @@ const makeSQL = (table, options) => {
|
|
|
4786
4826
|
}
|
|
4787
4827
|
if (query.group) {
|
|
4788
4828
|
const group = query.group.map(
|
|
4789
|
-
(item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) :
|
|
4829
|
+
(item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) : maybeSelectedColumnToSql(ctx, table.q, item, quotedAs)
|
|
4790
4830
|
);
|
|
4791
4831
|
sql.push(`GROUP BY ${group.join(", ")}`);
|
|
4792
4832
|
}
|