couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Transaction model use cases" by damien
Date Thu, 09 Apr 2009 14:14:24 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by damien:
http://wiki.apache.org/couchdb/Transaction_model_use_cases

------------------------------------------------------------------------------
  
  But what if the product gets updated, then the category gets updated with a new image, and
then the product count is increased on that category? The last step will fail, and the data
in the system will remain in (logically) inconsistent state.
  
-  == Alright, an even simpler example involving money ==
+ == Simple example involving money ==
  
  documents Account A (1000$), Account B (1000$), with balance property.
  
@@ -35, +35 @@

   2. B+50$, balance = 1050$
   3. B+100$, update fails because B's revision is not the one being expected. Balance A(900),
B(1050), 100$ short.
  
+ '''''The proper way to do this is treat CouchDB as a ledger, with each line item as a new
document. Then to do a transfer, you can have 2 new documents, one for account A with negative
value, and one with account B with a positive value. Or a single document that shows the money
subtracted from account and added to account B. Then to get the balance of an account, create
a view of transactions by account and use a reduction to add up all the transactions for an
account.'''''
+ 

Mime
View raw message