Let's say I have a data mapper function开发者_如何学Go that aggregates multiple tables and generates an object instance from that data. The mapper has a typical save() method which delegates to update/insert.
When the mapper executes save - ideally it isolates object fields that have been modified, thus preventing the code from blanket bombing the database.
How would you go about this?
Store both the original and a working copy of the data in the object(s). If they differ, write them back.
While you could store just a hash of the original data, this gets messy if your underlying database is normalized and you allow changes to the primary key.
C.
精彩评论