How can I return a sequelize instance asynchronously?

后端 未结 1 1879
情书的邮戳
情书的邮戳 2021-01-23 03:48

I can\'t seem to properly pass the sequelize object from the service.js file to the index.js sequelize variable.

Does anything loo

相关标签:
1条回答
  • 2021-01-23 04:46

    await new Sequelize(...) in the code above expects that new Sequelize returns a promise, while this is not so. There is authenticate method that does that.

    It should be:

    exports.init = async () => {
        let sequelize = new Sequelize(...);
        await sequelize.authenticate();
        return sequelize;
    };
    

    Make sure promise rejections are always properly handled:

    (async () => {
        sequelize = await lambdaHelper.init();
        contractModel = require('./models/Contract')(sequelize, Sequelize);
    })().catch(console.error);
    
    0 讨论(0)
提交回复
热议问题