-
Notifications
You must be signed in to change notification settings - Fork 94
/
db.js
44 lines (39 loc) · 1.29 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
34
35
36
37
38
39
40
41
42
43
44
/*jslint node: true */
"use strict";
var conf = require('./conf.js');
if (conf.storage === 'mysql'){
var mysql = require('mysql');
var mysql_pool_constructor = require('./mysql_pool.js');
var pool = mysql.createPool({
//var pool = mysql.createConnection({
connectionLimit : conf.database.max_connections,
host : conf.database.host,
user : conf.database.user,
password : conf.database.password,
charset : 'UTF8MB4_UNICODE_520_CI', // https://github.com/mysqljs/mysql/blob/master/lib/protocol/constants/charsets.js
database : conf.database.name
});
module.exports = mysql_pool_constructor(pool);
}
else if (conf.storage === 'sqlite'){
var sqlitePool = require('./sqlite_pool.js');
module.exports = sqlitePool(conf.database.filename, conf.database.max_connections, conf.database.bReadOnly);
}
function executeInTransaction(doWork, onDone){
module.exports.takeConnectionFromPool(function(conn){
conn.query("BEGIN", function(){
doWork(conn, function(err){
conn.query(err ? "ROLLBACK" : "COMMIT", function(){
conn.release();
if (onDone)
onDone(err);
});
});
});
});
}
module.exports.executeInTransaction = executeInTransaction;
if (!conf.bLight) {
const initial_votes = require('./initial_votes.js');
initial_votes.initSystemVarVotes(module.exports);
}