Skip to content
pre-alpha. The TypeScript API may still shift. The SQL won't.

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().

The CLI can use the default .sqlfu/app.db local SQLite file:

import {defineConfig} from 'sqlfu';
export default defineConfig({
definitions: './definitions.sql',
migrations: './migrations',
queries: './sql',
generate: {
sync: true,
},
});

bun:sqlite is synchronous, so generate.sync: true keeps generated wrappers synchronous too.

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, status
from jobs
where status = :status
order by id;

Generate the migration and wrappers:

Terminal window
npx sqlfu draft
npx sqlfu migrate
npx sqlfu generate
import {Database} from 'bun:sqlite';
import {createBunClient} from 'sqlfu';
import {listJobsByStatus} from './sql/.generated/queries.sql.ts';
const db = new Database('./.sqlfu/app.db');
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.