From: Jonathan E. <jon...@ca...> - 2006-06-06 16:47:33
|
On Tue, 06 Jun 2006 12:05:41 -0400, "Bruce Webber" <bru...@fa...> said: > I created a small Spyce application for my team to enter project > information into an SQLite database. I'm using SQL Alchemy to manage the > database. > > Spyce is installed on a Windows 2000 Server running Apache. Spyce is > running as a webserver and I'm using Apache's mod_proxy and mod_redirect > so > that requests for .spy pages are passed to Spyce on port 8000. > > This all seems to work fine, and I really like SQL Alchemy. > > When I create an SQL Alchemy engine, session, metadata and mapping > objects, > these objects persist even after the Spyce page completes. To avoid > attempting to recreate these objects (which results in an error), I'm > using > the Spyce pool module to store a "flag" which tells if the objects have > been created. If you want a global session (and, as you noticed, you probably don't :), rather than a pool + flags approach, it's more straightforward to put your initialization code in your configuration .py file, which you can then use as "from spyceConfig import ..." (No matter what your config file is actually named, spyce references it as spyceConfig.) > Is this the expected behavior? For a global session, yes. > I like it (I expect it improves > performance)but I'd like to understand it better, as I did not explicitly > place the SQL Alchemy objects in the pool to be retained. > > Also, it occurs to me that I should create an SQL Alchemy session object > for each Spyce page (closing it at the bottom of the page), so that users > do not share the same database session. Does this make sense? Yes, that's a better way to go. The next level of code-reuse would be to create a spyce module that takes care of create_session and flush automatically. Then all you have to do is [[.import name=db]]. Something like this: from spyceModule import spyceModule from sqlalchemy import * class db(spyceModule): def start(self): self._session = create_session() def finish(self, error): if not error: self._session.flush() def __getattr__(self, attr): return getattr(self._session, attr) -Jonathan -- C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay |