@playfast/reform-db-sqlite
v1.0.1
Published
bun:sqlite engine for @playfast/reform-db — a Db driver backed by Bun's built-in SQLite, with emulated reactivity and serialize()/deserialize() snapshots.
Maintainers
Readme
@playfast/reform-db-sqlite
The bun:sqlite engine for @playfast/reform-db.
Backs the engine-neutral Db driver from @playfast/reform-db with
Bun's built-in SQLite. Zero native dependencies (it's part of the Bun runtime),
serialize()/deserialize() snapshots, and emulated reactivity — SQLite has no
native live queries, so a live DbQuery re-runs after every write. Your tables,
queries, and migrations stay defined in the engine-neutral core.
Bun only.
bun:sqliteexists only under the Bun runtime. Import this package from code that runs on Bun; on Node the module import fails (surfaced as aDbError).
Install
bun add @playfast/reform-db-sqlite @playfast/reform-db kyselyeffect, kysely, @playfast/reform, and @playfast/reform-db are peer
dependencies.
Quick Start
import { DbSchema, DbTable, DbColumn, Migration } from '@playfast/reform-db'
import { Sqlite } from '@playfast/reform-db-sqlite'
import { Layer } from 'effect'
const AppDb = DbSchema.make('app', { tables: [/* … */] })
// IMPORTANT: render migrations for the SQLite dialect.
const migrations = Migration.fromSchema(AppDb, Migration.sqlite)
// Persistent (a file on disk):
const DataLayer = QueriesAndProcedures.pipe(
Layer.provideMerge(Sqlite.layer({ filename: 'app.db', migrations })),
)
// Ephemeral in-memory — the default for tests / proofs:
const TestLayer = QueriesAndProcedures.pipe(
Layer.provideMerge(Sqlite.memory({ migrations })),
)Both layers build the Db service synchronously (bun:sqlite opens on a background
fiber inside makeDriver), so they slot straight under reform's runSync scene /
proof mount.
Type storage
SQLite has no native boolean or json types, so the engine stores them as integer
(0/1) and text (JSON) respectively. The column Schemas in @playfast/reform-db
are engine-tolerant, so DbColumn.boolean() / DbColumn.json(schema) decode back to a
real boolean / object on read — the same table definition works on both engines.
API
Sqlite.layer(options?)— persistent (or in-memory, iffilenameis omitted)Db. Options:filename?,migrations?,loadDataDir?(seed from a priordumpBlob).Sqlite.memory(options?)— ephemeral in-memoryDb. Options:migrations?,loadDataDir?.makeSqliteEngine(options)— the rawDbEngine, for wiringmakeDriveryourself.
Snapshotting: driver.dump() returns a Blob of Database.serialize() bytes; feed it
back via loadDataDir to boot a database already populated (Database.deserialize).
License
MIT
