mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 23:36:35 +02:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
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.');
|
|
});
|
|
}; |