Its alive!

#batch insert
>>> db.posts.insert([dict(count=i+1) for i in range(3)])
[1, 2, 3]

#batch update (with optional transactions)
>>> def inc(r): r.count+=1
>>> def dec(r): r.count-=1
>>> db.posts.update(1,[2,3],dict(count=0),dict(count=lambda v: 
>>> v+2),dec,inc,count=lambda v: v-2)
3

#batch get
>>> db.posts.select(orderby=db.posts.id)
[{'count': 0L, 'id': 1}, {'count': 0L, 'id': 2}, {'count': 0L, 'id':
3}]

#batch delete
>>> db.posts.delete([3,2],1)
3

And its fully transactional when you pass callable args, all the
drivers will get it for free because it is not done at the driver
level.

Robin

On Feb 8, 3:46 pm, Robin B <robi...@gmail.com> wrote:
> I think in SQL you can use '|' to generate each in 1 query.
>
> Robin
>
> On Feb 8, 3:44 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > In principle I am for all of these but I am not sure they can be
> > implemented easily in SQL without loops. Can they?
>
> > On Feb 8, 3:39 pm, Robin B <robi...@gmail.com> wrote:
>
> > > We could add select and delete to tables and limitby could have a
> > > shortcut:
>
> > > instead of:
> > > (db.posts.id>0).select(orderby=~db.posts.created_at,limitby=(0,10))
>
> > > how about:
> > > db.posts.select(orderby=~db.posts.created_at, limitby=10)
>
> > > batch get:
> > > db.posts.select([3,5,9])
>
> > > and delete could also accept kwargs:
> > > db.posts.delete(orderby=db.posts.created_at,limitby=10)
>
> > > and batch delete:
> > > db.posts.delete([3,5,9])
>
> > > 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 web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to