Skip to content

Commit

Permalink
Merge pull request #11 from zopefoundation/REF-91-hurry-query-intids
Browse files Browse the repository at this point in the history
Add ``Ids`` term that queries for intids.
  • Loading branch information
thefunny42 committed Aug 8, 2018
2 parents 4b0f172 + 385b736 commit 38faf01
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGES.txt
Expand Up @@ -4,7 +4,7 @@ CHANGES
3.0.1 (unreleased)
------------------

- Nothing changed yet.
- Add ``Ids`` term that queries for intids.


3.0.0 (2018-01-19)
Expand All @@ -24,7 +24,7 @@ CHANGES

Major:
o Remove unsupported transaction_cache

Minor:
o Clarify HURRY_QUERY_TIMING environment and searchResults(timing=) type
o Fix TimingAwareCaching.report() output typo
Expand Down
2 changes: 1 addition & 1 deletion src/hurry/query/__init__.py
Expand Up @@ -14,6 +14,6 @@
"""
$Id$
"""
from hurry.query.query import All, And, Or, Eq, NotEq, Difference, Objects
from hurry.query.query import All, And, Or, Eq, NotEq, Difference, Objects, Ids
from hurry.query.query import Between, In, Ge, Le, Text
from hurry.query.query import no_results
12 changes: 12 additions & 0 deletions src/hurry/query/query.py
Expand Up @@ -445,6 +445,18 @@ def key(self, context=None):
return ('objects', self.ids(context))


class Ids(Term):

def __init__(self, *ids):
self.ids = ids

def apply(self, cache, context=None):
return IFSet(self.ids)

def key(self, context=None):
return ('ids', self.ids)


class IndexTerm(Term):

def __init__(self, catalog_name__and__index_name):
Expand Down
14 changes: 14 additions & 0 deletions src/hurry/query/query.txt
Expand Up @@ -777,3 +777,17 @@ queries::
>>> from hurry.query import Objects
>>> displayResult(Objects(content))
[<Content "1">, <Content "2">, <Content "3">, <Content "4">, <Content "5">, <Content "6">]

There is a special term that allows querying objects by intid::

>>> from hurry.query import Ids
>>> displayResult(Ids())
[]

>>> all_intids = [intid.getId(x) for x in content]
>>> displayResult(Ids(*all_intids))
[<Content "1">, <Content "2">, <Content "3">, <Content "4">, <Content "5">, <Content "6">]

>>> odd_intids = [intid.getId(x) for x in content if x.id % 2]
>>> displayResult(Ids(*odd_intids))
[<Content "1">, <Content "3">, <Content "5">]

0 comments on commit 38faf01

Please sign in to comment.