@rawdash/adapter-libsql
v0.28.0
Published
Rawdash libSQL/Turso storage adapter
Readme
@rawdash/adapter-libsql
libSQL / Turso storage adapter for rawdash.
What it is
@rawdash/adapter-libsql is a ServerStorage implementation backed by libSQL — works against any libSQL endpoint (Turso Cloud, self-hosted libsql-server, or a local file).
Internals: Kysely for type-safe queries on top of @libsql/client. Runs on Node and Cloudflare Workers / V8 edge from the same package.
Install
npm install @rawdash/adapter-libsql @libsql/client @rawdash/hono @hono/node-serverQuick example
import { serve as honoServe } from '@hono/node-server';
import { createClient } from '@libsql/client';
import { LibsqlStorage } from '@rawdash/adapter-libsql';
import { defineConfig } from '@rawdash/core';
import { mountEngine } from '@rawdash/hono';
const storage = new LibsqlStorage({
client: createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
}),
});
const config = defineConfig({
connectors: [],
dashboards: {},
});
const { app } = mountEngine(config, { storage });
honoServe({ fetch: app.fetch, port: 8080 });On Cloudflare Workers, import from @libsql/client/web and pass the resulting client in the same way.
Migrations
The Drizzle schema in src/drizzle-schema.ts is the source of truth.
pnpm db:generaterunsdrizzle-kit generateto emit a newmigrations/NNNN_*.sqlfile, then inlines the SQL intosrc/migrations-bundle.ts(formatted to match the repo's Prettier config so the regeneration is byte-stable).- The bundle is committed so the package can ship to npm without a build step. CI runs
pnpm --filter @rawdash/adapter-libsql db:bundleand fails if the result differs from what's checked in — this catches.sqlmigrations added without regenerating the bundle. - At runtime,
LibsqlStorageapplies pending migrations fromMIGRATIONSon first use and records applied versions in aschema_migrationstable. The runtime applier reads from the inlined array — no filesystem access — so it works on Cloudflare Workers and other edge runtimes.
License
Apache-2.0
