@vibeorm/sql 5.6.0 → 5.7.0

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/ast.d.ts CHANGED
@@ -1393,7 +1393,10 @@ export type ChainResult = {
1393
1393
  * array_agg("__vibe_i")::text FROM (SELECT DISTINCT ARRAY["c0", "c1"] AS
1394
1394
  * "__vibe_i" FROM "step" LIMIT $n) AS "__vibe_d")` — a two-dimensional text
1395
1395
  * array literal of at most `limit` distinct images, NULL when the step
1396
- * returned no row. A before image skips the rows whose arm marker is true.
1396
+ * returned no row. With `inserted`, both read the update arm's rows only
1397
+ * (`WHERE NOT` the marker), and `_a` is left out with `insertedOnly`;
1398
+ * - `<alias>_ia` (with `inserted` and `after`): the insert arm's after images
1399
+ * (`WHERE` the marker), so an upsert's after images arrive per arm.
1397
1400
  *
1398
1401
  * `before` / `after` name columns the step RETURNS (its
1399
1402
  * {@link CaptureReturningColumn} aliases), in image order. `limit` is bound once.
@@ -1403,7 +1406,7 @@ export type ChainCapture = {
1403
1406
  readonly alias: string;
1404
1407
  /** The step's `"inserted"` arm-marker column, for an `INSERT … ON CONFLICT DO UPDATE` step. */
1405
1408
  readonly inserted?: string;
1406
- /** With `inserted`: images of inserted rows only — `after` reads the rows whose marker is true. */
1409
+ /** With `inserted`: images of inserted rows only — `<alias>_ia`, no `<alias>_a`. */
1407
1410
  readonly insertedOnly?: true;
1408
1411
  readonly before?: readonly string[];
1409
1412
  readonly after?: readonly string[];
package/dist/index.js CHANGED
@@ -5596,8 +5596,12 @@ function captureAliases(params) {
5596
5596
  out.push(`${entry.alias}_i`);
5597
5597
  if (entry.before !== undefined && entry.before.length > 0)
5598
5598
  out.push(`${entry.alias}_b`);
5599
- if (entry.after !== undefined && entry.after.length > 0)
5600
- out.push(`${entry.alias}_a`);
5599
+ if (entry.after !== undefined && entry.after.length > 0) {
5600
+ if (entry.inserted === undefined || entry.insertedOnly !== true)
5601
+ out.push(`${entry.alias}_a`);
5602
+ if (entry.inserted !== undefined)
5603
+ out.push(`${entry.alias}_ia`);
5604
+ }
5601
5605
  }
5602
5606
  return out;
5603
5607
  }
@@ -5622,10 +5626,13 @@ function renderChainCaptures(params) {
5622
5626
  const limit = collector.add(entry.limit);
5623
5627
  const item = quote("__vibe_i");
5624
5628
  const image = (columns, filter) => `(SELECT array_agg(${item})::text FROM (SELECT DISTINCT ARRAY[${columns.map(quote).join(", ")}] AS ${item} FROM ${step}${filter} LIMIT ${limit}) AS ${quote("__vibe_d")})`;
5629
+ const updatedRows = marker === undefined ? "" : ` WHERE NOT ${marker}`;
5625
5630
  if (before.length > 0)
5626
- out.push(`${image(before, marker === undefined ? "" : ` WHERE NOT ${marker}`)} AS ${quote(`${entry.alias}_b`)}`);
5627
- if (after.length > 0)
5628
- out.push(`${image(after, marker !== undefined && entry.insertedOnly === true ? ` WHERE ${marker}` : "")} AS ${quote(`${entry.alias}_a`)}`);
5631
+ out.push(`${image(before, updatedRows)} AS ${quote(`${entry.alias}_b`)}`);
5632
+ if (after.length > 0 && (marker === undefined || entry.insertedOnly !== true))
5633
+ out.push(`${image(after, updatedRows)} AS ${quote(`${entry.alias}_a`)}`);
5634
+ if (after.length > 0 && marker !== undefined)
5635
+ out.push(`${image(after, ` WHERE ${marker}`)} AS ${quote(`${entry.alias}_ia`)}`);
5629
5636
  }
5630
5637
  return out;
5631
5638
  }
@@ -6580,4 +6587,4 @@ export {
6580
6587
  toPgArrayLiteral
6581
6588
  };
6582
6589
 
6583
- //# debugId=FBE116988ABE557464756E2164756E21
6590
+ //# debugId=0EA38AD633C52F8C64756E2164756E21