Browse Source

fix(sync): bind transaction inside effect

Kit Langton 3 weeks ago
parent
commit
a68395bfef
1 changed files with 18 additions and 16 deletions
  1. 18 16
      packages/opencode/src/sync/index.ts

+ 18 - 16
packages/opencode/src/sync/index.ts

@@ -235,22 +235,24 @@ export namespace SyncEvent {
           throw new Error(`SyncEvent.run: running old versions of events is not allowed: ${def.type}`)
         }
 
-        Database.transaction(
-          (tx) => {
-            const id = EventID.ascending()
-            const row = tx
-              .select({ seq: EventSequenceTable.seq })
-              .from(EventSequenceTable)
-              .where(eq(EventSequenceTable.aggregate_id, agg))
-              .get()
-            const seq = row?.seq != null ? row.seq + 1 : 0
-
-            const event = { id, seq, aggregateID: agg, data }
-            process(def, event, { publish: true })
-          },
-          {
-            behavior: "immediate",
-          },
+        yield* Effect.sync(() =>
+          Database.transaction(
+            (tx) => {
+              const id = EventID.ascending()
+              const row = tx
+                .select({ seq: EventSequenceTable.seq })
+                .from(EventSequenceTable)
+                .where(eq(EventSequenceTable.aggregate_id, agg))
+                .get()
+              const seq = row?.seq != null ? row.seq + 1 : 0
+
+              const event = { id, seq, aggregateID: agg, data }
+              process(def, event, { publish: true })
+            },
+            {
+              behavior: "immediate",
+            },
+          ),
         )
       })