/// import { DatabaseSync } from 'node:sqlite'; import type { Sql } from '../src/index/model.ts'; /** Durable Object SQLite allows at most 100 bound parameters per query * (developers.cloudflare.com/durable-objects/platform/limits/); node:sqlite allows far more. */ export const DO_MAX_BOUND_PARAMETERS = 100; /** Implements the model's `Sql` interface over `node:sqlite`, the way the spec asks for in * tests. The DO implements the same interface over `ctx.storage.sql.exec(...).toArray()`. */ export function sqliteSql(db: DatabaseSync = new DatabaseSync(':memory:')): Sql { return { exec>(query: string, ...bindings: unknown[]): T[] { if (bindings.length > DO_MAX_BOUND_PARAMETERS) { throw new Error(`${bindings.length} bound parameters; Durable Object SQLite allows ${DO_MAX_BOUND_PARAMETERS}`); } return db.prepare(query).all(...(bindings as never[])) as T[]; }, }; }