[Zope-dev] Re: SQLAlchemy integration experiment

Martijn Faassen faassen at startifact.com
Tue Jun 17 11:21:18 EDT 2008


Laurence Rowe wrote:
[snip]
> Why not just have:
> 
> class IDatabase(Interface):
>     """A utility that specifies the database.
>     """
> 
>     def session_factory():
>         """Create a new session
>         """
> 
>     def id():
>         """Get unique id for this database configuration.
> 
>         This should be unique per site (application).
>         """

This looks quite a lot like my proposed new IDatabase, which in fact 
also has a scopefunc() method, so that you can have a simple per-thread 
scope if you don't care about per-application scopes.

> class Database(grok.LocalUtility):
>     grok.implements(IDatabase)
> 
>     def session_factory(self):
>         engine = create_engine(
>             'postgres:///experiment',
>             convert_unicode=True)
>         return create_session(
>             bind=engine,
>             autocommit=True,
>             autoflush=True,
>             extension=ZopeTransactionExtension())
> 
>     def id(self):
>         # we use the application name as the unique id. Can we use
>         # something more clever and universally working?
>         return self.__parent__.__name__

Yes, that would be good. I'm just making sure it's wise to recreate an 
engine for each thread/application.

Regards,

Martijn



More information about the Zope-Dev mailing list