@palbase/backend 24.0.1 → 24.0.2

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.
@@ -3,7 +3,7 @@ import {
3
3
  BootRefused,
4
4
  createApp,
5
5
  loadConfig
6
- } from "../chunk-YSQBC2VL.js";
6
+ } from "../chunk-RPZNHY7J.js";
7
7
  import "../chunk-7Z6MGMXQ.js";
8
8
  import "../chunk-P2Q27SGP.js";
9
9
  import {
@@ -1589,7 +1589,7 @@ function isRef(v) {
1589
1589
  function isExpr(v) {
1590
1590
  return typeof v === "object" && v !== null && "$expr" in v;
1591
1591
  }
1592
- function renderValue(value, column, args, results, vectorCols) {
1592
+ function renderValue(value, column, args, results, vectorCols, transforms) {
1593
1593
  if (isRef(value)) {
1594
1594
  const source = results[value.$ref.op];
1595
1595
  const row = source?.rows[0];
@@ -1598,15 +1598,15 @@ function renderValue(value, column, args, results, vectorCols) {
1598
1598
  error_code: "tx_ref_unresolved"
1599
1599
  });
1600
1600
  }
1601
- return bindMaybeVector(args, column, vectorCols, row[value.$ref.field]);
1601
+ return bindMaybeVector(args, column, vectorCols, row[value.$ref.field], transforms);
1602
1602
  }
1603
1603
  if (isExpr(value)) {
1604
1604
  const fn = value.$expr;
1605
1605
  if (fn.fn === "now") return "now()";
1606
1606
  const operator = fn.fn === "inc" ? "+" : "-";
1607
- return `${quoteIdent(column)} ${operator} ${bindMaybeVector(args, column, vectorCols, fn.by)}`;
1607
+ return `${quoteIdent(column)} ${operator} ${bindMaybeVector(args, column, vectorCols, fn.by, transforms)}`;
1608
1608
  }
1609
- return bindMaybeVector(args, column, vectorCols, value);
1609
+ return bindMaybeVector(args, column, vectorCols, value, transforms);
1610
1610
  }
1611
1611
  function renderWhere(where, args, results) {
1612
1612
  const cols = Object.keys(where ?? {});
@@ -1618,21 +1618,26 @@ function renderWhere(where, args, results) {
1618
1618
  });
1619
1619
  return ` WHERE ${terms.join(" AND ")}`;
1620
1620
  }
1621
- function bindMaybeVector(args, column, vectorCols, value) {
1621
+ function bindMaybeVector(args, column, vectorCols, value, transforms) {
1622
1622
  if (column !== void 0 && vectorCols?.has(column) && Array.isArray(value)) {
1623
1623
  return args.bind(toVectorLiteral(value));
1624
1624
  }
1625
+ const t = column !== void 0 ? transforms?.get(column) : void 0;
1626
+ if (t?.toDb !== void 0 && value !== null && value !== void 0) {
1627
+ return args.bind(t.toDb(value));
1628
+ }
1625
1629
  return args.bind(value);
1626
1630
  }
1627
1631
  async function runPlanOp(sp, op, results) {
1628
1632
  const opVectorCols = vectorColumnsOf(currentSchema, op.table);
1633
+ const opTransforms = transformsOf(currentSchema, op.table);
1629
1634
  const args = new Args();
1630
1635
  const table = quoteIdent(op.table);
1631
1636
  let sql;
1632
1637
  switch (op.op) {
1633
1638
  case "insert": {
1634
1639
  const cols = Object.keys(op.values ?? {});
1635
- const rendered = cols.map((c) => renderValue(op.values[c], c, args, results, opVectorCols));
1640
+ const rendered = cols.map((c) => renderValue(op.values[c], c, args, results, opVectorCols, opTransforms));
1636
1641
  sql = cols.length ? `INSERT INTO ${table} (${cols.map(quoteIdent).join(", ")}) VALUES (${rendered.join(", ")}) RETURNING *` : `INSERT INTO ${table} DEFAULT VALUES RETURNING *`;
1637
1642
  break;
1638
1643
  }
@@ -1645,7 +1650,7 @@ async function runPlanOp(sp, op, results) {
1645
1650
  });
1646
1651
  }
1647
1652
  const rendered = cols.map(
1648
- (c) => renderValue(op.values[c], c, args, results, opVectorCols)
1653
+ (c) => renderValue(op.values[c], c, args, results, opVectorCols, opTransforms)
1649
1654
  );
1650
1655
  sql = `INSERT INTO ${table} (${cols.map(quoteIdent).join(", ")}) VALUES (${rendered.join(", ")}) ${onConflictTail(cols, conflict, "update")} RETURNING *`;
1651
1656
  break;
@@ -1655,7 +1660,7 @@ async function runPlanOp(sp, op, results) {
1655
1660
  if (rows.length === 0 || !rows[0]) return [];
1656
1661
  const cols = Object.keys(rows[0]);
1657
1662
  const tuples = rows.map(
1658
- (r) => `(${cols.map((c) => renderValue(r[c], c, args, results, opVectorCols)).join(", ")})`
1663
+ (r) => `(${cols.map((c) => renderValue(r[c], c, args, results, opVectorCols, opTransforms)).join(", ")})`
1659
1664
  );
1660
1665
  const conflictCols = op.onConflict ?? [];
1661
1666
  const tail = op.action !== void 0 && conflictCols.length > 0 ? ` ${onConflictTail(cols, conflictCols, op.action)}` : "";
@@ -1666,7 +1671,7 @@ async function runPlanOp(sp, op, results) {
1666
1671
  const cols = Object.keys(op.set ?? {});
1667
1672
  if (cols.length === 0) throw new Error(`update ${op.table}: nothing to set`);
1668
1673
  const assignments = cols.map(
1669
- (c) => `${quoteIdent(c)} = ${renderValue(op.set[c], c, args, results, opVectorCols)}`
1674
+ (c) => `${quoteIdent(c)} = ${renderValue(op.set[c], c, args, results, opVectorCols, opTransforms)}`
1670
1675
  );
1671
1676
  sql = `UPDATE ${table} SET ${assignments.join(", ")}${renderWhere(op.where, args, results)} RETURNING *`;
1672
1677
  break;
@@ -2401,4 +2406,4 @@ export {
2401
2406
  installEgressFence,
2402
2407
  createApp
2403
2408
  };
2404
- //# sourceMappingURL=chunk-YSQBC2VL.js.map
2409
+ //# sourceMappingURL=chunk-RPZNHY7J.js.map