Skip to content

Repository files navigation

@nationdex/db

Database extension for ForgeScript apps and bots. It lets you store and manage persistent data (variables, leaderboards, cooldowns) across multiple database backends with TypeORM.

discordLicense


Contents


Installation

Install the package:

npm install github:nationdex/db

You 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-sqlite3

Quick Start

Import 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");

Database Types & Options

The DB constructor takes an options object. Here is how to configure each supported database:

SQLite (Default)

Stores data in a local file.

newDB({type: "sqlite",folder: "database"// folder where the database file will be saved})

MongoDB

Connects to a MongoDB database using a connection string.

newDB({type: "mongodb",url: "mongodb+srv://user:password@cluster.mongodb.net/dbname"})

MySQL

Connects using credentials or a connection URL.

newDB({type: "mysql",host: "localhost",port: 3306,username: "root",password: "password",database: "my_database"})

PostgreSQL

Connects using credentials or a connection URL.

newDB({type: "postgres",host: "localhost",port: 5432,username: "postgres",password: "password",database: "my_database"})

Better-SQLite3

Uses better-sqlite3 as the SQLite backend.

newDB({type: "better-sqlite3",folder: "database"})

License

This project is licensed under the GPL-3.0 License.

About

DataBase extension for Project Nationdex 2.0

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages