| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 3 个月前 | ||
| 4 个月前 | ||
| 6 个月前 | ||
| 5 个月前 | ||
| 5 个月前 | ||
| 30 天前 | ||
| 6 个月前 | ||
| 7 个月前 |
SQLite Raw Example
This example demonstrates using the raw SQLite driver with RivetKit actors.
Getting Started
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/sqlite-raw
npm install
npm run dev
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
Large Insert Benchmark
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 to10.BENCH_ROWS: Number of rows to split the payload across. Defaults to1.RIVET_ENDPOINT: Engine endpoint. Defaults tohttp://127.0.0.1:6420.
The benchmark prints:
- Actor-side SQLite insert time
- End-to-end action latency
- Native SQLite baseline latency
- Relative slowdown versus native SQLite
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/index.ts- Actor definition, migrations, and registry startupscripts/client.ts- Simple todo clientscripts/bench-large-insert.ts- Large-payload benchmark runner
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
)
`);
},
})
License
MIT