It is not in any patch. It is RFC to decide if it is a good idea and
how it is supposed to work...

this could be a shorter syntax, because you do not construct the
attrs, you just mutate the record directly:

def txn(rec):
  if rec.name == 'bob':
    rec.count += 1
  elif rec.name == 'alice':
    rec.count -= 1

In general you should not mutate the args in a transaction, because
the transaction may be retried several times, but this txn is wrapped
inside a real transaction, so it gets fresh args each retry, so it is
okay to mutate them:

def real_txn(txn,record):
    rec = google_db.get_by_id(record.id)
    rec.id = rec.key().id()
    txn(rec)
    rec.put()
    return rec

return google_db.run_in_transaction(real_txn,record)

This can be made backwards compatible with SQL which just calls the
callable.

If this is acceptable, I will start implementing it.

Robin


On Feb 7, 9:11 am, mdipierro <[email protected]> wrote:
> I assume this is in your latest patch. I will try apply it during the
> week-end.
>
> On Feb 7, 8:39 am, Robin B <[email protected]> wrote:
>
> > update() and update_record() should accept callables:
>
> > def txn(record):
> >   attrs = {}
> >   if record.name == 'bob':
> >     attrs['count'] = record.count + 1
> >   elif record.name == 'alice':
> >     attrs['count'] = record.count - 1
> >   return attrs
>
> > #complex transactions
> > (db.posts.id>0).update(txn)
>
> > # simple transactions
> > (db.posts.id>0).update(count=lambda v: v+1)
>
> > The benefit of a complex transaction is that the developer can control
> > the order attributes are assigned and make complex decisions in side
> > the transaction.  Simple transactions can use the shorthand notation
> > and put the callable inline.
>
> > 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