@monopi/db

Shared SQLite database for monopi extensions with Drizzle ORM, migration support, and schema module registration.

Packages

Package details

package

Install @monopi/db from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@monopi/db
Package
@monopi/db
Version
0.6.1
Published
Aug 28, 2026
Downloads
263/mo · 36/wk
Author
ifiokjr
License
MIT
Types
package
Size
27.7 KB
Dependencies
2 dependencies · 1 peer

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@monopi/db

Shared SQLite database for monopi extensions.

Why

All monopi extensions that need persistence use this single database instead of each opening a private .db file. This reduces file handles, simplifies backups, and enables cross-extension queries.

Usage

Register a schema module

import { registerSchemaModule, runMigrations, getSharedDatabase } from "@monopi/db";

// Declare your extension's tables
registerSchemaModule({
	id: "analytics",
	migrations: [
		`CREATE TABLE IF NOT EXISTS analytics_sessions (
			id TEXT PRIMARY KEY,
			started_at INTEGER NOT NULL
		);`,
	],
	tables: ["analytics_sessions"],
});

// Run all pending migrations (call once at startup)
runMigrations();

// Use the shared database
const db = getSharedDatabase();
db.run`INSERT INTO analytics_sessions (id, started_at) VALUES (?, ?)`;

Database path

The database lives at ~/.pi/agent/monopi.db by default. Override for testing:

import { setDatabasePath } from "@monopi/db";

setDatabasePath("/tmp/test.db");