简体   繁体   中英

can i access sequelize from outside the database provider writing raw query in nestjs using sequelize

 export const databaseProviders = [ { provide: 'Sequelize', useFactory: async () => { const sequelize = new Sequelize({ dialect: 'postgres', host: process.env.PG_HOST, port: Number(process.env.PG_PORT), database: process.env.PG_DATABASE, username: process.env.PG_USERNAME, password: process.env.PG_PASSWORD, }); sequelize.addModels([OrderModule]); await sequelize.sync(); return sequelize; }, }, ];

Can I access the sequelize outside the file, so that i can use raw queries? Is there decorator or something which i can use to access the sequelize to write the raw queries.

Issue resolved. We can use the @Inject to access the sequelize from the provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM