目录
当前位置: 首页 > 文档资料 > ORM2 中文文档 >

7. 创建和更新记录

优质
小牛编辑
137浏览
2023-12-01

创建

  1. var newRecord = {};
  2. newRecord.id = 1;
  3. newRecord.name = "John"
  4. Person.create(newRecord, function(err, results) {
  5. ...
  6. });

保存

  1. Person.find({ surname: "Doe" }, function (err, people) {
  2. // SQL: "SELECT * FROM person WHERE surname = 'Doe'"
  3. console.log("People found: %d", people.length);
  4. console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
  5. people[0].age = 16;
  6. people[0].save(function (err) {
  7. // err.msg = "under-age";
  8. });
  9. });