Effect CommunityEC
Effect Community15mo ago
5 replies
André König

Handling Transactions with SqlResolver in TypeScript

Currently, I have the first case where I have to write data transactionally, but having a hard time to make TypeScript happy. What is the recommended way of doing transactions with SqlResolver (or SqlSchema)?

Currently I'm trying to use the SqlResolver:

const Insert = yield* SqlResolver.ordered("InsertEntity", {
  Request: InsertEntitySchema,
  Result: Entity,
  execute: (requests) =>
    sql.withTransaction(Effect.gen(function* () {
      yield* sql`
          INSERT INTO entities
          ${sql.insert(requests)}
          RETURNING entities.*
      `;

      // How to perform the other inserts here?
      // `requests` is an array. Do I have to extract the entries manually?
    }))
});
Was this page helpful?