我只是通过书本学习 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/