[Zope] Questions on ZODB BTrees versus bsddb BTrees
Chris Withers
chris at simplistix.co.uk
Fri May 5 03:36:35 EDT 2006
Terry Jones wrote:
> Usually you find database records by means of the record's key.
> However, the key that you use for your record will not always contain
> the information required to provide you with rapid access to the data
> that you want to retrieve.
Ah, okay, you do this with multiple BTrees in Zope, unless you want to
swallow the whole ZCatalog...
> For example, suppose your database contains
> records related to users. The key might be a string that is some unique
> identifier for the person, such as a user ID.
from BTrees.IOBTree import IOBTree
chris = object()
id2user = IOBTree()
id2user[1234] = chris
> is, by the information stored in the key), it may also on occasion want
> to location people by, say, their name.
from BTrees.OOBTree import OOBTree, OOSet
name2user = OOBTree()
name2user['chris'] = chris
Now, if you have more than one value, you use a set:
dan = object()
age2user = OOBTree()
age2user[27] = OOSet(chris,dan)
Although, to be honest, if you're doing all this, you'll likely get more
milleage out of the zcatalog than rolling it all yourself...
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list