Skip to content

Commit e7cd88d

Browse files
committed
updated readme example to also sync/create
1 parent 1af9b1f commit e7cd88d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Readme.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,28 @@ orm.connect("mysql://username:password@host/database", function (err, db) {
6969
}
7070
});
7171

72-
Person.find({ surname: "Doe" }, function (err, people) {
73-
// SQL: "SELECT * FROM person WHERE surname = 'Doe'"
74-
75-
console.log("People found: %d", people.length);
76-
console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
77-
78-
people[0].age = 16;
79-
people[0].save(function (err) {
80-
// err.msg = "under-age";
72+
// add the table to the database
73+
db.sync(function(err) {
74+
if (err) throw err;
75+
76+
// add a row to the person table
77+
Person.create({ id: 1, name: "John", surname: "Doe", age: 27 }, function(err) {
78+
if (err) throw err;
79+
80+
// query the person table by surname
81+
Person.find({ surname: "Doe" }, function (err, people) {
82+
// SQL: "SELECT * FROM person WHERE surname = 'Doe'"
83+
if (err) throw err;
84+
85+
console.log("People found: %d", people.length);
86+
console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
87+
88+
people[0].age = 16;
89+
people[0].save(function (err) {
90+
// err.msg = "under-age";
91+
});
92+
});
93+
8194
});
8295
});
8396
});

0 commit comments

Comments
 (0)