import { Connection , createConnection , getConnection } from "typeorm" ; import ORMConfig from "../ormconfig" ; export const DBConnect = async ( ) => { let connection ; try { connection = getConnection ( ) ; } catch ( e ) { } try { if ( connection ) { if ( ! connection . isConnected ) { await connection . connect ( ) ; } } else { await createConnection ( ORMConfig ) ; } console . log ( "🌴 Database connection was successful!" ) ; } catch ( e ) { console . error ( 'ERROR: Database connection failed!!' , e ) ; throw e ; } } ; export const TryDBConnect = async ( onError , next ? ) => { try { await DBConnect ( ) ; if ( next ) { next ( ) ; } } catch ( e ) { onError ( ) ; } } ;