Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/rooms

Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.

FollowForkOpen app

Files

test-db.ts

16 lines · 639 B · TypeScript
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<null | number | string>
			if (/^\s*(SELECT|WITH)|RETURNING/i.test(query)) return { rows: statement.all(...values) as Array<Record<string, unknown>> }
			statement.run(...values)
			return { rows: [] }
		},
	}
}