-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.js
54 lines (48 loc) · 1.11 KB
/
connection.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
45
46
47
48
49
50
51
52
53
54
var mysql = require("mysql");
var pool = mysql.createPool(
{
connectionLimit: 100,
host: '127.0.0.1',
user: 'root',
password: '1234',
database: 'helloworld',
multipleStatements: true,
debug: false
}
);
getConnection = function (callback) {
pool.getConnection(function (err, conn) {
if (err) {
return callback(err);
}
callback(err, conn);
});
};
function connectMysql() {
var self = this;
var conn = '';
var pool = mysql.createPool({
connectionLimit: 100,
host: '127.0.0.1',
user: 'root',
password: '1234',
database: 'helloworld',
debug: false
});
pool.getConnection(function (err, connection) {
if (err) {
self.stop(err);
} else {
conn = connection;
}
});
return conn;
}
stop = function (err) {
console.log("ISSUE WITH MYSQL \n" + err);
process.exit(1);
}
module.exports = {
connectMysql: connectMysql,
getConnection: getConnection
}