-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
40 lines (40 loc) · 915 Bytes
/
model.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
const mysql = require("mysql");
const DB_CONFIG=require('./db_config')
class Model {
static conn = null;
static connect() {
this.conn = mysql.createConnection(DB_CONFIG)
}
static end() {
Model.conn.end();
}
static exeSql(sql) {
let promise = new Promise((resolve, reject) => {
this.connect();
this.conn.query(sql, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
Model.end();
});
});
return promise;
}
static exeSql2(sql,params=[]) {
let promise = new Promise((resolve, reject) => {
this.connect();
this.conn.query(sql, params,(err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
Model.end();
});
});
return promise;
}
}
module.exports = Model;