Koishi DataView Plugin
koishi-plugin-dataview is a plugin for the Koishi chatbot framework, providing a web-based console interface to view and interact with various database tables directly within the Koishi Console. It leverages Koishi's existing database connectivity to present data in a structured, browsable format, enhancing debugging and administrative capabilities. The current stable version is 2.7.8. Koishi plugins generally follow the release cadence of the Koishi core framework, with frequent updates to ensure compatibility and introduce new features. Its key differentiator is its seamless integration into the Koishi Console, offering a unified management experience for bot operations and underlying data, which is crucial for complex bot applications needing direct data inspection without external tools, simplifying bot administration and data inspection.
Common errors
-
Error: Cannot find module '@koishijs/plugin-console'
cause The peer dependency `@koishijs/plugin-console` is not installed.fixRun `npm install @koishijs/plugin-console` or `yarn add @koishijs/plugin-console`. -
Error: Plugin koishi-plugin-dataview requires version X of koishi, but you have version Y.
cause Koishi core version mismatch with the plugin's peer dependency requirements.fixUpgrade or downgrade your `koishi` package to a compatible version as specified in `koishi-plugin-dataview`'s `package.json` peer dependencies, or update the plugin. -
TypeError: Cannot read properties of undefined (reading 'registerTab')
cause This error typically indicates that the Koishi Console plugin (`@koishijs/plugin-console`) was not loaded or initialized before `koishi-plugin-dataview`.fixEnsure `app.plugin(Console)` is called before `app.plugin(DataViewPlugin)` in your application entry file.
Warnings
- breaking Major version updates of Koishi or its console plugin often require corresponding updates to koishi-plugin-dataview due to API changes. Always check the changelog when upgrading Koishi core.
- gotcha The DataView plugin requires `@koishijs/plugin-console` to be installed and loaded in your Koishi application. Without the console, the DataView interface will not be accessible.
- gotcha DataView only displays data from the database configured for Koishi itself. If Koishi is not connected to a database, or is using an ephemeral in-memory database, DataView will show limited or temporary data.
Install
-
npm install koishi-plugin-dataview -
yarn add koishi-plugin-dataview -
pnpm add koishi-plugin-dataview
Imports
- DataViewPlugin
const DataViewPlugin = require('koishi-plugin-dataview')import DataViewPlugin from 'koishi-plugin-dataview'
- DataViewPluginConfig
import type { Config as DataViewPluginConfig } from 'koishi-plugin-dataview' - KoishiContextUse
new DataViewPlugin(ctx, options)
ctx.plugin(DataViewPlugin, options)
Quickstart
import { App, Schema } from 'koishi';
import { Console } from '@koishijs/plugin-console';
import DataViewPlugin from 'koishi-plugin-dataview';
const config = {
port: 8080,
host: 'localhost',
logLevel: 'info',
database: {
// Use 'memory' for a quick demo. For production, configure a real database
// like 'mysql', 'sqlite', or 'mongo' to see persistent data.
protocol: 'memory'
}
};
const app = new App(config);
// Koishi Console plugin is a peer dependency and must be loaded.
app.plugin(Console);
// Load the DataView plugin without specific options for default behavior.
app.plugin(DataViewPlugin, {
// Optional: configure specific tables to display or other plugin settings.
// Example: maxRows: 100, // Limit number of rows per table displayed
});
app.start().then(() => {
console.log('Koishi application started successfully.');
console.log('Access the Koishi Console at http://localhost:8080/console');
console.log('DataView will be available under the "Data" tab in the console.');
}).catch(err => {
console.error('Failed to start Koishi application:', err);
});