SQL.LibSQL reference
LibSQL
Section titled “LibSQL”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) wrapped in a chainable Proxy, so it can be
resolved once at init and used 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 built lazily on the first query and memoized on the
current execution’s Scope (via makeExecutionMemo), so it’s
created 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. Resolving the URL and token is likewise
deferred, so deploy / plan-time invocations never connect.