An advanced DataBase extension for ForgeScript.
- Installation
- How to use Events
- How to update
- Documentation
- Credits
Download these npm packages:
npm i @tryforge/forge.db sqlite3
Now, in your client initialization:
const { ForgeDB } = require("@tryforge/forge.db")
// I'll assume client, can be bot or anything else
const client = new ForgeClient({
...options // The options you currently have
extensions: [
new ForgeDB()
]
})
And voi-la, you bot now has been connected a local database.
Download these npm packages:
npm i @tryforge/forge.db mongodb
Now, in your client initialization:
const { ForgeDB } = require("@tryforge/forge.db")
// I'll assume client, can be bot or anything else
const client = new ForgeClient({
...options // The options you currently have
extensions: [
new ForgeDB({
type: "mongodb",
url: "Your_MongoURI_URL"
})
]
})
And voi-la, you bot now has been connected a mongo database.
If you want to install other dbs you need to follow these steps:
- Install forge.db package
npm i @tryforge/forge.db
- Install your db package
- For
better-sqlite3
npm i better-sqlite3
- For
mysql
npm i mysql # or npm i mysql2
- For
postgres
npm i postgres
- For
- Connect ForgeDB with ForgeScript
const { ForgeDB } = require("@tryforge/forge.db")
// I'll assume client, can be bot or anything else
const client = new ForgeClient({
...options // The options you currently have
extensions: [
new ForgeDB({
type: "mysql" | "postgres" | "better-sqlite3";
url?: string
host?: string
port?: number
username?: string
password?: string
database?: string //the path of your db
})
]
})
And voi-la, you bot now has been connected a database.
Once you configure your database you will head over to the main file of your bot and you will type this
const { ForgeDB } = require("@tryforge/forge.db")
const db = new ForgeDB({
...options? //The options you have for ForgeDB if you have any
events: [] //the events you want to use.
//Availalbe: `connect`, `variableCreate`, variableUpdate, `variableDelete`
})
const client = new ForgeClient({
...options // The options you currently have
extensions: [ db ]
})
db.commands.add({
type: "connect" | "variableCreate" | "variableUpdate" | "variableDelete"
code: `Your_Code_Goes_Here`
})
And voi-la, you learnt how to use database events!
Thanks for reading this guide and for using ForgeDB
This package was made by with love aggelos, a developer of ForgeScript. Use ForgeScript, it's better and easier.
Also huge thanks to aditya and aurea for their contributions <3