Skip to content
Closed
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
38 changes: 38 additions & 0 deletions packages/alchemy/test/Cloudflare/D1/QueryDatabaseLocal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>("value");
});
}).pipe(Effect.provide(Cloudflare.D1.QueryDatabaseLocal)),
);

return yield* Query({});
}),
);

expect(out).toBe(42);

yield* stack.destroy();
}).pipe(logLevel),
{ timeout: 120_000 },
);