[Zope-dev] Re: zope.sqlalchemy

Laurence Rowe l at lrowe.co.uk
Wed May 7 08:48:52 EDT 2008


Martijn Faassen wrote:
> Hi there (especially Christian),
> 
> I think we can work with explicits saves. In many cases the user won't 
> have to worry about it anyway as the container object will do it for 
> them (besides making the relation), or this 'query container' we spoke 
> of will do it for them (but just the 'save' bit).
> 
> One point is that the scoped session approach itself doesn't work very 
> well for using multiple databases in the same app. We could consider 
> passing the session along in the containers during object graph wakling 
> (or traversal) so an app can easily traverse into multiple databases. 
> I'm not sure whether we can make the ORM do this for us though; does it 
> initialize the mapping with a session?

Registering a ScopedSession as a utility seems a good approach. I'm 
experimenting with ways of registering engines as local utilities. 
Hopefully the combination will allow something along the lines of:

 >>> Session = 
scoped_session(sessionmaker(bind=LookupEngine('my-engine')...))
 >>> provideUtility(Session, IScopedSession, 'my-app')
 >>> engine = EngineUtility(url='sqlite:///')
 >>> provideUtility(engine, IConnectable, 'my-engine') # but normally a 
local utility registration

The code would get a session through:

 >>> Session = getUtility(IScopedSession, 'my-app')
 >>> session = Session()

Mappers are registered with the metadata, so nothing special need be 
done here.

Laurence



More information about the Zope-Dev mailing list