-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
33 lines (29 loc) · 1.01 KB
/
db.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
var options = require(__dirname + '/options');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : options.storageConfig.host,
user : options.storageConfig.user,
password : options.storageConfig.password,
database : options.storageConfig.db,
port : options.storageConfig.port
});
exports.WriteToRoleQueue = function WriteToRoleQueue(user_id, adding, role) {
connection.query('INSERT INTO bot_queue (user_id, adding, role) VALUES (?, ?, ?)', [user_id, adding, role], function (error, results, fields) {
if (error) {
console.error('unable to queue ' + adding?'addition':'removal' + ' of role ' + role + ' within the database for user ' + user_id + '.')
throw error
}
})
}
exports.PullQueue = function PullQueue(callback) {
connection.query('SELECT * FROM bot_queue', function (error, results, fields) {
if (error)
{
throw error
}
callback(results, ClearQueue)
})
}
function ClearQueue() {
connection.query('TRUNCATE TABLE bot_queue')
}