Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mysql = require('mysql');
- class MysqlPool {
- credentials = {};
- pool;
- constructor(host, user, password, database) {
- this.credentials.host = host;
- this.credentials.user = user;
- this.credentials.password = password;
- this.credentials.database = database;
- this.pool = mysql.createPool(this.credentials);
- }
- async query(query, placeholders) {
- return new Promise((resolve, reject) => {
- this.pool.getConnection(function(err, connection) {
- connection.query(query, placeholders, function (error, result, fields) {
- connection.release();
- if (error) {
- return reject(error);
- }
- resolve(result);
- });
- });
- });
- }
- }
- module.exports = MysqlPool;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement