Skip to main content
ctx.database (PluginDatabaseAccessor) opens (or creates) an SQLite database file scoped to your plugin’s data directory at {userData}/plugins-data/{pluginId}/. It returns a better-sqlite3 Database instance.
const db = ctx.database.open("landing-reports.db");

db.exec(`
  CREATE TABLE IF NOT EXISTS reports (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    flight_id TEXT NOT NULL,
    landing_rate REAL,
    created_at TEXT DEFAULT (datetime('now'))
  )
`);

const insert = db.prepare(
  "INSERT INTO reports (flight_id, landing_rate) VALUES (?, ?)",
);
insert.run("VA123", -180.5);

const rows = db.prepare("SELECT * FROM reports").all();
ctx.logger.info("DB", `Found ${rows.length} landing reports`);
The directory is created automatically on first use. Each plugin gets its own isolated directory — plugins cannot access each other’s databases. When to use it: for structured or larger datasets a plugin needs to persist locally — landing history, cached rosters, anything relational or queryable. For a handful of simple values, ctx.config is lighter.