Skip to content

Turso

Turso hosts SQLite databases for you. Create them in the same Stack as your Workers, and query them with Effect SQL or Drizzle.

New here? Set up credentials first, then build the tutorial.

Every database lives in a group. The group decides where its databases run.

import * as Turso from "alchemy/Turso";
export const Group = Turso.Group("Group", { location: "aws-us-east-1" });
export const Db = Effect.gen(function* () {
const group = yield* Group;
return yield* Turso.Database("Db", {
group: group.name,
migrations: "./migrations",
});
});

Each deploy runs any new migrations. See Migrations.

Turso.Connect gives the Worker the database’s URL and a token. Pass it to Drizzle or Effect SQL:

const conn = yield* Turso.Connect(Db);
const db = yield* Drizzle.LibSQL(conn);

See Connections.

Turso databases are cheap, so you can give each customer their own. Turso.ManageDatabases lets a Worker create, query, and delete databases in one group:

const tenants = yield* Turso.ManageDatabases(Tenants);
const acme = yield* tenants.create("acme");
const sql = yield* SQL.LibSQL(tenants.connect(acme.name));

The tutorial builds this step by step. The Database per tenant guide has the details.