@secondlayer/subgraphs 3.14.2 → 3.14.4

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.
@@ -520,21 +520,22 @@ class SubgraphContext {
520
520
  "_tx_id",
521
521
  "_created_at"
522
522
  ];
523
- const valuesList = Array.from(batch.rows.values()).map((r) => {
524
- const vals = [
523
+ if (this.journal) {
524
+ statements.push(this.journalCaptureSQL(batch.table, batch.keyCols, Array.from(batch.rows.values()).map((r) => batch.keyCols.map((k) => escapeLiteral(r.keys[k])))));
525
+ }
526
+ for (const r of batch.rows.values()) {
527
+ const keyPred = batch.keyCols.map((k) => `"${k}" = ${escapeLiteral(r.keys[k])}`).join(" AND ");
528
+ const updSet = batch.deltaCols.map((c) => `"${c}" = COALESCE("${c}", 0) + (${String(r.deltas[c] ?? 0n)})`).join(", ");
529
+ statements.push(`UPDATE ${qualifiedTable} SET ${updSet} WHERE ${keyPred}`);
530
+ const insertVals = [
525
531
  ...batch.keyCols.map((k) => escapeLiteral(r.keys[k])),
526
532
  ...batch.deltaCols.map((c) => String(r.deltas[c] ?? 0n)),
527
533
  escapeLiteral(r.meta.blockHeight),
528
534
  escapeLiteral(r.meta.txId),
529
535
  "NOW()"
530
536
  ];
531
- return `(${vals.join(", ")})`;
532
- }).join(", ");
533
- const setClauses = batch.deltaCols.map((c) => `"${c}" = COALESCE("${batch.table}"."${c}", 0) + EXCLUDED."${c}"`);
534
- if (this.journal) {
535
- statements.push(this.journalCaptureSQL(batch.table, batch.keyCols, Array.from(batch.rows.values()).map((r) => batch.keyCols.map((k) => escapeLiteral(r.keys[k])))));
537
+ statements.push(`INSERT INTO ${qualifiedTable} (${cols.map((c) => `"${c}"`).join(", ")}) ` + `SELECT ${insertVals.join(", ")} ` + `WHERE NOT EXISTS (SELECT 1 FROM ${qualifiedTable} WHERE ${keyPred})`);
536
538
  }
537
- statements.push(`INSERT INTO ${qualifiedTable} (${cols.map((c) => `"${c}"`).join(", ")}) VALUES ${valuesList} ` + `ON CONFLICT (${batch.keyCols.map((k) => `"${k}"`).join(", ")}) DO UPDATE SET ${setClauses.join(", ")}`);
538
539
  incBatch = null;
539
540
  incBatchKey = "";
540
541
  };
@@ -2760,5 +2761,5 @@ export {
2760
2761
  backfillSubgraph
2761
2762
  };
2762
2763
 
2763
- //# debugId=4535BB1C7C6ABE3264756E2164756E21
2764
+ //# debugId=7723AA51218664DB64756E2164756E21
2764
2765
  //# sourceMappingURL=reindex.js.map