Database extension for ForgeScript apps and bots. It lets you store and manage persistent data (variables, leaderboards, cooldowns) across multiple database backends with TypeORM.
Install the package:
npm install github:nationdex/dbYou also need the driver package for the database you plan to use:
# For SQLite (default)
npm install sqlite3
# For MongoDB
npm install mongodb
# For MySQL
npm install mysql2 # or mysql
# For PostgreSQL
npm install pg
# For Better-SQLite3
npm install better-sqlite3Import 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({
type: "sqlite",
events: ["connect", "variableCreate", "variableUpdate", "variableDelete"]
});
const client = new ForgeClient({
events: ["clientReady"]
extensions: [db]
});
client.login("YOUR_BOT_TOKEN");The DB constructor takes an options object. Here is how to configure each supported database:
Stores data in a local file.
new DB({
type: "sqlite",
folder: "database" // folder where the database file will be saved
})Connects to a MongoDB database using a connection string.
new DB({
type: "mongodb",
url: "mongodb+srv://user:password@cluster.mongodb.net/dbname"
})Connects using credentials or a connection URL.
new DB({
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "password",
database: "my_database"
})Connects using credentials or a connection URL.
new DB({
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "password",
database: "my_database"
})Uses better-sqlite3 as the SQLite backend.
new DB({
type: "better-sqlite3",
folder: "database"
})This project is licensed under the GPL-3.0 License.