[Zope-dev] Re: SQLAlchemy integration experiment
Brian Sutherland
brian at vanguardistas.net
Tue Jun 17 09:36:52 EDT 2008
On Tue, Jun 17, 2008 at 11:58:56AM +0200, Martijn Faassen wrote:
> Anyway, the balance can come out somewhere else. People are free to write
> their own integration approaches, it's just that mine is actually about
> trying to make exactly this pattern work in the first place. Then when I
> succeed people want it changed. :) Anyway, no surprise: I knew that some
> want other patterns, and I'll be curious to see the other approaches as
> well.
Hmm, how about this approach. It builds on and is almost compatible
with yours, but allows me a plug in point where I need it. My use case
is the simplest in that I have no local utilities and no need of
application scoped sessions (plain old thread scoping works just fine).
But I would like to have the option of using code others write for
zope/sqlalchemy and allow others to use our code.
The total code I would write in zope.sqlalchemy would be this:
class ISession(Interface):
def __call__():
"""Return a SQLAlchemy Session object"""
def Session():
return getUtility(ISession)()
I would use it in view code like:
from zope.sqlalchemy import Session
class View:
def some_view_method(self):
session = Session()
session.do_stuff()
I do believe that the application scoping approach you showed us could
be implemented by registering your session as the ISession utility.
It may be that zope.sqlalchemy provides different implementations of
sessions, but I would prefer to see no ISession utility actually
registered.
> Regards,
>
> Martijn
>
> _______________________________________________
> Zope-Dev maillist - Zope-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> ** No cross posts or HTML encoding! **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope )
--
Brian Sutherland
More information about the Zope-Dev
mailing list