25 lines
608 B
JavaScript
25 lines
608 B
JavaScript
const mysql = require('mysql2/promise');
|
|
const config = require('./config.js');
|
|
|
|
module.exports = {
|
|
init() {
|
|
if (!this.pool) {
|
|
this.pool = mysql.createPool(config.mysql);
|
|
this.pool.on('connection', connection => {
|
|
connection.config.namedPlaceholders = true;
|
|
});
|
|
}
|
|
},
|
|
find(query, params) {
|
|
return this.pool.query(query, params).then(([rows]) => {
|
|
return rows;
|
|
});
|
|
},
|
|
findOne(query, params) {
|
|
return this.find(query, params).then(([rows]) => rows);
|
|
},
|
|
findFromDef() {
|
|
|
|
}
|
|
};
|