Koishi Database Console

raw JSON →
0.2.3 verified Thu Apr 23 auth: no javascript

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.

error Error: Plugin 'koishi-plugin-database-console' requires @koishijs/plugin-console@^5.29.4, got 5.x.x
cause Peer dependency mismatch for `@koishijs/plugin-console`.
fix
Update your @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.
cause The package is not installed or the import path is incorrect.
fix
Ensure the package is installed: 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)
cause The `@koishijs/plugin-console` plugin is not properly loaded or initialized in your Koishi application.
fix
Add @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'));
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.
fix Refer to the Koishi official documentation and the plugin's GitHub repository for specific migration guides or updated versions. Ensure all peer dependencies match the required Koishi ecosystem versions.
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.
fix Ensure `@koishijs/plugin-console` is installed and enabled in your Koishi configuration. Access the Koishi console through your browser, usually at `http://localhost:8080` by default.
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.
fix Verify that your `minato` and database driver versions satisfy the peer dependency requirements of `koishi` and `koishi-plugin-database-console`. Update dependencies if necessary.
npm install koishi-plugin-database-console
yarn add koishi-plugin-database-console
pnpm add koishi-plugin-database-console

This quickstart demonstrates how to apply the koishi-plugin-database-console within a Koishi application and shows basic interaction with Koishi's Minato database layer. It assumes an existing Koishi project with a database configured.

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({});