t3-code-android-nightly/.repos/effect-smol/packages/sql/pg/test/TransactionAcquire.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

45 lines
1.4 KiB
TypeScript

import { PgClient } from "@effect/sql-pg"
import { assert, it } from "@effect/vitest"
import { Effect } from "effect"
import * as Reactivity from "effect/reactivity/Reactivity"
import { Duplex } from "node:stream"
it.effect("withTransaction surfaces stream factory failures instead of defecting", () =>
Effect.gen(function*() {
const sql = yield* PgClient.make({
username: "test",
stream: () => {
throw new Error("stream factory failed")
}
})
const error = yield* Effect.flip(sql.withTransaction(sql`SELECT 1`))
assert.strictEqual(error.reason._tag, "ConnectionError")
assert.strictEqual(error.reason.operation, "connect")
}).pipe(
Effect.scoped,
Effect.provide(Reactivity.layer)
))
it.effect("withTransaction surfaces startup transport failures instead of defecting", () =>
Effect.gen(function*() {
const sql = yield* PgClient.make({
username: "test",
stream: () =>
new Duplex({
read() {},
write(_chunk, _encoding, callback) {
callback(new Error("startup write failed"))
}
})
})
const error = yield* Effect.flip(sql.withTransaction(sql`SELECT 1`))
assert.strictEqual(error.reason._tag, "ConnectionError")
assert.strictEqual(error.reason.operation, "connect")
}).pipe(
Effect.scoped,
Effect.provide(Reactivity.layer)
))