[web2py] Helper functions to get one from database

2010-03-16 Thread Michael Toomim
Hi guys, I've found the following functions to be commonly useful in practice. Has anyone else written anything similar? Is there a better idiom here, or better names or interfaces for these? def get_one(query): result = db(query).select() assert len(result) = 1, GAH get_one called when

Re: [web2py] Helper functions to get one from database

2010-03-16 Thread Thadeus Burgess
single_record = db(query).select().first() if not single_record: print no record else: print record!, single_record You can also do db(query).count() db(query).select().last() -Thadeus On Tue, Mar 16, 2010 at 3:45 PM, Michael Toomim too...@gmail.com wrote: Hi guys, I've found the