[storm] Store factory for ZStorm
James Henstridge
james at jamesh.id.au
Thu Jul 9 03:39:07 BST 2009
On Wed, Jul 8, 2009 at 6:05 PM, Stuart
Bishop<stuart.bishop at canonical.com> wrote:
> On Tue, Jul 7, 2009 at 12:25 AM, Gustavo Niemeyer<gustavo at niemeyer.net> wrote:
>> Hi Stuart,
>>
>> Thanks for bringing this up here.
>>
>>> I've done this by extending ZStorm.get and ZStorm.create with a
>>> store_factory argument. The default factory is storm.store.Store.
>>>
>>> jamesh (who has reviewed this branch so far) felt it necessary to add a
>>> configure-once-first API too, so I've also added
>>> ZStore.set_default_store_factory to mirror ZStore.set_default_uri.
>>>
>>> Passing a factory to ZStorm seems like the cleanest way of supporting my use
>>> cases and is also the most flexible.
>>
>> I agree with James. I'd actually go even further than this, and
>> define *only* the ZStorm-wide factory. So, in practice, defining a
>> ZStorm.set_store_factory() method and using only this factory
>> internally. Even if there are per-URI differences, it would be
>> possible to code these inside the story factory itself, so the
>> individual methods likely won't need additional extensions.
>
> Should the uri argument to ZStorm.get and ZStorm.create get dropped
> too or left for backwards compatibility?
The argument to create() should stay, since that provides a way to
create temporary stores that are linked to the Zope transaction.
I always found the uri argument to get() a bit of a weird one, but it
is currently used by a number of projects (you mentioned Launchpad,
and I think UbuntuOne calls it somewhere). So the most that could be
done in the short term would be deprecation.
If we had no users, I'd probably structure the API as:
def create(uri, store_factory=None):
# Create a store with given database uri, hooked up to the TM
def configure_store(name, uri, store_factory=None):
# Set database URI and store factory for named store.
def get(name):
# Get the named store, creating one if it doesn't exist for this thread.
# Store is created via create() using values from configure_store().
# This method updates _named and _name_index instead of create()
James.
More information about the storm
mailing list