the session does bind to a single engine most easily:

        s = create_session(bind_to=engine)

then you can in fact say:

        conn = session.connection(None)

now.  should we just have session.connection() and have the mapper  
argument be optional ?  I chose to make it required to start with,  
based on "explicit is better than implicit".   since in most cases  
these days, people have the engine accessible via the Tables inside  
of Mappers and arent doing that explicit session thing, so in those  
cases session.connection() wouldnt work.


On Jun 12, 2006, at 8:54 PM, Daniel Miller wrote:

>
> Steve Zatz wrote:
>> I occasionally need to drop into straight SQL when using a session
>> object with a threadlocal strategy.  It is probably obvious but I am
>> not sure how to obtain the same connection that the session object is
>> using to execute straight SQL.
>>
>
> You might try this:
>
> conn = session.connection(None)
>
> I'm not sure if that will work in your case, but it seems like the  
> simplest solution. If that doesn't work try this:
>
> conn = session.connection(mapper)
>
> with a mapper that is bound to the engine on which you'd like to  
> execute SQL. I worked with Mike to make the Session object more  
> useful, but haven't had time to work on the Connection and Engine  
> interfaces. There seems to be a lot of methods on those interfaces  
> that are used internally by SA, but understanding them for external  
> use is baffling to me. I haven't bothered to do it yet because I  
> haven't needed too...
>
> IMO Session should have a connection() method that takes no  
> arguments. Like this:
>
> conn = session.connection()
>
> The multiple-engines-per-session code makes the Session object seem  
> unnecessarily complex to me, and it doesn't seem like most people  
> will be using it that way either. I know there is at least one  
> person using SA that needs this functionality, but I would have  
> liked to see the Session work with a single connection by default  
> and have the multiple-engine stuff implemented as a connection  
> proxy (or something like that) that handles all the multi-engine  
> complexity internally. Just my $0.02. Like I said, I haven't had  
> time to look at this for a while.
>
> ~ Daniel
>
>
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to