-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
41 lines (36 loc) · 1.05 KB
/
database.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
const mysql = require('mysql');
class DBOperation
{
constructor() {
this.response = "something went wrong";
this.connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "webkul"
});
}
async dbOperation(queryObject) {
var self = this;
await this.performDbAction(queryObject.action).then(() => {
this.response = "success"
}).catch((err) => {
this.response = err;
})
}
performDbAction(action) {
var self = this;
return new Promise((res, rej) => {
var self2 = self;
self.connection.connect((err) => {
if(err) rej();
let sqlCommand = action + " database node_test";
let msg = "Database " + action + "ed!";
self2.connection.query(sqlCommand, (err, result) => {
if (err) rej(err);
res();
});
})
});
}
}
module.exports = DBOperation;