-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.js
45 lines (42 loc) · 1.06 KB
/
sql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const sql = require('sqlite3');
const db = new sql.Database('bot.sqlite');
console.log('Initialized database connection.');
const tables = {
blacklist: [
'id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
'snowflake TEXT NOT NULL',
'guild TEXT NOT NULL',
],
warnings: [
'id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
'snowflake TEXT NOT NULL',
'reason TEXT NOT NULL',
'warner TEXT NOT NULL',
'guild TEXT NOT NULL',
'time INTEGER NOT NULL',
],
bans: [
'id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
'snowflake TEXT NOT NULL',
'guild TEXT NOT NULL',
'unbannedAt INTEGER NOT NULL',
],
mutes: [
'id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
'snowflake TEXT NOT NULL',
'guild TEXT NOT NULL',
'unmutedAt INTEGER NOT NULL',
],
config: [
'id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
'option TEXT NOT NULL',
'value TEXT NOT NULL',
'guild TEXT NOT NULL',
],
};
for(const table in tables) {
db.run(`CREATE TABLE ${table} (${tables[table].join(', ')})`, () => {
console.log(`Initialized table "${table}".`);
});
}
module.exports = db;