@broberg/db-sdk
v0.1.0
Published
Thin shared database client for the WebHouse fleet — one DB SDK, every project. Turso/libSQL today; Postgres/Supabase transports later. Pilot: Buddy Cloud (F067).
Readme
@broberg/db-sdk
The WebHouse fleet's shared database transport — one thin facade every
project depends on, instead of scattering driver calls across repos. The same
play as @broberg/ai-sdk, for
the data layer.
Turso/libSQL today; Postgres/Supabase transports planned behind the same API. Pilot consumer: Buddy Cloud (F067).
Install
bun add @broberg/db-sdk
# or: npm i @broberg/db-sdkUse
import { createClient, createReplica, health } from '@broberg/db-sdk';
// Remote (cloud hub). Reads TURSO_DATABASE_URL + TURSO_AUTH_TOKEN from env.
const db = createClient();
await health(db); // { ok: true, version: "3.45.1" }
// Embedded replica (edge daemon): a local file synced from the remote primary.
const edge = createReplica({ path: '/data/buddy.db', syncIntervalSeconds: 30 });
// reads hit the local file at SQLite speed; writes forward to the primary
await edge.sync(); // or rely on the intervalThin by design. No ORM coupling — layer Drizzle in the consumer:
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@broberg/db-sdk';
const orm = drizzle(createClient(), { schema });API
| Export | Signature | What it does |
|---|---|---|
| createClient | (cfg?: DbConfig) => Client | Remote client. cfg: { url?, authToken?, backend? } (env fallback). |
| createReplica | (cfg: ReplicaConfig) => Client | Embedded replica. cfg: { path, syncUrl?, authToken?, syncIntervalSeconds?, backend? }. |
| health | (client) => Promise<{ ok, version }> | Liveness + SQLite-version probe. |
Re-exports Client / ResultSet (from @libsql/client) and the config types.
Multi-backend roadmap
backend defaults to 'libsql' (Turso) — the only transport implemented today.
postgres / supabase are the planned extension points: a new transport lands
under src/backends/ and widens the Backend union, without changing the
public createClient / createReplica surface. The domain layer (ORM, schema,
tenant-scoping) stays in each consumer.
License
FSL-1.1-Apache-2.0 © Christian Broberg
