[ZODB-Dev] grab zodb dict keys by search term

Darryl Dixon - Winterhouse Consulting darryl.dixon at winterhouseconsulting.com
Wed Dec 11 02:56:53 CET 2013


Hi Tamer,

It depends on what you're trying to achieve. BTrees should not be mutated
whilst iterating over them, so depending on how you have structured your
data, you might do something like:

for key in [x for x in BTree.keys() if x.startswith('aa')]:
    # Do stuff

Or perhaps something else like:

for key in list(BTree.keys()):
    if key['subkey'] == 5:
        yield BTree[key]

...Or some other pattern depending on your use case.

The key here is that the ZODB really allows you to "cut out the middle
man" where previously you might store data in an RDBMS and then do
processing/transformation of that data in Python after extracting it with
SQL (and then re-storing it again afterwards), instead now you can just
directly process the data as if it was in Python objects waiting the
entire time.

Hope this helps.

regards,
Darryl Dixon
Winterhouse Consulting Ltd


> Hi people!
>
> I am working a lot with IOB and OOB Trees as well with PersistentDict
> and PersistentList to store my Data in ZODB.
> I want to ask if there is a way to grab data from a dataset by search
> time.
>
> I know only the SQL way:
>
> select lower(COL1) from table1 where COL1 LIKE 'aa%'
>
> so usually I want to get the entryies only that starts with 'aa'
>
> do I have to iterate the entire dict with an interator or are there
> builtin functions that could accomplish those tasks for me ?!
>
>
> I would kindly thank you
>
>
>
> Tamer
> _______________________________________________
> For more information about ZODB, see http://zodb.org/
>
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
>



More information about the ZODB-Dev mailing list