-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool.js
41 lines (37 loc) · 1022 Bytes
/
pool.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
var mysql = require('db-mysql');
var generic_pool = require('generic-pool');
var pool = generic_pool.Pool({
name : 'mysql',
create : function(callback) {
new mysql.Database({
hostname: 'localhost',
user: 'root',
password: '17061985',
database: 'ninja',
charset : 'utf8'
}).connect(function(err, server) {
callback(err, this);
});
},
destroy : function(client) { client.disconnect(); },
max : 10,
idleTimeoutMillis : 30000,
});
function getSql() {
return new mysql.Database({
hostname: 'localhost',
user: 'root',
password: '17061985',
database: 'ninja',
charset: 'utf8'
}).on('error', function(error) {
console.log('ERROR: ' + error);
}).on('ready', function(server) {
console.log('Connected to ' + server.hostname + ' (' + server.version + ')');
});
}
function getPool() {
return pool;
}
exports.getSql = getSql;
exports.getPool = getPool;