Adapters — SQLite Web (WASM)
Use the SQLite Web adapter to run SQLite in the browser via WASM. You keep the same vibecode‑db client API; only the storage changes.
Execution rule: In v1.0,
.select(projection)executes the query — chain filters/modifiers before calling it. Writes (insert,update,delete) execute immediately.
When to use
- Offline‑first or read‑heavy browser apps
- Low‑latency UX with local data
Installation
1pnpm add @vibecode-db/client @vibecode-db/sqlite-web
2# or: npm i ... | yarn add ...Note:
@vibecode-db/sqlite-webdepends on@vibecode-db/sqlite-core, which in turn depends on@vibecode-db/client. You do not need to importsqlite-coredirectly.
Minimal wiring
1// db/client.web.ts
2import { createClient } from '@vibecode-db/client'
3import { SQLiteWebAdapter } from '@vibecode-db/sqlite-web'
4import { db } from './schema' // your defineSchema(...) export
5
6export const vibecode = createClient({
7 dbSpec: {
8 schema: db.zodBundle,
9 relations: db.relations, // recommended for relation-aware projections
10 // seed?: { ... } // optional boot data (adapter policy-dependent)
11 // meta?: { ... } // optional adapter-specific metadata
12 },
13 adapter: (ctx) => new SQLiteWebAdapter(ctx, {
14 // common options:
15 // wasm: { wasmUrl: '/sql-wasm.wasm' }, // path to sqlite WASM asset
16 }),
17})Adapter options
| Option | Type | Purpose |
|---|---|---|
wasm.wasmUrl | string | Path to the SQLite WASM binary served by your app. |
Relational reads — current SQLite limits
The SQLite adapters implement “SELECT list + LEFT JOINs for one‑level many‑to‑one nesting.”
- ✅
todos → users(name)via.select('id, title, users(name)') - ❌ Deep chains (
a → b → c) and inline 1→M expansions aren’t executed today — use two queries or DB‑side views.
Example: first query
1// one-level M→1 nested projection
2const todos = await vibecode
3 .from('todos')
4 .where({ user_id: 1 })
5 .order('created_at', { ascending: false })
6 .limit(10)
7 .select('id, title, users(name)')Note
Memory: ephemeral (tab‑scoped); fastest for smoke tests.
Seeding (
dbSpec.seed) behavior is adapter‑policy: common pattern is insert‑if‑empty on first run.
Summary
SQLite Web gives you instant, local reads/writes with a portable query surface. Start local, keep your schema/types, and stay free to swap to Supabase or SQLite Expo later — without touching your UI queries.