On Dec 10, 2008, at 2:27 PM, Andreas Jung wrote:
> Hi there,
>
> is there some more efficient way for dictifying a resultset other than
>
> lst = list()
> for row in session.query(...).all():
>
> d = self.__dict__.copy()
> for k in d.keys():
> if k.startswith('_sa'):
> del d[k]
>
> lst.append(d)
>
> Especially the loop of the keys takes pretty long for large result
> sets
> and tables with lots of columns.
the most efficient way would be to use a ResultProxy instead of the
ORM and to call dict() on each row. Otherwise a more succinct way
of what you're doing there, not necessarily much faster, might be
list = [
dict((k, v) for k, v in obj.__dict__.iteritems() if not
k.startswith('_sa'))
for obj in session.query.all()
]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---