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
|
// require module
|
||||||
const jwt = require('jsonwebtoken');
|
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
|
// global variable
|
||||||
const jwt_key = "goodjwtkey";
|
const jwt_key = "goodjwtkey";
|
||||||
|
|
||||||
@ -112,7 +101,8 @@ module.exports = {
|
|||||||
// return connection of db
|
// return connection of db
|
||||||
getDBConnection : async function() {
|
getDBConnection : async function() {
|
||||||
try {
|
try {
|
||||||
const conn = await pool.getConnection();
|
const db_manager = require('../db');
|
||||||
|
const conn = await db_manager.getDBConnection();
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
|||||||
@ -1,16 +1,5 @@
|
|||||||
// require module
|
// require module
|
||||||
const jwt = require('jsonwebtoken');
|
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
|
// global variable
|
||||||
const jwt_key = "goodjwtkey";
|
const jwt_key = "goodjwtkey";
|
||||||
|
|
||||||
@ -112,7 +101,8 @@ module.exports = {
|
|||||||
// return connection of db
|
// return connection of db
|
||||||
getDBConnection : async function() {
|
getDBConnection : async function() {
|
||||||
try {
|
try {
|
||||||
const conn = await pool.getConnection();
|
const db_manager = require('../db');
|
||||||
|
const conn = await db_manager.getDBConnection();
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user