开发者

Any good guides and/or advice for indexing my objects in zodb?

I'm going to be writing a general object class for use with zodb. These objects will add themselves to a btree index once they are persisted to the zodb object graph.

I've never really worked with any of this before, but would anyone have any resources and/or advice on doing this?

开发者_如何转开发With zodb's power when dealing with object references and a good indexing strategy, I could end up getting the best of both database worlds.

Any other thoughts are more than welcome, thanks!


Have a look at repoze.catalog:

repoze.catalog is a Python indexing and searching framework. It relies on zope.index and most of its internals are taken from zope.app.catalog. Unlike zope.app.catalog, however, it is meant to be useful outside of the larger Zope framework within arbitrary Python applications.


Depends on your indexing needs, but when all that you need is accessibility by an id, you probably don't need any fancy indexing package.

These objects will add themselves to a btree index once they are persisted to the zodb object graph.

Well, "add themselves" would imply, that they hold a reference to their BTree / index solution. On the other side you're talking about "once they are persited", which implies some kind of "put them into the DB"-function. So I suggest, just do the persisting and indexing of the objects in one go with something like that:

def persist_obj(db, obj):
    tree = db.root()['mybtree']
    id = tree.maxKey() + 1
    obj.id = id
    tree[id] = obj

If you have a wrapper for your database, putting this in a member function of wour wrapper would be the natural location for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜