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";constdb=newDB({type: "sqlite",events: ["connect","variableCreate","variableUpdate","variableDelete"]});constclient=newForgeClient({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.
newDB({type: "sqlite",folder: "database"// folder where the database file will be saved})Connects to a MongoDB database using a connection string.
newDB({type: "mongodb",url: "mongodb+srv://user:password@cluster.mongodb.net/dbname"})Connects using credentials or a connection URL.
newDB({type: "mysql",host: "localhost",port: 3306,username: "root",password: "password",database: "my_database"})Connects using credentials or a connection URL.
newDB({type: "postgres",host: "localhost",port: 5432,username: "postgres",password: "password",database: "my_database"})Uses better-sqlite3 as the SQLite backend.
newDB({type: "better-sqlite3",folder: "database"})This project is licensed under the GPL-3.0 License.