Features
- Raw SQLite API: Direct SQL access using
@rivetkit/db/raw - Migrations on Wake: Uses
onMigrateto create tables on actor wake - Todo List: Simple CRUD operations with raw SQL queries
Running the Example
pnpm install
pnpm dev
Usage
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 todo
Code Structure
src/registry.ts- Actor definition with database configurationsrc/server.ts- Server entry point
Database
The 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
)
`);
},
})

