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 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, _b, _c, _d, _e;
1779
+ var _a;
1780
1780
  const index = column.indexOf(".");
1781
1781
  if (index !== -1) {
1782
- const table = column.slice(0, index);
1783
- const key = column.slice(index + 1);
1784
- if (key === "*") {
1785
- if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
1786
- return select ? `row_to_json("${table}".*)` : `"${table}".r`;
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
- const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
1791
- const quoted = `"${table}"`;
1792
- const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
1793
- if (col) {
1794
- if (col.data.name) {
1795
- return `"${tableName}"."${col.data.name}"`;
1796
- }
1797
- if (col.data.computed) {
1798
- return `${col.data.computed.toSQL(ctx, quoted)}`;
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 `"${tableName}"."${key}"`;
1826
+ return column;
1803
1827
  }
1804
- if (!select && ((_e = data.joinedShapes) == null ? void 0 : _e[column])) {
1805
- return `"${column}".r`;
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 simpleColumnToSQL(ctx, column, shape[column], quotedAs);
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 `${columnToSql(ctx, data, data.shape, column, quotedAs)} ${dir || "ASC"}`;
4072
+ return `${maybeSelectedColumnToSql(ctx, data, column, quotedAs)} ${dir || "ASC"}`;
4040
4073
  };
4041
4074
 
4042
4075
  const windowToSql = (ctx, data, window, quotedAs) => {
@@ -4786,7 +4819,7 @@ const makeSQL = (table, options) => {
4786
4819
  }
4787
4820
  if (query.group) {
4788
4821
  const group = query.group.map(
4789
- (item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) : columnToSql(ctx, table.q, table.q.shape, item, quotedAs)
4822
+ (item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) : maybeSelectedColumnToSql(ctx, table.q, item, quotedAs)
4790
4823
  );
4791
4824
  sql.push(`GROUP BY ${group.join(", ")}`);
4792
4825
  }