feat: add session persistence examples and SQLite driver

This commit is contained in:
Nathan Flurry 2026-02-11 20:29:03 -08:00
parent 64d1324628
commit 3c2a9cbbbb
14 changed files with 524 additions and 11 deletions

View file

@ -17,6 +17,7 @@
}
},
"dependencies": {
"better-sqlite3": "^11.0.0",
"sandbox-agent": "workspace:*"
},
"files": [
@ -29,6 +30,7 @@
"test:watch": "vitest"
},
"devDependencies": {
"@types/better-sqlite3": "^7.0.0",
"@types/node": "^22.0.0",
"tsup": "^8.0.0",
"typescript": "^5.7.0",

View file

@ -1,4 +1,4 @@
import { DatabaseSync } from "node:sqlite";
import Database from "better-sqlite3";
import type {
ListEventsRequest,
ListPage,
@ -12,16 +12,13 @@ const DEFAULT_LIST_LIMIT = 100;
export interface SQLiteSessionPersistDriverOptions {
filename?: string;
open?: boolean;
}
export class SQLiteSessionPersistDriver implements SessionPersistDriver {
private readonly db: DatabaseSync;
private readonly db: Database.Database;
constructor(options: SQLiteSessionPersistDriverOptions = {}) {
this.db = new DatabaseSync(options.filename ?? ":memory:", {
open: options.open ?? true,
});
this.db = new Database(options.filename ?? ":memory:");
this.initialize();
}

View file

@ -7,4 +7,5 @@ export default defineConfig({
sourcemap: true,
clean: true,
target: "es2022",
external: ["better-sqlite3"],
});