diff --git a/.changeset/wide-years-peel.md b/.changeset/wide-years-peel.md new file mode 100644 index 00000000000..cfac5e78c69 --- /dev/null +++ b/.changeset/wide-years-peel.md @@ -0,0 +1,5 @@ +--- +"@effect/sql-drizzle": patch +--- + +Remove special handling of execute, fix #5714 diff --git a/packages/sql-drizzle/src/internal/patch.ts b/packages/sql-drizzle/src/internal/patch.ts index d84a37748e0..efbc2fe39e5 100644 --- a/packages/sql-drizzle/src/internal/patch.ts +++ b/packages/sql-drizzle/src/internal/patch.ts @@ -48,14 +48,6 @@ export const makeRemoteCallback = Effect.gen(function*() { return (sql: string, params: Array, method: "all" | "execute" | "get" | "values" | "run") => { const runPromise = Runtime.runPromise(currentRuntime ? currentRuntime : constructionRuntime) const statement = client.unsafe(sql, params) - if (method === "execute") { - return runPromise(Effect.either(Effect.map(statement.raw, (header) => ({ rows: [header] })))).then((res) => { - if (res._tag === "Left") { - throw res.left.cause - } - return res.right - }) - } let effect: Effect.Effect = method === "all" || method === "values" ? statement.values : statement.withoutTransform diff --git a/packages/sql-drizzle/test/Pg.test.ts b/packages/sql-drizzle/test/Pg.test.ts index 1a21aee5969..17b1c86db3e 100644 --- a/packages/sql-drizzle/test/Pg.test.ts +++ b/packages/sql-drizzle/test/Pg.test.ts @@ -1,6 +1,7 @@ import { SqlClient } from "@effect/sql" import * as Pg from "@effect/sql-drizzle/Pg" import { assert, describe, it } from "@effect/vitest" +import { sql as dsql } from "drizzle-orm" import * as D from "drizzle-orm/pg-core" import { Effect, Layer } from "effect" import * as Logger from "effect/Logger" @@ -35,6 +36,27 @@ describe.sequential("Pg", () => { timeout: 60000 }) + it.effect("execute", () => + Effect.gen(function*() { + const sql = yield* SqlClient.SqlClient + const db = yield* Pg.PgDrizzle + + yield* sql`CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL, snake_case TEXT NOT NULL)` + yield* db.insert(users).values({ name: "Alice", snakeCase: "alice" }) + + const results = yield* db.execute<{ + id: number + name: string + }>(dsql`select id, name from users`) + + assert.deepStrictEqual(results, [{ id: 1, name: "Alice" }]) + }).pipe( + Effect.provide(DrizzlePgLive), + Effect.catchTag("ContainerError", () => Effect.void) + ), { + timeout: 60000 + }) + it.effect("orm", () => Effect.gen(function*() { const sql = yield* SqlClient.SqlClient