[Zope-dev] SQLAlchemy (zope.sqlalchemy) integration
Hi, Regarding to the discussion some days ago with the SQLAlchemy Zope3 integration, I still have problems with retrieving the session. I currently use a utility for the engine, which seems to work well. However, for retrieving the session, I tried to use the following pattern (many thanks to Michael Bayer, btw.): database module --- SASession = scoped_session(sessionmaker( transactional = True, autoflush = True, extension = ZopeTransactionExtension())) def getSASession(): SASession.remove() engine = getUtility(ISAEngineUtility).getEngine() s = SASession() s.bind = engine return s In my application, I then use getSASession() to retrieve my session. However, what I think is not that beautiful is the s.bind = engine part. Are there any suggestions how to improve this? Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 ___ Zope-Dev maillist - Zope-Dev@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 )
Re: [Zope-dev] SQLAlchemy (zope.sqlalchemy) integration
On Jun 4, 2008, at 12:02 PM, Hermann Himmelbauer wrote: Hi, Regarding to the discussion some days ago with the SQLAlchemy Zope3 integration, I still have problems with retrieving the session. I currently use a utility for the engine, which seems to work well. However, for retrieving the session, I tried to use the following pattern (many thanks to Michael Bayer, btw.): database module --- SASession = scoped_session(sessionmaker( transactional = True, autoflush = True, extension = ZopeTransactionExtension())) def getSASession(): SASession.remove() engine = getUtility(ISAEngineUtility).getEngine() s = SASession() s.bind = engine return s In my application, I then use getSASession() to retrieve my session. However, what I think is not that beautiful is the s.bind = engine part. Are there any suggestions how to improve this? FTR, my suggestion here is to configure/tear down sessions upon request boundaries, as described in http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_lifespan . ___ Zope-Dev maillist - Zope-Dev@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 )