Reputation: 73
I just learning node.js by book.
I follow to instructions in the book and got an error. I spended couple of hours to find a problem, but without success. Hope for your help and understanding.
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;
});};
Error occurs here:
exports.keylist = function(){
return exports.connectDB()
.then(SQNote => {
return SQNote.findAll({ attributes: [ 'notekey' ] })
.then(notes => {
return notes.map(note => notekey);
});
});};
Error: error in browser picture
SQNote.findAll is not a function
TypeError: SQNote.findAll is not a function at exports.connectDB.then.SQNote (/home/vegas/NodeJS_course/notes/models/notes-sequelize.js:119:23) at anonymous
Upvotes: 0
Views: 1024
Reputation: 73
After spend another few hours I found my mistake. Should be:
return SQNote.sync();
Instead:
return SQNote.sync;
Upvotes: 1