import { MicroframeworkLoader , MicroframeworkSettings } from 'microframework-w3tec' ; import { createConnection , getConnectionOptions } from 'typeorm' ; import { env } from '../env' ; export const typeormLoader = async ( settings ) => { const loadedConnectionOptions = await getConnectionOptions ( ) ; const connectionOptions = Object . assign ( loadedConnectionOptions , { type : env . db . type as any , host : env . db . host , port : env . db . port , username : env . db . username , password : env . db . password , database : env . db . database , synchronize : env . db . synchronize , logging : true , logger : 'advanced-console' , entities : env . app . dirs . entities , migrations : env . app . dirs . migrations , } ) ; const connection = await createConnection ( connectionOptions ) ; await connection . runMigrations ( ) ; if ( settings ) { settings . setData ( 'connection' , connection ) ; settings . onShutdown ( ( ) => connection . close ( ) ) ; } } ;