feat: reuse databases's db object to clean repetitive code

This commit is contained in:
Ting-Jun Wang 2024-07-24 17:32:40 +08:00
parent cee419609f
commit 08f3b34b6b
Signed by: snsd0805
GPG Key ID: D175E969960C4B16
2 changed files with 4 additions and 24 deletions

View File

@ -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) {

View File

@ -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) {