Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iterate/sqlfu/llms.txt

Use this file to discover all available pages before exploring further.

Turso and libSQL offer several deployment modes: a local embedded file, a remote Turso Cloud database, and a sync mode that keeps a local file in sync with Turso Cloud. sqlfu supports all of them through adapter factories that share the same typed client surface — your application code stays the same regardless of which mode you run in. Most Turso and libSQL drivers are asynchronous. Generated wrappers reflect that, returning promises at each call site.

Configuration

For a @libsql/client-based setup that works locally and in production with a URL swap:
sqlfu.config.ts
import {createClient} from '@libsql/client';
import {defineConfig, createLibsqlClient} from 'sqlfu';

export default defineConfig({
  db: () => {
    const raw = createClient({
      url: process.env.TURSO_DATABASE_URL || 'file:./db/app.sqlite',
      authToken: process.env.TURSO_AUTH_TOKEN,
    });

    return {
      client: createLibsqlClient(raw),
      async [Symbol.asyncDispose]() {
        await raw.close();
      },
    };
  },
  definitions: './definitions.sql',
  migrations: './migrations',
  queries: './sql',
});
With url: 'file:./db/app.sqlite' locally and libsql://... in production, sqlfu commands (migrate, check, the UI) always operate on the same database your app uses — no separate scratch file.
Set TURSO_DATABASE_URL and TURSO_AUTH_TOKEN in your environment for Turso Cloud access. Locally, omit both and the file: fallback keeps everything on disk.

Schema and queries

definitions.sql
create table organizations (
  id integer primary key,
  slug text not null unique,
  name text not null
);
sql/queries.sql
/** @name findOrganization */
select id, slug, name
from organizations
where slug = :slug
limit 1;
npx sqlfu draft
npx sqlfu migrate
npx sqlfu generate

Choosing a driver

The most versatile option. Use file: URLs locally and libsql:// in production with no code changes at the sqlfu boundary:
src/db.ts
import {createClient} from '@libsql/client';
import {createLibsqlClient} from 'sqlfu';

import {findOrganization} from './sql/.generated/queries.sql.ts';

const raw = createClient({
  url: process.env.TURSO_DATABASE_URL!,
  authToken: process.env.TURSO_AUTH_TOKEN,
});
const client = createLibsqlClient(raw);

const organization = await findOrganization(client, {slug: 'acme'});
Install:
npm install sqlfu @libsql/client

Choosing between local and remote

A few rules of thumb:
  • Local dev, remote prod with no code changes: use @libsql/client. Set url: 'file:app.db' locally and libsql://... in production.
  • Edge runtimes or serverless without native deps: use @tursodatabase/serverless.
  • Embedded database that syncs to Turso Cloud: use @tursodatabase/sync.
  • Fastest pure-local experience on Node with native bindings: use @tursodatabase/database.

Adapters reference

Every Turso and libSQL adapter snippet with the full compatibility matrix.

Cloudflare D1 guide

Use sqlfu with D1 on Cloudflare Workers.

Build docs developers (and LLMs) love