geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

some questions about update #255

Closed perltzhu closed 9 years ago

perltzhu commented 9 years ago

Foo.first(1, function (err, model) { // Check if there was an error with the DB if (err) throw new Error('Uh oh, something broke');

// If there was no error, but no model was found it must be missing if (!err && !model) throw new Error('Foo not found');

// Update the model's name property model.name = "New name!";

// Once we're done updating properties we can call save on the model. // Save will send the current model data to the DB you specified model.save(function (err, updatedModel) { if (err) throw new Error('Could not save the model'); console.log("The model was updated!"); }); });

After I use this model lib, I find that I can not avoid finding a row when I want to update a row. I think that the better way is to avoid the SELECT. Update a row , I usually use the raw SQL just like : Update table Set column=value WHERE ID = value.