On Jul 8, 2008, at 2:04 PM, Manlio Perillo wrote:

>
> I'm thinking to add a function:
>
> # XXX add support for additional parameters like close_with_result?
> def contextual_connect(environ, engine):
>    connection = environ.get('wsgix.dbapi.contextual_connection')
>    if connection is None:
>       connection = engine.connect()
>       environ['wsgix.dbapi.contextual_connection'] = connection
>
>    return connection
>
>
> Using this function I can do:
>
> connection = contextual_connect(environ, engine)
> engine.transaction(callable, connection, *args, **kwargs)
>
> and so on, perhaps implementing some convenient wrappers.
>
>
> Moreover I plan to write a "pseudo" middleware that will take care of
> proper cleanup of the contextual connection at the end of the request.
>
>
> My question is: will this suffice or should I implement something more
> integrated with SQLAlchemy?
>
>
> Another problem is with the ORM, but I'm still studing it since a lot
> has changed since last time I have used it.

Current integration approaches focus on the scoped_session() construct  
as "home base" for the current transaction.  This is an adaption of  
0.3's "SessionContext", and the idea is the same; it receives a  
"scopefunc" which can return any token you like that identifies the  
current "context".  By default, it returns the current thread  
identifier, but you can change it to examine other resources to get at  
the WSGI environ or similar.   When using ORM session, the automatic  
"nesting of begin/commit" behavior is available if you set autocommit  
to True to start with, then use "begin()/commit()" pairs, sending the  
flag "subtransactions=True" to allow subtransactions.  I'm not sure if  
your scheme overall calls for that.

I think the method you're using with an individual connection would  
work fine as well -  the begin() method on connection also nests  
itself with a "subtransaction" when called multiple times.

Obviously, if multiple requests occur async in a single thread, you  
have to ensure the connection pool is sized appropriately otherwise  
your whole app could freeze if an async request blocks on no  
connections available.







>
>
>
>
> Thanks   Manlio Perillo
>
>
>
> >


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