On Mon, Apr 5, 2010 at 5:55 PM, Michael Bayer <[email protected]>wrote:

> I'm unclear on what usage you'd like to see.


What I'm trying to do would be roughly equivalent to this:

def query_foo(self):
    logger = logging.getLogger(__name__ + '.' + self.__class__.__name__)
    query = self.session.query(Foo)
    logger.debug(query)
    logger.debug(query.compile().params)
    return query.all()

However, this is pretty unmanageable.  The above method could be reduced to
one line of code if not for the logging boilerplate.  So what I'd like to do
is somehow be able to do the above, but without the logger boilerplate.

The main reason for doing this is to have queries logged to where they're
used.  This is really useful because I'm using nose to run tests, and it
would really be nice to be able to filter out all queries except the ones
that are generated by a particular class or module.



> Are you looking for all queries to do this (use Session with query_cls)?


The only way to subclass query to do what I'm looking for would be to
override every method that actually executes the query to log the query and
then execute it.  Is there a better way to do it that I'm not thinking of?

-- 
Jason Baker
Developer
ZeOmega
3010 Gaylord Parkway, Suite 210
Frisco, TX 75034
O:  214-618-9880  ext 8024
[email protected]
www.ZeOmega.com
Proven. Progressive. Partner.

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

Reply via email to