-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBase.js
More file actions
37 lines (28 loc) · 841 Bytes
/
Copy pathDataBase.js
File metadata and controls
37 lines (28 loc) · 841 Bytes
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
var DataBase = exports;
var config = require('./config').mysql;
var mysql = require('mysql');
DataBase.msyql = null;
DataBase.init = function () {
if (DataBase.msyql == null) {
DataBase.msyql = mysql.createPool({
host: config.MYSQL_HOST,
port: config.MYSQL_PORT,
user: config.MYSQL_USER,
password: config.MYSQL_PSWD,
database: config.MYSQL_DB,
connectionLimit : 50,
});
}
};
DataBase.close = function (callback) {
callback = callback || _nop;
if (DataBase.msyql != null) {
DataBase.msyql.end(function (err) {
DataBase.msyql = null;
console.log('mysql 退出成功');
callback(err);
});
}
};
function _nop(/* ... */) {
}