pqb 0.31.4 → 0.31.5
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 +57 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1774,35 +1774,68 @@ function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
|
|
|
1774
1774
|
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
1775
1775
|
}
|
|
1776
1776
|
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
1777
|
-
var _a
|
|
1777
|
+
var _a;
|
|
1778
1778
|
const index = column.indexOf(".");
|
|
1779
1779
|
if (index !== -1) {
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1780
|
+
return columnWithDotToSql(
|
|
1781
|
+
ctx,
|
|
1782
|
+
data,
|
|
1783
|
+
shape,
|
|
1784
|
+
column,
|
|
1785
|
+
index,
|
|
1786
|
+
quotedAs,
|
|
1787
|
+
select
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1790
|
+
if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
|
|
1791
|
+
return `"${column}".r`;
|
|
1792
|
+
}
|
|
1793
|
+
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
1794
|
+
};
|
|
1795
|
+
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
1796
|
+
var _a;
|
|
1797
|
+
const index = column.indexOf(".");
|
|
1798
|
+
if (index !== -1) {
|
|
1799
|
+
return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
|
|
1800
|
+
} else {
|
|
1801
|
+
if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
|
|
1802
|
+
return `"${column}".r`;
|
|
1803
|
+
}
|
|
1804
|
+
if (data.select) {
|
|
1805
|
+
for (const s of data.select) {
|
|
1806
|
+
if (typeof s === "object" && "selectAs" in s) {
|
|
1807
|
+
if (column in s.selectAs) {
|
|
1808
|
+
return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1785
1811
|
}
|
|
1786
|
-
return column;
|
|
1787
1812
|
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
}
|
|
1798
|
-
return `"${tableName}"."${key}"`;
|
|
1813
|
+
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
|
|
1817
|
+
var _a, _b, _c, _d;
|
|
1818
|
+
const table = column.slice(0, index);
|
|
1819
|
+
const key = column.slice(index + 1);
|
|
1820
|
+
if (key === "*") {
|
|
1821
|
+
if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
|
|
1822
|
+
return select ? `row_to_json("${table}".*)` : `"${table}".r`;
|
|
1799
1823
|
}
|
|
1800
|
-
return
|
|
1824
|
+
return column;
|
|
1801
1825
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1826
|
+
const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
|
|
1827
|
+
const quoted = `"${table}"`;
|
|
1828
|
+
const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
|
|
1829
|
+
if (col) {
|
|
1830
|
+
if (col.data.name) {
|
|
1831
|
+
return `"${tableName}"."${col.data.name}"`;
|
|
1832
|
+
}
|
|
1833
|
+
if (col.data.computed) {
|
|
1834
|
+
return `${col.data.computed.toSQL(ctx, quoted)}`;
|
|
1835
|
+
}
|
|
1836
|
+
return `"${tableName}"."${key}"`;
|
|
1804
1837
|
}
|
|
1805
|
-
return
|
|
1838
|
+
return `"${tableName}"."${key}"`;
|
|
1806
1839
|
};
|
|
1807
1840
|
const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
|
|
1808
1841
|
var _a, _b, _c, _d;
|
|
@@ -4034,7 +4067,7 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
|
|
|
4034
4067
|
const order = dir || (!search.order || search.order === true ? emptyObject : search.order);
|
|
4035
4068
|
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"}`;
|
|
4036
4069
|
}
|
|
4037
|
-
return `${
|
|
4070
|
+
return `${maybeSelectedColumnToSql(ctx, data, column, quotedAs)} ${dir || "ASC"}`;
|
|
4038
4071
|
};
|
|
4039
4072
|
|
|
4040
4073
|
const windowToSql = (ctx, data, window, quotedAs) => {
|
|
@@ -4784,7 +4817,7 @@ const makeSQL = (table, options) => {
|
|
|
4784
4817
|
}
|
|
4785
4818
|
if (query.group) {
|
|
4786
4819
|
const group = query.group.map(
|
|
4787
|
-
(item) => isExpression(item) ? item.toSQL(ctx, quotedAs) :
|
|
4820
|
+
(item) => isExpression(item) ? item.toSQL(ctx, quotedAs) : maybeSelectedColumnToSql(ctx, table.q, item, quotedAs)
|
|
4788
4821
|
);
|
|
4789
4822
|
sql.push(`GROUP BY ${group.join(", ")}`);
|
|
4790
4823
|
}
|