create table only if database connection was successful

This commit is contained in:
slawk0
2024-08-29 23:44:46 +02:00
parent 1921b4f5a5
commit d2194ebc34

View File

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