On Tue, Jun 17, 2008 at 06:05:10PM +0200, Martijn Faassen wrote:
> 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().

Whoops!

There goes my reputation, if I had one;)

> 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.

Yep. As I don't try store anything in the ZODB, my case is much simpler.

I can just instantiate the Database object as a module level global and
register is via ZCML.

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

-- 
Brian Sutherland
_______________________________________________
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