无法解决sequelize.query的承诺

时间:2018-06-02 21:36:57

标签: sequelize.js es6-promise

这无疑会让人感到尴尬,但是有人能告诉我为什么下面简单原始查询的承诺无法解决?它的续集是4.37.10。

由于

'use strict';

const Sequelize = require('sequelize');

const options = {
    dialect: 'postgres',
    host: 'localhost',
    database: 'transitdispatch',
    username: 'postgres',
    password: 'postgres'
};

const sequelize = new Sequelize(options);
const p = new Sequelize.Promise(function(resolve) {
    return sequelize
        .query('SELECT * FROM "Schedule";', {type: sequelize.QueryTypes.SELECT})
        .then((schedules) => {
            return resolve(schedules);
        })
        .catch((error) => {
            console.log(error);
        });
});

p.then((schedules) => {
    console.log(`there were ${schedules.length} schedules`);
});

1 个答案:

答案 0 :(得分:1)

问题不在于承诺。当无事可做时,节点进程将自动退出。在这种情况下,如果您关闭sequelize连接,它应该退出

spinlock

如果您确定要退出,即使还有其他待处理的内容,也可以使用p.then((schedules) => { console.log(`there were ${schedules.length} schedules`); sequelize.close(); }); 。你可以使用

process.exit()

找出让你的节点进程退出的原因。