examples/sqlite-raw/README.md
This example demonstrates using the raw SQLite driver with RivetKit actors.
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/sqlite-raw
npm install
npm run dev
@rivetkit/db/rawonMigrate to create tables on actor wakepnpm install
pnpm dev
To benchmark a large payload insert against a local RivetKit actor and compare it to native SQLite on disk:
pnpm bench:large-insert
Environment variables:
BENCH_MB: Total payload size in MiB. Defaults to 10.BENCH_ROWS: Number of rows to split the payload across. Defaults to 1.RIVET_ENDPOINT: Engine endpoint. Defaults to http://127.0.0.1:6420.The benchmark prints:
The example creates a todoList actor with the following actions:
addTodo(title: string) - Add a new todogetTodos() - Get all todostoggleTodo(id: number) - Toggle todo completion statusdeleteTodo(id: number) - Delete a todosrc/index.ts - Actor definition, migrations, and registry startupscripts/client.ts - Simple todo clientscripts/bench-large-insert.ts - Large-payload benchmark runnerThe database uses the KV-backed SQLite VFS, which stores data in a key-value store. The schema is created using raw SQL in the onMigrate hook:
db: db({
onMigrate: async (db) => {
await db.execute(`
CREATE TABLE IF NOT EXISTS todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
completed INTEGER DEFAULT 0,
created_at INTEGER NOT NULL
)
`);
},
})
MIT