You can even do this:
p = db.select(person).list()
I find it more convenient than wrapping it in list(...).
Anand
By the way, what is the background of this feature?
I do not understand what are the advantages of these iterators over lists.
Could somebody knowledgeable explain?
I think I am missing out on something. :)
Thanks,
Dragan
However, I think most websites do "paged" database queries anyway, because too
much database thrashing also leads to too much browser thrashing :)
You are right, this default behaviour caused some confusion with me, especially
when I needed to use a record twice inside one page. And I think this case is
more likely than somebody querying for a million records and expecting it to work.
Bests,
Dragan
--
http://noobz.cc/
http://digitalfolklore.org/
http://contemporary-home-computing.org/1tb/
~ theiostream.
On Nov 6, 3:19 pm, Anand Chitipothu <anandol...@gmail.com> wrote:
> 2011/11/6 andrei <andre...@gmail.com>:
Try this:
# I think this the correct header
web.header('Content-type', 'application/json')
# First convert rows into a list of JSON dumps
json_rows = [json.dumps(row) for row in db.select('foo')]
# Then just join them.
return '[%s]' % ', '.join(json_rows)
Have you tried dumping the whole list? Does it work? Like this:
# Dumping a list of rows as JSON
return json.dumps([row for row in db.select('foo')])
Let me know if this works, I'm very curious.
d = web.query("SELECT COUNT(*) AS count FROM mytable")
print d[0].count
both of which IMHO defeat the benefit of iterBetter. My hack was to include dummy data as the last json element as in:
class HMA:
def GET(self):
rows = db.select('TX_CIT_HMA', order='SM_HMA')
web.header('Content-Type', 'application/json')
yield '{identifier: "SM_HMA", items: ['
for row in rows:
yield json.dumps(row) + ','
yield '{"SM_HMA": "None", "TX_HMA": "None"}]}'
Not the best fix I admit.
Yes this will work but defeats the benefit of iterBetter and yield.
--To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/SzTGYLI-0asJ.
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.