To perform certain actions on GAE you need transactions, eg.
atomically increment a counter.
This is what it would look like:
row.update_record(count=lambda r: r.count+1)
The GAE driver would check attributes for lambdas and invoke a
transaction when a lambda is present, the other SQL drivers could be
modified to be tolerant of lambdas and pass the current row into the
lambda and will get the correct outcome.
The transaction would work something like this in gql.py:
from google.appengine.ext import db as google_db
def update_record_txn(attrs,table_obj):
record = table_obj.get_by_id(
attrs.id)
for k,v in attrs:
if isinstance(v,lambda x: x):
v = v(record)
setattr(record,k,v)
record.put()
return record
try:
return google_db.run_in_transaction(update_record_txn,
row,table_obj)
except:
pass
# could handle TransactionFailedError() caused by contention
This would be backwards compatible.
Thoughts?
Robin