On 10.12.2008 20:36 Uhr, Michael Bayer wrote:
>
> 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()
>
Does SA contain some official API to introspect the list of defined
synonyms for a particular class? The goal is to take values defined as a
synonym also into account for the dictification (for backward
compatiblity reasons for an existing codebase).
Andreas
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[email protected]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard