diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-04 19:31:52 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-04 19:31:52 (GMT) |
commit | 0d27344cd91294f948c2a62a61b9f92aba7a4c18 (patch) | |
tree | 0b06f2f68ba899d9eeedfa1fdc1e94aac56a1c9c | |
parent | 1f285bce14cad1daaa5791aba705d361b59fe08c (diff) |
support value in (...) style queries, see query.txt
-rw-r--r-- | src/olpc/datastore/query.py | 7 | ||||
-rw-r--r-- | tests/query.txt | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/olpc/datastore/query.py b/src/olpc/datastore/query.py index e450b5a..c65fe14 100644 --- a/src/olpc/datastore/query.py +++ b/src/olpc/datastore/query.py @@ -339,9 +339,14 @@ class QueryManager(SugarDomain): if ctime or mtime: self._query_dates(ctime, mtime, where) for k,v in query.iteritems(): + if isinstance(v, list): + v = properties.c.value.in_(*v) + else: + v = properties.c.value==v + where.append(select([properties.c.content_id], and_( properties.c.key==k, - properties.c.value==v))) + v))) statement = intersect(*where) statement.distinct=True diff --git a/tests/query.txt b/tests/query.txt index 9a16eca..e1f3791 100644 --- a/tests/query.txt +++ b/tests/query.txt @@ -255,6 +255,17 @@ used in the 'author' field. >>> assert set(qm.get_uniquevaluesfor('author')) == set(['Benjamin', 'Sarah']) +Now that we can see a set of possible values it might be nice to +select any content with properties from a known set. For example + +>>> r, c = qm.find(author=['Benjamin', 'Sarah']) +>>> assert c == 3 + +By putting the request value in a list we can ask that the value be +'IN' this collection. All participating values are included in this +way. + + Now for politeness we shut everything down >>> qm.stop() >>> import shutil, os |