feat: reuse databases's db object to clean repetitive code
This commit is contained in:
parent
cee419609f
commit
08f3b34b6b
@ -1,16 +1,5 @@
|
||||
// require module
|
||||
const jwt = require('jsonwebtoken');
|
||||
const db = require("mariadb");
|
||||
|
||||
// create pool
|
||||
const pool = db.createPool({
|
||||
connectionLimit : 50,
|
||||
host : 'localhost',
|
||||
user : 'user',
|
||||
password : '',
|
||||
database : 'scholarship'
|
||||
});
|
||||
|
||||
// global variable
|
||||
const jwt_key = "goodjwtkey";
|
||||
|
||||
@ -112,7 +101,8 @@ module.exports = {
|
||||
// return connection of db
|
||||
getDBConnection : async function() {
|
||||
try {
|
||||
const conn = await pool.getConnection();
|
||||
const db_manager = require('../db');
|
||||
const conn = await db_manager.getDBConnection();
|
||||
return conn;
|
||||
}
|
||||
catch(e) {
|
||||
|
||||
@ -1,16 +1,5 @@
|
||||
// require module
|
||||
const jwt = require('jsonwebtoken');
|
||||
const db = require("mariadb");
|
||||
|
||||
// create pool
|
||||
const pool = db.createPool({
|
||||
connectionLimit : 50,
|
||||
host : 'localhost',
|
||||
user : 'user',
|
||||
password : '',
|
||||
database : 'scholarship'
|
||||
});
|
||||
|
||||
// global variable
|
||||
const jwt_key = "goodjwtkey";
|
||||
|
||||
@ -112,7 +101,8 @@ module.exports = {
|
||||
// return connection of db
|
||||
getDBConnection : async function() {
|
||||
try {
|
||||
const conn = await pool.getConnection();
|
||||
const db_manager = require('../db');
|
||||
const conn = await db_manager.getDBConnection();
|
||||
return conn;
|
||||
}
|
||||
catch(e) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user