Koishi In-Memory Database
raw JSON →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.
Common errors
error Error: Cannot find module 'koishi-database-memory' ↓
error TypeError: MemoryDatabase is not a constructor ↓
app.plugin(MemoryDatabase, options) — do not instantiate directly. error Error: [cordis] Invalid plugin: Expected function or object but got... ↓
import { MemoryDatabase } from 'koishi-database-memory'. error TypeError: Cannot read properties of undefined (reading 'extend') ↓
app.plugin(MemoryDatabase) is called before any database operations. Warnings
breaking Upgrading from koishi-database-memory v1.0 to v1.2 requires renaming import from 'koishi-plugin-memory' to 'koishi-database-memory'. ↓
deprecated Direct use of `new MemoryDatabase()` is deprecated; use `app.plugin(MemoryDatabase, options)` instead. ↓
gotcha Data is not persisted; all data is lost when the process restarts. ↓
gotcha MemoryDatabase does not support complex queries like joins or aggregations; it implements only basic CRUD operations. ↓
Install
npm install koishi-database-memory yarn add koishi-database-memory pnpm add koishi-database-memory Imports
- MemoryDatabase wrong
const MemoryDatabase = require('koishi-database-memory')correctimport { MemoryDatabase } from 'koishi-database-memory' - default wrong
import { default as MemoryDatabase } from 'koishi-database-memory'correctimport MemoryDatabase from 'koishi-database-memory' - type MemoryDatabaseConfig wrong
import { MemoryDatabaseConfig } from 'koishi-database-memory'correctimport type { MemoryDatabaseConfig } from 'koishi-database-memory' - MemoryDatabase wrong
import MemoryDatabase from 'koishi-database-memory/dist/index.js'correctimport { MemoryDatabase } from 'koishi-database-memory'
Quickstart
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()