-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathdatabase.js
More file actions
18 lines (15 loc) · 643 Bytes
/
database.js
File metadata and controls
18 lines (15 loc) · 643 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// This file is used to create a database instance for the bot to use.
const { QuickDB } = require("quick.db");
const path = require("path");
const fs = require("fs");
// Use DATABASE_PATH env var if set, otherwise default to ./json.sqlite
// This maintains backwards compatibility while adding flexibility for deployments (e.g. Coolify)
const dbPath = process.env.DATABASE_PATH || "./json.sqlite";
if (process.env.DATABASE_PATH) {
const dir = path.dirname(dbPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
const db = new QuickDB({ filePath: dbPath });
module.exports = db;