Bun database extension for Project Nationdex 2026. It stores persistent data (variables, leaderboards, cooldowns, and suggestions) in an embedded PGlite instance — full Postgres compiled to WASM, running in-process. No database server, no native driver package, no extra install step.
bun add github:nationdex/db#mainUse Bun 1.4.3 or newer with the ForgeScript version supplied by Project Nationdex 2026.
Import DB from @nationdex/db and add it to your ForgeClient extensions:
import { ForgeClient } from "@tryforge/forgescript";
import { DB } from "@nationdex/db";
const db = new DB({
folder: "database", // where PGlite persists its data
events: ["connect", "variableCreate", "variableUpdate", "variableDelete"]
});
const client = new ForgeClient({
events: ["clientReady"],
extensions: [db]
});
client.login("YOUR_BOT_TOKEN");new DB({
folder?: string // directory PGlite persists to (default: "database")
memory?: boolean // run fully in-memory, no persistence (useful for tests)
events?: Array<"connect" | "variableCreate" | "variableUpdate" | "variableDelete">
})There is no type option anymore — PGlite is the only backend.
PGlite persists to disk, so an ungraceful exit can lose whatever hasn't been flushed yet. If your process handles its own shutdown (SIGINT/SIGTERM, a PM2/systemd stop, etc.), call DataBase.close() from it before exiting:
process.on("SIGINT", async () => {
await client.db.close();
process.exit(0);
});This isn't wired up automatically — installing process-wide signal handlers is the host application's call, not something this extension should do on your behalf.
DataBase (src/util/database.ts) wraps a single PGlite instance and stores variables, cooldowns, suggestions, and votes. All ~70 ForgeScript functions in src/functions/ go through this one static facade, so nothing outside database.ts needs to know that Postgres — not a remote server, a WASM build running inside your own process — is what's underneath.
This project is licensed under the GPL-3.0 License.
Run bun run metadata after changing ForgeScript functions or events. The generator reads the current extension definitions and writes the JSON served from this repository.
- In TryForge ForgeVSC, add
github:nationdex/db#maintoforgevsc.workspace.additionalPackages. - In EdexLabs ForgeVSC, add
github:nationdex/db#maintoextensionsinforgeconfig.json.
Use $getGlobalVar[config;;prefix] for a nested configuration value and $getSuggestionStats[userId] for a submitter's open count and latest submission timestamp. The timestamp is in milliseconds and is null if the submitter has no suggestions.