Koishi Database Console
raw JSON →koishi-plugin-database-console is a Koishi plugin designed to extend the Koishi Console with a graphical user interface for managing data stored via Minato, Koishi's universal database abstraction layer. It enables bot administrators to view and potentially manipulate their bot's underlying data directly within the Koishi web interface, abstracting away the need for external database management tools. Currently at version 0.2.3, this plugin operates within the active Koishi ecosystem, which generally sees frequent minor updates and periodic major version releases. Its primary differentiator is the seamless integration into the existing Koishi Console, offering a centralized management experience for chatbot operations and data. This allows for easier debugging, data inspection, and simplified administration, especially for those less familiar with direct database interaction.
Common errors
error Error: Plugin 'koishi-plugin-database-console' requires @koishijs/plugin-console@^5.29.4, got 5.x.x ↓
@koishijs/plugin-console package to match the required version using npm install @koishijs/plugin-console@^5.29.4 or yarn add @koishijs/plugin-console@^5.29.4. error Cannot find module 'koishi-plugin-database-console' or its corresponding type declarations. ↓
npm install koishi-plugin-database-console or yarn add koishi-plugin-database-console. Verify the import statement is import { apply } from 'koishi-plugin-database-console'. error TypeError: ctx.console is undefined (or similar error when accessing console features) ↓
@koishijs/plugin-console to your Koishi configuration file (e.g., koishi.yml or koishi.config.ts) and ensure it loads before koishi-plugin-database-console if there's an explicit ordering. Example in koishi.config.ts: ctx.plugin(require('@koishijs/plugin-console')); Warnings
breaking Major version upgrades of the Koishi framework (e.g., Koishi v3 to v4) or its core console plugin (@koishijs/plugin-console) may introduce breaking changes requiring updates to this plugin. Always consult Koishi's official release notes. ↓
gotcha This plugin requires a correctly configured and running Koishi console (`@koishijs/plugin-console`) to function. Without the console, the database UI will not be accessible. ↓
gotcha Compatibility with the underlying database driver (e.g., `@minatojs/driver-sqlite`) and `minato` itself is crucial. Mismatched versions can lead to database connection errors or unexpected behavior. ↓
Install
npm install koishi-plugin-database-console yarn add koishi-plugin-database-console pnpm add koishi-plugin-database-console Imports
- apply wrong
import KoishiDatabaseConsole from 'koishi-plugin-database-console'correctimport { apply } from 'koishi-plugin-database-console' - Config
import { Config } from 'koishi-plugin-database-console' - koishiPluginDatabaseConsole wrong
const { apply } = require('koishi-plugin-database-console')correctconst koishiPluginDatabaseConsole = require('koishi-plugin-database-console')
Quickstart
import { Context, Schema } from 'koishi';
import { apply, Config } from 'koishi-plugin-database-console';
interface MyConfig extends Config {
// Add any specific configurations for koishi-plugin-database-console here
// For example, if it had a specific endpoint or permissions.
// This plugin usually doesn't require explicit configuration beyond enabling it.
}
export const name = 'my-koishi-app';
export function apply(ctx: Context, config: MyConfig) {
// Apply the database console plugin.
// It automatically registers itself with the Koishi console.
ctx.plugin(apply, config);
ctx.logger('app').info('Koishi Database Console plugin applied!');
// Example of using Koishi's database context (Minato)
// This part is for demonstrating Minato, not directly the plugin.
ctx.model.extend('user', {
exampleData: { type: 'string' }
});
ctx.on('ready', async () => {
const user = await ctx.model.User.create({ id: '123', exampleData: 'Hello Minato!' });
ctx.logger('app').info(`Created example user: ${user.id} with data: ${user.exampleData}`);
});
// Register a simple command to show the bot is active
ctx.command('db.test', 'Test database console functionality (indirectly)')
.action(async ({ session }) => {
const user = await session.user.get();
return `Your exampleData in database: ${user.exampleData || 'N/A'}. Check the Koishi console for database views.`;
});
}
export const Config: Schema<MyConfig> = Schema.object({});