@@ -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