Bun SQLite
Use this guide when your app runs on Bun and uses bun:sqlite.
The sqlfu project loop stays the same as Getting Started:
write schema SQL, draft migrations, write query SQL, generate wrappers. The
runtime adapter changes to createBunClient().
Config
Section titled “Config”The CLI can still use a local SQLite file path:
import {defineConfig} from 'sqlfu';
export default defineConfig({ db: './db/app.sqlite', definitions: './definitions.sql', migrations: './migrations', queries: './sql', generate: { sync: true, },});bun:sqlite is synchronous, so generate.sync: true keeps generated wrappers
synchronous too.
Schema and query
Section titled “Schema and query”create table jobs ( id integer primary key, name text not null, status text not null);Put the query in sql/queries.sql:
/** @name listJobsByStatus */select id, name, statusfrom jobswhere status = :statusorder by id;Generate the migration and wrappers:
npx sqlfu draftnpx sqlfu migratenpx sqlfu generateBun runtime
Section titled “Bun runtime”import {Database} from 'bun:sqlite';import {createBunClient} from 'sqlfu';
import {listJobsByStatus} from './sql/.generated/queries.sql.ts';
const db = new Database('./db/app.sqlite');const client = createBunClient(db);
const pendingJobs = listJobsByStatus(client, {status: 'pending'});The wrapper is the same wrapper you would call with node:sqlite or
better-sqlite3 when generate.sync: true is enabled.
Read next
Section titled “Read next”- Getting Started for the base SQL workflow.
- Adapters for the
bun:sqliteadapter snippet. - Type generation from SQL for params, list params, and generated row types.