Brian Sutherland wrote:
[snip]
This would probably be close to what I would write for my usecase:

class Database:

    implements(IDatabase)

    def __init__(self, *args, **kw):
        self._args = args
        self._kw = kw

    def scopefunc(self):
        return None # use default per-thread scoping

    def session_factory(self):
        return sessionmaker(*self._args, **self._kw)

I don't think you can use sessionmaker, as that creates a class and you need to create an actual session in this place. You'd need create_session. You'd also need to implement your scopefunc, otherwise you get *no* scoping at all, not even per thread, so return thread.get_ident().

Like this:

class Database:
    implements(IDatabase)

    def __init__(self, *args, **kw):
        self._args = args
        self._kw = kw

    def scopefunc(self):
        return thread.get_ident()

    def session_factory(self):
        return create_session(*self._args, **self._kw)

we're ignoring the details of what creates the engine, but if you pass 'bind' along when you create Database that should take care of it.

Regards,

Martijn

_______________________________________________
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 )

Reply via email to