[sqlalchemy] Re: how many query objects in sa?
On May 28, 2008, at 12:36 PM, Lukasz Szybalski wrote: Hello, I have used the following to query my data: #start class th(object): pass mapper(th,th_table) a = session .query (th ).filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() #end I noticed that there is a query th .query ().filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() but it gives me a : AttributeError: 'generator' object has no attribute 'all' something else is going on there. filter() on Query returns a new Query in all cases. What is th.query() ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how many query objects in sa?
On Wed, May 28, 2008 at 11:59 AM, Michael Bayer [EMAIL PROTECTED] wrote: On May 28, 2008, at 12:36 PM, Lukasz Szybalski wrote: Hello, I have used the following to query my data: #start class th(object): pass mapper(th,th_table) a = session .query (th ).filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() #end I noticed that there is a query th .query ().filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() but it gives me a : AttributeError: 'generator' object has no attribute 'all' something else is going on there. filter() on Query returns a new Query in all cases. What is th.query() ? Since the session is bound to the mapped classes(in tg and in sa). I shouldn't have to use session.query(mymappedclass).somfilter What I want to do is convert the: session.query(th).filter(sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() to just a query using mapped class. Asumed that session.query(th).somefilter is same as th.query().somefilter would do it, but obviously these two are different. So I my question is, are the session.query(th).somefilter vs th.query().somefilter different or am I missing something here. Lucas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how many query objects in sa?
On Wed, May 28, 2008 at 1:07 PM, Lukasz Szybalski [EMAIL PROTECTED] wrote: On Wed, May 28, 2008 at 11:59 AM, Michael Bayer [EMAIL PROTECTED] wrote: On May 28, 2008, at 12:36 PM, Lukasz Szybalski wrote: Hello, I have used the following to query my data: #start class th(object): pass mapper(th,th_table) a = session .query (th ).filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() #end I noticed that there is a query th .query ().filter (sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() but it gives me a : AttributeError: 'generator' object has no attribute 'all' something else is going on there. filter() on Query returns a new Query in all cases. What is th.query() ? Since the session is bound to the mapped classes(in tg and in sa). I shouldn't have to use session.query(mymappedclass).somfilter What I want to do is convert the: session.query(th).filter(sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080325')).all() to just a query using mapped class. sorry. I copied the wrong query Just for clarification: session.query(th).somefilter is same as th.query().somefilter correct? Lucas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how many query objects in sa?
On May 28, 2008, at 2:44 PM, Lukasz Szybalski wrote: sorry. I copied the wrong query Just for clarification: session.query(th).somefilter is same as th.query().somefilter correct? there is a query attribute added to mapped classes if you use the mapper function provided by ScopedSession. Alternatively, ScopedSession also has a method called query_property which can be used to add a similar attribute without the extra functionality implied by ScopedSession.mapper.Otherwise, theres no such attribute query added to mapped classes, and you haven't specified if you're using one of these extensions. The behavior of the query attribute provided by these libraries is to just return a Query so there's no difference in behavior. It is usually common to access the attribute as a descriptor, i.e. cls.query.filter(..) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how many query objects in sa?
On Wed, May 28, 2008 at 2:07 PM, Michael Bayer [EMAIL PROTECTED] wrote: On May 28, 2008, at 2:44 PM, Lukasz Szybalski wrote: sorry. I copied the wrong query Just for clarification: session.query(th).somefilter is same as th.query().somefilter correct? there is a query attribute added to mapped classes if you use the mapper function provided by ScopedSession. Alternatively, ScopedSession also has a method called query_property which can be used to add a similar attribute without the extra functionality implied by ScopedSession.mapper.Otherwise, theres no such attribute query added to mapped classes, and you haven't specified if you're using one of these extensions. The behavior of the query attribute provided by these libraries is to just return a Query so there's no difference in behavior. It is usually common to access the attribute as a descriptor, i.e. cls.query.filter(..) This implementation is in Turbogears so turbogears handles the session management. I assume they have to be using the ScopedSession. Thanks a lot. Lucas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---