mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-13 23:58:16 +02:00
add prefix
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
require('dotenv').config();
|
||||
|
||||
module.exports = function initDB() {
|
||||
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Connected to the db.db database.');
|
||||
});
|
||||
|
||||
db.run(`PRAGMA foreign_keys = ON;`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Foreign key constraint enabled');
|
||||
});
|
||||
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS prefix(
|
||||
prefix TEXT NOT NULL DEFAULT '${process.env.DEFAULT_PREFIX}',
|
||||
serverID TEXT NOT NULL UNIQUE
|
||||
)`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Created prefix table');
|
||||
});
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS users(
|
||||
serverID TEXT NOT NULL,
|
||||
userID TEXT NOT NULL,
|
||||
coins INTEGER NOT NULL DEFAULT 0,
|
||||
bank INTEGER NOT NULL DEFAULT 0,
|
||||
xp INTEGER NOT NULL DEFAULT 0,
|
||||
levels INTEGER NOT NULL DEFAULT 0,
|
||||
messages INTEGER NOT NULL DEFAULT 0
|
||||
)`, (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Created users table');
|
||||
});
|
||||
|
||||
|
||||
db.close((err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
console.log('Close the database connection.');
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user