From d2194ebc349356f67ba3d49642c3463ebe4ac6de Mon Sep 17 00:00:00 2001 From: slawk0 Date: Thu, 29 Aug 2024 23:44:46 +0200 Subject: [PATCH] create table only if database connection was successful --- backend/db.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/db.js b/backend/db.js index fbc294c..a68fec2 100644 --- a/backend/db.js +++ b/backend/db.js @@ -11,9 +11,17 @@ const db = new Client({ // create connection to database db.connect() - .then(() => console.log('Successfully connected to database')) - .catch((err) => console.log('Error on connecting to database: ', err)); - + .then(() => { + console.log('Successfully connected to database'); + // if connection is succesful create tables + createTables() + .catch((err) => { + console.error('Error creating tables:', err); + }); + }) + .catch((err) => { + console.error('Error connecting to database: ', err); + }) async function createTables() { try { // Create accounts table