Skip to content
 
 

Latest commit

 

History

267 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

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.

discord License


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

const db = new DB({
    type: "sqlite",
    events: ["connect", "variableCreate", "variableUpdate", "variableDelete"]
});

const client = new ForgeClient({
    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.

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

MongoDB

Connects to a MongoDB database using a connection string.

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

MySQL

Connects using credentials or a connection URL.

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

PostgreSQL

Connects using credentials or a connection URL.

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

Better-SQLite3

Uses better-sqlite3 as the SQLite backend.

new DB({
    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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages