ChordDB is a lightweight, MongoDB-inspired database that uses Discord channels as storage, with end-to-end encryption and optional wrapper-based caching for performance.
It is designed primarily for bots, prototypes, and small-scale systems where simplicity and zero external infrastructure matter.
- π¦ Discord messages as database records (1 message = 1 document)
- π AES-GCM encryption using Node.js
crypto - π§ Mongo-like query & update operators (
$set,$inc,$unset,$push) - β‘ Cache-aware fetching (recommended with Discord API wrappers)
- π§© ESM-first with CJS support
- π§ͺ Works with plain JSON data
npm install chorddbimport { Chord } from "chorddb";const { Chord } = require("chorddb");import { Chord, getKey } from "chorddb";
const chord = new Chord({
token: "YOUR_BOT_TOKEN",
key: getKey("YOUR_ENCRYPTION_KEY_OR_PASSWORD"),
collections: [
{ name: "users", channelId: "1469947881367797825" },
{ name: "shop", channelId: "1469947881367797826" },
],
});Note
You can optionally provide a Discord API wrapper (discord.js, oceanic, bakit, etc.) to enable cache-based reads and reduce REST usage.
import { Chord } from "chorddb";
import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const chord = new Chord({
token: "YOUR_BOT_TOKEN",
key: getKey("YOUR_ENCRYPTION_KEY_OR_PASSWORD"),
collections: [...]
});
// Listen for gateway payloads to make sure the cache is up-to-date
client.on("raw", (payload) => chord.updateGatewayPayload(payload));
// Enable wrapper mode for caching
// You can either use await it or just let it run
await chord.useWrapper();
await client.login("YOUR_BOT_TOKEN");const users = chord.collect("users");
const guilds = chord.collect("guilds");await users.insertOne({
username: "someone",
coins: 100,
});
let moreUsers = await users.insertMany([
{ username: "someone else", coins: 200 },
{ username: "another user", coins: 300 },
]);await users.find({
username: "someone",
});
await users.findById("123"); // ID is the message IDor using a predicate:
const richUsers = await users.find((doc) => doc.coins > 500);await users.updateOne(
{ username: "someone" },
{
$inc: { coins: 50 },
$set: { premium: true },
},
);
await users.updateMany((doc) => doc["coins"] < 300, {
$dec: { coins: 20 },
});await users.deleteOne({ username: "someone else" });
await users.deleteMany((doc) => doc["coins"] < 150);const allUsers = await users.findAll();- Object matching
- Predicate functions
$set$inc$dec$unset$push
(Operator behavior is intentionally Mongo-like but simplified.)
- Cache is optional but strongly recommended
- Without a wrapper cache, ChordDB falls back to paginated REST fetching
- Fetching is lazy and incremental to avoid rate limits
- β Prototype bots
- β Startup MVPs
- β Small persistent data needs
β οΈ Not intended for high-write or large-scale production databases
- Image / binary uploads
- Indexing helpers
- Better schema validation
- Query optimization
Contributions are welcome! Please open an issue or pull request if you have any suggestions or find any bugs.
Thanks to everyone who helps make ChordDB better!
