Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wide-years-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/sql-drizzle": patch
---

Remove special handling of execute, fix #5714
8 changes: 0 additions & 8 deletions packages/sql-drizzle/src/internal/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
currentRuntime = pre
return out
},
catch: (cause) => new SqlError({ cause, message: "Failed to execute QueryPromise" })

Check failure on line 29 in packages/sql-drizzle/src/internal/patch.ts

View workflow job for this annotation

GitHub Actions / Test (Node 3/4)

test/Mysql.test.ts > Mysql > orm

SqlError: Failed to execute QueryPromise ❯ catch src/internal/patch.ts:29:29 ❯ ../effect/src/internal/core-effect.ts:1683:29 ❯ ../effect/src/internal/fiberRuntime.ts:1146:41 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { span: undefined, _tag: 'SqlError' } Caused by: TypeError: Cannot read properties of undefined (reading 'insertId') ❯ PreparedQuery.execute ../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@op-eng_35891bb4102b4f80e0c9a0c31edccf6f/node_modules/src/mysql-proxy/session.ts:122:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { span: undefined }

Check failure on line 29 in packages/sql-drizzle/src/internal/patch.ts

View workflow job for this annotation

GitHub Actions / Test (Node 3/4)

test/Mysql.test.ts > Mysql > works

SqlError: Failed to execute QueryPromise ❯ catch src/internal/patch.ts:29:29 ❯ ../effect/src/internal/core-effect.ts:1683:29 ❯ ../effect/src/internal/fiberRuntime.ts:1146:41 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { span: undefined, _tag: 'SqlError' } Caused by: Caused by: TypeError: Cannot read properties of undefined (reading 'insertId') ❯ PreparedQuery.execute ../../node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@op-eng_35891bb4102b4f80e0c9a0c31edccf6f/node_modules/src/mysql-proxy/session.ts:122:29 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { span: undefined }
})
)
)
Expand All @@ -48,14 +48,6 @@
return (sql: string, params: Array<any>, 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<any, SqlError> = method === "all" || method === "values"
? statement.values
: statement.withoutTransform
Expand Down
22 changes: 22 additions & 0 deletions packages/sql-drizzle/test/Pg.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading