Skip to content

SQL.LibSQL reference

Source: packages/sql/src/SQLite.ts

Open an @effect/sql-libsql client over a SQLite database through libSQL — a Turso database, any other libSQL server, or a local file: database.

Accepts the client returned by Turso.Connect(db) (or any { url, authToken }) and returns a LibsqlClient (which implements the generic SqlClient interface). Resolve it once at Construction phase and use it from any handler:

import * as SQL from "@alchemy.run/sql/SQLite";
const conn = yield* Turso.Connect(Db);
const sql = yield* SQL.LibSQL(conn);
fetch: Effect.gen(function* () {
const users = yield* sql`SELECT * FROM users`;
});

The client is a real LibsqlClient: sql`...`, sql.insert and sql.and build and compile statements with @effect/sql-libsql’s own code, with no connection. Running a statement opens the database. It is opened at most once per execution — a Worker fetch/queue/scheduled event, a Durable Object call, a Workflow run, or a Lambda invocation — and closed when the event settles. The URL and token resolve then too, so deploy / plan-time invocations never connect.