opencode/packages/core/test/fixture/recorded-sql.ts
Sebastian 9c3f8311a6
Some checks are pending
bot-nix-hashes / compute (push) Blocked by required conditions
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-6vcpu-macos-latest, aarch64-darwin) (push) Waiting to run
bot-nix-hashes / publish (push) Blocked by required conditions
check-nix / nix-eval (push) Waiting to run
check / typecheck (push) Waiting to run
deploy-files / files-build (push) Waiting to run
deploy-files / files-deploy (push) Blocked by required conditions
deploy-site / site-deploy (push) Blocked by required conditions
deploy-site / site-build (push) Waiting to run
deploy / legacy-build (push) Waiting to run
deploy / legacy-deploy (push) Blocked by required conditions
deploy / data-build (push) Waiting to run
deploy / data-deploy (push) Blocked by required conditions
feat(server): sync and write several experimental spaces in one request (#66694)
Co-authored-by: kommander <335157+kommander@users.noreply.github.com>
2026-11-27 00:26:13 +01:00

38 lines
1.4 KiB
TypeScript

import { SqliteClient } from "@effect/sql-sqlite-bun"
import { Effect, Layer } from "effect"
import { Reactivity } from "effect/reactivity"
import { SqlClient, Statement } from "effect/sql"
/** An in-memory SQLite client that records every statement it runs, so a test can count them or ask SQLite how it plans them. */
export const recordedSql = () => {
const statements: Array<{ readonly query: string; readonly params: ReadonlyArray<unknown> }> = []
const layer = Layer.effect(
SqlClient.SqlClient,
Effect.gen(function* () {
const client = yield* SqlClient.SqlClient
const connection = yield* client.reserve
const record = (query: string, params: ReadonlyArray<unknown>) => statements.push({ query, params })
return yield* SqlClient.make({
acquirer: Effect.succeed({
...connection,
execute: (query, params, transform) => {
record(query, params)
return connection.execute(query, params, transform)
},
executeValues: (query, params) => {
record(query, params)
return connection.executeValues(query, params)
},
}),
compiler: Statement.makeCompilerSqlite(),
driver: client.driver,
spanAttributes: [],
})
}),
).pipe(
Layer.provide(SqliteClient.layer({ filename: ":memory:", disableWAL: true })),
Layer.provide(Reactivity.layer),
Layer.orDie,
)
return { statements, layer }
}