[]previous and next page

Turso

Turso runs libSQL as a hosted service, so the code above is already a Turso app: only the environment changes.

For agentsUpdated

Turso runs libSQL as a hosted service, so the code above is already a Turso app: only the environment changes.

sh
DATABASE_URL=libsql://my-database-my-org.turso.io
DATABASE_AUTH_TOKEN=<a token for this database>

Create the token with the Turso CLI and keep it in the host's secret store. createClient chooses the transport from the URL: libsql:// and https:// use the network, file: opens a local database file.

Edge runtimes (Cloudflare Workers, Vercel Edge, Netlify Edge) cannot open files or load native modules. Import the client that speaks HTTP and WebSocket only, and keep the rest of the code as it is:

src/server/edge-db.server.tsts
import { createClient } from "@libsql/client/web";
import { drizzle } from "drizzle-orm/libsql/web";
import * as schema from "./schema";

/** A client for runtimes without a file system. On Workers read the values from the environment binding. */
export function openEdge(url: string, authToken: string) {
  return drizzle(createClient({ url, authToken }), { schema });
}

Connection pooling is the database's job here: Turso accepts many short HTTP connections, so a serverless function needs no pooler. For a server that runs for a long time, one client per process, as above, is enough.