> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skyvexsoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ctx.database

> Per-plugin SQLite storage from a background module.

`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](https://github.com/WiseLibs/better-sqlite3) `Database` instance.

```ts theme={null}
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`](/sdk/background/context/config) is lighter.
