-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
42 lines (37 loc) · 876 Bytes
/
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
var mysql = require('mysql');
var pool = mysql.createPool({
host:'127.0.0.1',
user:'ivan',
password:'mercdev',
database:'exapp'
});
module.exports.get = function(q, cb){
pool.getConnection(function(err, connection){
if(err) {throw err; return;}
connection.query(q, function(err, data){
if(err) {throw err; return;}
connection.release();
cb(data);
});
});
}
module.exports.set = function(q, data, cb){
pool.getConnection(function(err, connection){
if(err) {throw err; return;}
connection.query(q, data, function(err, info){
if(err) {throw err; return;}
connection.release();
cb();
});
});
}
module.exports.del = function(q, cb){
pool.getConnection(function(err, connection){
if(err) {throw err; return;}
connection.query(q, function(err, results){
if(err) {throw err; return;}
connection.release();
cb();
});
});
}