Koishi In-Memory Database

raw JSON →
1.2.0 verified Fri May 01 auth: no javascript

koishi-database-memory is an in-memory database implementation for the Koishi chatbot framework (v4.x). Version 1.2.0 provides a lightweight, zero-configuration database backend that stores all data in memory, suitable for development, testing, or small-scale deployments where persistence is not required. It ships with TypeScript types and requires koishi-core ^1.12.0 as a peer dependency. Unlike SQL-based databases (e.g., koishi-database-sqlite or koishi-database-mysql), it offers the fastest read/write speeds but no data persistence across restarts. The package is maintained as part of the Koishi monorepo and follows its release cadence. It is intended for use cases where temporary storage suffices, and can be easily swapped with a persistent database later.

error Error: Cannot find module 'koishi-database-memory'
cause Package not installed or misconfigured in dependencies.
fix
Run 'npm install koishi-database-memory' and ensure it is listed in package.json dependencies.
error TypeError: MemoryDatabase is not a constructor
cause Using `new MemoryDatabase()` instead of `app.plugin(MemoryDatabase)`.
fix
Use app.plugin(MemoryDatabase, options) — do not instantiate directly.
error Error: [cordis] Invalid plugin: Expected function or object but got...
cause MemoryDatabase imported incorrectly (e.g., wrong default import in CommonJS).
fix
Use ESM import syntax: import { MemoryDatabase } from 'koishi-database-memory'.
error TypeError: Cannot read properties of undefined (reading 'extend')
cause MemoryDatabase plugin not installed before calling model methods.
fix
Ensure app.plugin(MemoryDatabase) is called before any database operations.
breaking Upgrading from koishi-database-memory v1.0 to v1.2 requires renaming import from 'koishi-plugin-memory' to 'koishi-database-memory'.
fix Replace import { MemoryDatabase } from 'koishi-plugin-memory' with import { MemoryDatabase } from 'koishi-database-memory'.
deprecated Direct use of `new MemoryDatabase()` is deprecated; use `app.plugin(MemoryDatabase, options)` instead.
fix Use the plugin system: app.plugin(MemoryDatabase, {})
gotcha Data is not persisted; all data is lost when the process restarts.
fix Use a persistent database like SQLite or MySQL for production. MemoryDatabase is intended for development/testing.
gotcha MemoryDatabase does not support complex queries like joins or aggregations; it implements only basic CRUD operations.
fix Refer to Koishi database API limitations; use SQL databases for advanced queries.
npm install koishi-database-memory
yarn add koishi-database-memory
pnpm add koishi-database-memory

Shows how to install and use the MemoryDatabase plugin in a Koishi app, including extending a model and creating a record.

import { Context } from 'koishi-core'
import { MemoryDatabase } from 'koishi-database-memory'

const app = new Context()
app.plugin(MemoryDatabase, {})

// Now you can use database operations
app.model.extend('user', {})
app.model.create('user', { name: 'Alice' }).then(user => {
  console.log(user)
})

app.start()