import { Sequelize } from 'sequelize-typescript' ; import { SequelizeModuleConfiguration } from './sequelize.interfaces' ; export function createSequelizeProviders ( { config , models } ) { const sequelizeProvider = { provide : Sequelize , useFactory : async ( ) => { const sequelize = new Sequelize ( config ) ; sequelize . addModels ( models ) ; return sequelize ; } } ; const modelsProvider = ( models || [ ] ) . map ( model => { return { provide : model , useFactory : ( sequelize ) => sequelize . models [ model . name ] , inject : [ Sequelize ] } ; } ) ; return [ sequelizeProvider , ... modelsProvider ] ; }