-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.js
25 lines (24 loc) · 920 Bytes
/
tables.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
const log = require('./logger');
const db = require('./db');
// create tables
db.getConnection()
.then(conn => {
conn.query(`CREATE TABLE IF NOT EXISTS main (
botID VARCHAr(20) NOT NULL,
ecoTotal INT NOT NULL DEFAULT 0,
guildRegistered INT NOT NULL DEFAULT 0
)`)
.then(() => {
// check if a row exists
conn.query(`SELECT * FROM main`)
.then(rows => {
if (rows.length === 0) {
conn.query(`INSERT INTO main (botID) VALUES ('${process.env.BOT_ID}')`)
.then(() => {
log.info(`Row created in main with botID ${process.env.BOT_ID}`)
})
}
})
log.info(`Table main created`)
})
})