Database (@swelte/plus)
Embedded SQLite/KV — beyond-SvelteKit, optional package. A single SQLite file (WAL mode) lives
next to the binary. Core stays parity-only; plus owns the swelte migrate CLI.
npm install @swelte/plusSWELTE_PLUGINS=@swelte/plus/db swelte migrate
# created src/lib/backend/db.v (backend-only helper)
# created db/migrations/001_swelte_kv.sql
# migrated: 001_swelte_kv.sql
# migrate: applied 1 migration(s)// src/lib/backend/db.v (scaffolded by swelte migrate)
module backend
import db.sqlite
__global swelte_db = sqlite.DB{}
pub fn db() !sqlite.DB { ... } // WAL, shared conn
pub fn kv_set(key string, value string) ! { ... } // exec_none (101)
pub fn kv_get(key string) !string { ... } // exec + get_string
pub fn kv_del(key string) ! { ... }First run scaffolds src/lib/backend/db.v (backend-only, importable from #routes/*.v, never from the browser) + db/migrations/001_swelte_kv.sql,
then applies db/migrations/*.sql in order (tracked in _swelte_migrations, idempotent). App tables are your own SQL; the swelte_kv table is available for app-owned key/value data. ISR owns its HTML cache; the browser outbox uses
IndexedDB. Durable jobs use a separate scheduler SQLite file.
Gotcha: exec vs exec_none
V's db.sqlite exec() only steps row-returning queries — DDL/DML
(CREATE/INSERT/UPDATE/DELETE) silently no-op through it. Use exec_none() and expect 101 (SQLITE_DONE). SELECTs keep exec() + Row.get_string/get_int.
PostgreSQL through V
The Plus plugin provides SQLite/KV. V also supplies db.pg, ORM support, pooling, parameterized queries and transactions. Use those
facilities from native backend modules with the required libpq dependencies. Initialize shared
resources during startup and close them after shutdown draining. The disposable PostgreSQL fixture
probes transaction, migration, locking and failure cleanup; application schemas and migration
policy remain application-owned.