Registry / database / koishi-plugin-database-txtdb

koishi-plugin-database-txtdb

JSON →
library1.2.0jsnpmunverified

A Koishi plugin that provides a simple, file-based database service using plain text files. Data is stored line-by-line as JSON strings, making it highly readable and easy to debug. It is designed for small-scale or prototype bots that do not require a full database engine. Current stable version: 1.2.0. Released as needed. Key differentiators: no dependencies beyond Koishi, zero parsing overhead, file-lock based concurrency safety.

npm install koishi-plugin-database-txtdb
INSTALL
IMPORT
SIG · KOISHI-PLUGIN-DATA
K
koishi-plugin-database-txtdb
databasejavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import TxtDb from 'koishi-plugin-database-txtdb'
const TxtDb = require('koishi-plugin-database-txtdb')
ESM-only package; default export is the plugin class.
Plugin
import type { Plugin } from 'koishi' import TxtDb from 'koishi-plugin-database-txtdb'
import { TxtDb } from 'koishi-plugin-database-txtdb'
Named export 'TxtDb' does not exist; use default import.
install
ctx.plugin(TxtDb, { path: './data' })
ctx.use(TxtDb)
TxtDb is a Koishi service plugin; use ctx.plugin() to install with options.

Install and use TxtDB plugin. Shows import, plugin registration, table creation, insertion, and query using Koishi database API.

// Install: npm install koishi-plugin-database-txtdb // In your Koishi config: import { Context } from 'koishi' import TxtDb from 'koishi-plugin-database-txtdb' export function apply(ctx: Context) { // Install the TXT DB service ctx.plugin(TxtDb, { path: 'data/database/txtdb' // default path }) // Now you can use ctx.database ctx.on('ready', async () => { // Create a table await ctx.database.create('users') // Insert a record const id = await ctx.database.set('users', 1, { name: 'Alice', score: 100 }) console.log('Inserted id:', id) // Query const user = await ctx.database.get('users', 1) console.log('User:', user) }) }
Debug
Known issues
gotchaData is not persistent across restarts if path points to a tmpfs or in-memory filesystem? Actually it persists, but ensure the path directory exists and is writable.
fix
Set path to a persistent location, e.g., './data/txtdb' inside your project directory.
affects: >=1.0.0
gotchaTable IDs are numeric and auto-incremented. If you insert a record with a specific ID, it may conflict with auto-generated IDs.
fix
Do not manually set ID field; let the database assign it.
affects: >=1.0.0
gotchaFile size may grow unbounded; no built-in compaction or cleanup. Old records are not automatically removed.
fix
Implement periodic cleanup or delete records using ctx.database.remove()
affects: >=1.0.0
deprecatedTXT DB does not support complex queries (e.g., where, sort, limit). Koishi's database API may assume these capabilities; unsupported methods will throw or behave unexpectedly.
fix
Use a full-featured database such as koishi-plugin-database-sqlite or koishi-plugin-database-mysql for production bots.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: TxtDb is not a constructor
Using default import incorrectly (named import instead of default) because package is ESM-only.
fix
Use import TxtDb from 'koishi-plugin-database-txtdb' (no curly braces)
Error: Cannot find module 'koishi-plugin-database-txtdb'
Package not installed or incorrect import path.
fix
Run 'npm install koishi-plugin-database-txtdb' and ensure import matches package name exactly.
error: Failed to create table: EACCES: permission denied
Node process does not have write permission to the configured path.
fix
Set path to a directory the process can write to, or run with appropriate permissions.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
koishirequiredCore peer dependency; plugin requires Koishi runtime v4.17.1+
Agent activity
7 hits · last 30 days
node
6
Resources
koishi-plugin-database-txtdb — npm install koishi-plugin-database-txtdb · libregistry