[Zope-dev] Re: zope.sqlalchemy

Laurence Rowe l at lrowe.co.uk
Tue May 6 12:14:40 EDT 2008


Martijn Faassen wrote:
> Hey,
> 
> Laurence Rowe wrote:
>> See pypi or the readme for details, but briefly usage is something like:
>>
>>     >>> engine = create_engine('sqlite:///')
>>     >>> Session = scoped_session(sessionmaker(
>>     ... bind=engine, transactional=True, autoflush=True,
>>     ... extension=ZopeTransactionExtension()))
>>     >>> session = Session()
>>     >>> session.save(User(name='bob'))
>>     >>> transaction.commit()
> 
> One thing I understood from Christian Theune is that with scoped 
> sessions, explicit session.save() is not always necessary. Since I see 
> it being used here, could you perhaps comment on this?

Registering a mapper with Session.mapper would work with this extension, 
but I'm reluctant to recommend it for two reasons: I don't know how it 
works with the declarative plugin; and it necessarily limits mapped 
classes to a single Session and therefor a single engine. In a zope 
context I think it's quite likely that you could have the same classes 
mapped to different databases (i.e. two instances of a single application).

> This is great news, also for megrok.rdb, which we started to develop at 
> the Grokkerdam sprint.

I read somewhere on one of the blog planets that you had discussed 
container implementations. Any more information/code about this? I'm 
quite hopeful that Zope 2.12 will let us share much more code now that 
Acquisition is being tamed.

Laurence



More information about the Zope-Dev mailing list