Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021/// <reference types="node" />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<T = Record<string, unknown>>(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[]; }, };}