[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-19 Thread King Simon-NFHD78

 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:sqlalch...@googlegroups.com] On Behalf Of Andreas Jung
 Sent: 19 December 2008 06:30
 To: sqlalchemy@googlegroups.com
 Subject: [sqlalchemy] Re: Efficient dictificationof result sets
 
 On 19.12.2008 2:57 Uhr, Michael Bayer wrote:
 
  On Dec 18, 2008, at 3:04 PM, Andreas Jung wrote:
  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).
 
  the mapper's get_property() method includes a resolve_synonyms
  keyword arg that indicates a given key which points to a synonym
  should return the actual referenced property, so a recipe 
 that builds
  upon this would look like:
 
  set([mapper.get_property(p.key, resolve_synonyms=True) for p in
  mapper.iterate_properties])
 
 However this does not apply when using the declarative layer. Any 
 options within such a context?
 
 Andreas
 

I haven't been following this discussion closely, so I'm probably wrong,
but that statement doesn't sound right to me. As far as I'm aware, the
declarative layer is just a convenience for setting up Tables and mapped
classes at the same time. The end result is exactly the same as if you
created the tables and classes in the traditional way. I would be very
surprised if the above expression didn't work.

You can get the mapper for a mapped class or object using the
class_mapper and object_mapper functions.

Hope that helps,

Simon

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-19 Thread az

exactly, the declarative layer is syntax sugar, i.e. shorter way to 
say same thing, same as elixir and dbcook - they just differ in how 
many things each one automates/hides.
after that, i.e. after mappers compiled, it's all plain SA - sessions, 
queries etc...
i dont know about elixir, although dbcook does have some extra 
conveniences around query and overall model'metadata, they do not 
change the overall idea - it's another shorter way to say same 
thing.

ciao
svil

On Friday 19 December 2008 12:02:07 King Simon-NFHD78 wrote:
  -Original Message-
  From: sqlalchemy@googlegroups.com
  [mailto:sqlalch...@googlegroups.com] On Behalf Of Andreas Jung
  Sent: 19 December 2008 06:30
  To: sqlalchemy@googlegroups.com
  Subject: [sqlalchemy] Re: Efficient dictificationof result sets
 
  On 19.12.2008 2:57 Uhr, Michael Bayer wrote:
   On Dec 18, 2008, at 3:04 PM, Andreas Jung wrote:
   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).
  
   the mapper's get_property() method includes a
   resolve_synonyms keyword arg that indicates a given key which
   points to a synonym should return the actual referenced
   property, so a recipe
 
  that builds
 
   upon this would look like:
  
   set([mapper.get_property(p.key, resolve_synonyms=True) for p in
   mapper.iterate_properties])
 
  However this does not apply when using the declarative layer. Any
  options within such a context?
 
  Andreas

 I haven't been following this discussion closely, so I'm probably
 wrong, but that statement doesn't sound right to me. As far as I'm
 aware, the declarative layer is just a convenience for setting up
 Tables and mapped classes at the same time. The end result is
 exactly the same as if you created the tables and classes in the
 traditional way. I would be very surprised if the above expression
 didn't work.

 You can get the mapper for a mapped class or object using the
 class_mapper and object_mapper functions.

 Hope that helps,

 Simon

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-18 Thread Andreas Jung
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 sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
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:i...@zopyx.com
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



[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-18 Thread Michael Bayer


On Dec 18, 2008, at 3:04 PM, Andreas Jung wrote:

 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).

the mapper's get_property() method includes a resolve_synonyms  
keyword arg that indicates a given key which points to a synonym  
should return the actual referenced property, so a recipe that builds  
upon this would look like:

set([mapper.get_property(p.key, resolve_synonyms=True) for p in  
mapper.iterate_properties])





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-18 Thread Andreas Jung
On 19.12.2008 2:57 Uhr, Michael Bayer wrote:

 On Dec 18, 2008, at 3:04 PM, Andreas Jung wrote:

 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).

 the mapper's get_property() method includes a resolve_synonyms
 keyword arg that indicates a given key which points to a synonym
 should return the actual referenced property, so a recipe that builds
 upon this would look like:

 set([mapper.get_property(p.key, resolve_synonyms=True) for p in
 mapper.iterate_properties])

However this does not apply when using the declarative layer. Any 
options within such a context?

Andreas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
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:i...@zopyx.com
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



[sqlalchemy] Re: Efficient dictificationof result sets

2008-12-10 Thread Michael Bayer


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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---