@fedify/botkit-sqlite
v0.4.0
Published
SQLite-based repository for BotKit
Readme
@fedify/botkit-sqlite
This package is a SQLite-based repository implementation for BotKit.
It provides a production-ready data storage solution using the built-in
node:sqlite module, offering better performance and reliability compared to
in-memory storage while maintaining compatibility with both Deno and Node.js
environments.
Installation
deno add jsr:@fedify/botkit-sqlite
npm add @fedify/botkit-sqlite
pnpm add @fedify/botkit-sqlite
yarn add @fedify/botkit-sqliteUsage
The SqliteRepository can be used as a drop-in replacement for other repository
implementations in BotKit:
import { createBot } from "@fedify/botkit";
import { SqliteRepository } from "@fedify/botkit-sqlite";
const bot = createBot({
username: "mybot",
name: "My Bot",
repository: new SqliteRepository({
// Use a file-based database for persistence:
path: "./bot-data.db",
// Enable WAL mode for better performance (default: true):
wal: true,
}),
// ... other bot configuration
});Options
The SqliteRepository constructor accepts the following options:
path(optional): Path to the SQLite database file. Defaults to":memory:"for an in-memory database. Use a file path for persistent storage.wal(optional): Whether to enable write-ahead logging (WAL) mode for better performance. Defaults totrue. Note that WAL mode is automatically disabled for in-memory databases.
Examples
In-memory database (for testing/development)
const repository = new SqliteRepository(); // Uses :memory: by defaultFile-based database (for production)
const repository = new SqliteRepository({
path: "./data/botkit.db",
wal: true,
});Features
Cross-runtime: Works with both Deno and Node.js using the
node:sqlitemoduleHigh performance: Utilizes WAL mode and proper indexing for optimal performance
ACID compliance: Transactions ensure data integrity and consistency
Full
RepositoryAPI: Implements all BotKit repository methods including:- Key pair management for ActivityPub signing
- Message storage and retrieval with temporal filtering
- Follower and following relationship management
- Poll voting system
Resource management: Implements
Disposableinterface for proper cleanup
