> row.update_record(count=db.table.count+1)

Nice, thats great syntax for incrementing counters, but you would need
a lambda to do anything more complicated than arithmetic in a
transaction.

What about a more complex transaction like read a value and set it
based on rules (for creating a lock)?  That could only be accomplished
with a lambda...right?

Robin



On Jan 9, 5:51 pm, mdipierro <[email protected]> wrote:
> I think we have something like this without introducing a special
> syntax for GAE based on lambda. In fact on non-gae you can now do
>
> row.update_record(count=db.table.count+1)
>
> The same could work on GAE with your code below.
>
> massimo
>
> On Jan 9, 1:11 pm, Robin B <[email protected]> wrote:
>
> > 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
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to