-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
44 lines (36 loc) · 879 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
42
43
44
const SQL_info = require('./KEY/SQL_info.json')
const mysql = require('mysql');
var connection;
const conn = {
host: SQL_info.host,
port: SQL_info.port,
user: SQL_info.user,
password: SQL_info.password,
database: SQL_info.database,
multipleStatemens: true
};
function connect(){
conn.typeCast = function (field, next) {
if (field.type === 'JSON') {
return JSON.parse(field.string())
}
return next()
};
connection = mysql.createConnection(conn); // DB Connect
connection.connect(function(err){
if(err){
console.error(err);
console.error("MySQL connection err");
return ;
}
console.log("MySQL connected");
});
return connection;
}
function return_connection(){
return connection;
}
module.exports = {
connect,
return_connection
}