node.js - Sequelize : findAll is not a function

标签 node.js sqlite sequelize.js

我只是通过书本学习 node.js。

我按照书中的说明进行操作,但出现错误。
我花了几个小时来找到问题,但没有成功。
希望得到您的帮助和理解。

exports.connectDB = function(){
var SQNote;
var sequlz;

if(SQNote) return SQNote.sync();

return new Promise((resolve, reject) => {
    fs.readFile(process.env.SEQUELIZE_CONNECT, 'utf-8', (err, data) => {
        if(err){
            reject(err);
        }
        else{
            resolve(data);
        }
    });
})
.then(yamltext => {
    return jsyaml.safeLoad(yamltext, 'utf-8');
})
.then(params => {
    sequlz = new Sequelize(params.dbname, 
        params.username, 
        params.password, 
        params.params);

    SQNote = sequlz.define('Note', {
                            notekey: {
                                    type: Sequelize.STRING,
                                    primaryKey: true,
                                    unique: true
                                },
                            title: Sequelize.STRING,
                            body: Sequelize.STRING
                        });
    return SQNote.sync;
});};

这里发生错误:
exports.keylist = function(){
return exports.connectDB()
.then(SQNote => {
    return SQNote.findAll({ attributes: [ 'notekey' ] })
    .then(notes => {
        return notes.map(note => notekey);
    });
});};

错误:
error in browser picture

SQNote.findAll 不是函数

类型错误:SQNote.findAll 不是函数
在exports.connectDB.then.SQNote (/home/vegas/NodeJS_course/notes/models/notes-sequelize.js:119:23)
在匿名

最佳答案

又花了几个小时后,我发现了我的错误。
应该:

return SQNote.sync();

反而:
return SQNote.sync;

关于node.js - Sequelize : findAll is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48239278/

相关文章:

node.js - npm 安装时间失败,找不到 make 错误

python - 将 Python AES 转换为 Node

node.js - 在 Ubuntu 14.04 1and1 虚拟服务器上安装 Node

java - 组合键上的 Sqlite 相对补集

postgresql - 记录来自 Sequelize 的 postgres 输出消息

node.js - 在 Sequelize NodeJS 中多次对同一字段连接表的条件?

node.js - 使用meteor将图像文件从google云存储桶下载到IOS localstorage

php - 拉维尔 5.1 : Enable SQLite foreign key constraints

c# - 如何以 c# windows 形式将 Excel 文件数据导入 SQLite 数据库?

mysql - Sequelize 中的 findAll() 找不到在事务中创建的行