orm2 中文文档 7. 创建和更新记录

译者:飞龙

来源:Creating and Updating Items

创建

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

保存

Person.find({ surname: "Doe" }, function (err, people) {
    // SQL: "SELECT * FROM person WHERE surname = 'Doe'"

    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";
    });
});
    原文作者:飞龙
    原文地址: https://segmentfault.com/a/1190000004281613
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞