Skip to content

Commit

Permalink
Updated connected db issue in db.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanC112 committed Jun 4, 2024
1 parent b5d6bce commit 98b39b5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions db.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import client from './db.config';
import client from './db.config';

const getDB = async () => {
console.log("Connecting to Database ...");

try {
await client.connect();
console.log("Database connected");
return client;
} catch (err: any) {
return client;
let isActive = false;
const getDB = async () => {
console.log("Connecting to Database ...");
if (isActive) {
console.log("Database already connected");
return client;
}
try {
await client.connect();
console.log("Database connected");
isActive = true;
return client;
} catch (err: any) {
return client;
}
}
}

export default getDB;

0 comments on commit 98b39b5

Please sign in to comment.