Closed DarkPark closed 9 years ago
The example does not sync the model (which you have resolved by adding the empty table), nor does it populate the table with any data (which is the step you are missing).
I've extended the example to do both of those and tested with sqlite & sent a pull request. You can see the change here.
Switching the Person.find block with the following does both the sync and the create;
// add the table to the database
db.sync(function(err) {
if (err) throw err;
// add a row to the person table
Person.create({ id: 1, name: "John", surname: "Doe", age: 27 }, function(err) {
if (err) throw err;
// query the person table by surname
Person.find({ surname: "Doe" }, function (err, people) {
// SQL: "SELECT * FROM person WHERE surname = 'Doe'"
if (err) throw err;
console.log("People found: %d", people.length);
console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
people[0].age = 16;
people[0].save(function (err) {
// err.msg = "under-age";
});
});
});
});
@staff0rd thank you very much - this time it really works sad that official documentation provides misleading examples
The example from the index page with switching to sqlite in-memory database and error logging:
gives:
In case I use the existing db file with this connect line:
and add empty table
person
then it fails in a different way:Seems to me this example should define a table, it's structure and actually create it in the db file. Am I wrong and I have to manually create all the tables with all the fields?