On Oct 28, 2008, at 12:09 PM, Felix Schwarz wrote:

>
> Hi,
>
> I develop an extension for the well known Trac. trac itself has an
> extremly simple db 'layer' for creating tables and the like but all  
> sql
> queries must be generated manually.
>
> This sucks - however, if you only have simple queries, it still works.
>
> But now I'm debugging a somewhat bigger query with 3-4 joins, some
> unions and multiple sub-selects. This is really the point where I  
> should
> start with SQLAlchemy :-)
>
> Now I have an open db connection which is managed by trac. Can I re- 
> use
>  this connection for my SQLAlchemy needs? In the beginning, I don't
> want to use the declarative layer or anything. No transaction  
> control etc.


sqlalchemy would want the connection to be involved in an Engine()  
somehow.   If there's just one connection for the whole thing, you'd  
put it into a creator() such as:

from sqlalchemy import create_engine
from sqlalchemy.pool import StaticPool
e = create_engine('postgres://', creator = lambda: my_trac_connection,  
poolclass=StaticPool)

the StaticPool means the SQLA pool wont be involved in creating new  
connections or closing any of them, it just calls the creator once and  
thats it.

that approach above is generally only as threadsafe as the original  
connection object itself.   SQLA also likes the "engine" to be created  
just once per application.   So if trac has more of an opening/closing  
connections thing going on as opposed to just one "per-process"  
connection, you'd want to wire into that, which may be easiest by  
writing a custom pool class.  you only need to create one or two  
methods.

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

Reply via email to