Registry /
database / koishi-plugin-database-leveldb
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default export
✓ import KoishiDatabaseLeveldb from 'koishi-plugin-database-leveldb'
✗ const KoishiDatabaseLeveldb = require('koishi-plugin-database-leveldb')
CommonJS require() may not work if the package or its dependencies use ESM; recommended to use ESM imports.
apply function
✓ export const inject = ['database']; export async function apply(ctx: Context) { ... }
✗ function apply(ctx) { ... }
Must use export for apply and inject with TypeScript module augmentation; ensure 'database' is in inject array.
Tables type augmentation
✓ declare module 'koishi' { interface Tables { demo: DemoTable } }
✗ declare module 'koishi' { interface Tables { demo: DemoTable } }
The declaration must be inside a module augmentation, not a regular declaration. Ensure the module name is 'koishi'.
Shows how to define a table, inject database, and perform CRUD operations using Koishi's database interface with LevelDB backend.
import { Context } from 'koishi'
// Install plugin in your Koishi app
// app.plugin(require('koishi-plugin-database-leveldb'))
// or with ESM: import KoishiDatabaseLeveldb from 'koishi-plugin-database-leveldb'; app.plugin(KoishiDatabaseLeveldb)
// Then in a plugin:
declare module 'koishi' {
interface Tables {
todos: Todo
}
}
interface Todo {
id: number
content: string
completed: boolean
}
export const inject = ['database']
export async function apply(ctx: Context) {
ctx.model.extend('todos', {
id: 'integer',
content: 'string',
completed: 'boolean',
}, { primary: 'id' })
// Create a todo
await ctx.database.create('todos', { id: 1, content: 'Buy milk', completed: false })
// Read todos
const todos = await ctx.database.get('todos', {})
console.log(todos)
// Update a todo
await ctx.database.set('todos', { id: 1 }, { completed: true })
// Delete a todo
await ctx.database.remove('todos', { id: 1 })
}
Errors
Common errors & fixes
Error: Cannot find module 'koishi-plugin-database-leveldb'
Package not installed or not in node_modules.
fixRun 'npm install koishi-plugin-database-leveldb' or add to package.json.
TypeError: ctx.database.get is not a function
Missing 'database' injection; plugin did not request database service.
fixEnsure your plugin has 'export const inject = ['database']' and the database plugin is loaded before yours.
LeveldbError: IO error: ... LOCK: No such file or directory
Data directory not writable or parent directory missing.
fixCreate the 'data/database' directory or change the storage path via config.
TypeError: Cannot read property 'extend' of undefined
Database service not initialized; database plugin not properly loaded.
fixVerify that the database plugin (koishi-plugin-database-leveldb) is installed and registered via app.plugin() before using ctx.model.
Audit
Dependencies
koishirequiredPeer dependency; required as the bot framework to use this plugin