diff --git a/packages/alchemy/test/Cloudflare/D1/QueryDatabaseLocal.test.ts b/packages/alchemy/test/Cloudflare/D1/QueryDatabaseLocal.test.ts index 82c25b0479..4a62bf942f 100644 --- a/packages/alchemy/test/Cloudflare/D1/QueryDatabaseLocal.test.ts +++ b/packages/alchemy/test/Cloudflare/D1/QueryDatabaseLocal.test.ts @@ -85,3 +85,41 @@ test.provider( }).pipe(logLevel), { timeout: 120_000 }, ); + +// Expected to fail before reaching D1: Distilled validates params as string[], +// so .bind(42) throws "Expected string, got 42" during request encoding. +test.provider( + "QueryDatabaseLocal: binds numeric prepared-statement parameters", + (stack) => + Effect.gen(function* () { + yield* stack.destroy(); + + const out = yield* stack.deploy( + Effect.gen(function* () { + const database = yield* Cloudflare.D1.Database("NumericBindDatabase"); + + const Query = Action( + "QueryNumericBind", + Effect.gen(function* () { + const db = yield* Cloudflare.D1.QueryDatabase(database); + + return Effect.fn(function* () { + // Selecting the parameter directly rules out table schema or seed behavior. + return yield* db + .prepare("SELECT ? AS value") + .bind(42) + .first("value"); + }); + }).pipe(Effect.provide(Cloudflare.D1.QueryDatabaseLocal)), + ); + + return yield* Query({}); + }), + ); + + expect(out).toBe(42); + + yield* stack.destroy(); + }).pipe(logLevel), + { timeout: 120_000 }, +);