import { DatabaseSync } from 'node:sqlite' import type { Db } from './db.ts' /** In-memory SQLite with the same `sql()` shape as Kody package storage. Tests only. */ export function memoryDb(): Db { const db = new DatabaseSync(':memory:') return { async sql(query, params = []) { const statement = db.prepare(query) const values = params.map((value) => (typeof value === 'boolean' ? Number(value) : value)) as Array if (/^\s*(SELECT|WITH)|RETURNING/i.test(query)) return { rows: statement.all(...values) as Array> } statement.run(...values) return { rows: [] } }, } }