Merge lp:~pedronis/u1db/document-get-index-w-bool-number into lp:u1db

Proposed by Samuele Pedroni
Status: Merged
Approved by: Stuart Langridge
Approved revision: 439
Merged at revision: 439
Proposed branch: lp:~pedronis/u1db/document-get-index-w-bool-number
Merge into: lp:u1db
Diff against target: 51 lines (+27/-2)
1 file modified
html-docs/high-level-api.rst (+27/-2)
To merge this branch: bzr merge lp:~pedronis/u1db/document-get-index-w-bool-number
Reviewer Review Type Date Requested Status
Stuart Langridge (community) Approve
Review via email: mp+165218@code.launchpad.net

Commit message

clarify querying of number() and bool() indexes, values for querying are always strings (atm)

Description of the change

clarify querying of number() and bool() indexes, values for querying are always strings (atm)

To post a comment you must log in.
438. By Samuele Pedroni

bool() query example

439. By Samuele Pedroni

number() example and note

Revision history for this message
Stuart Langridge (sil) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'html-docs/high-level-api.rst'
--- html-docs/high-level-api.rst 2012-09-18 16:25:41 +0000
+++ html-docs/high-level-api.rst 2013-05-24 12:41:26 +0000
@@ -308,8 +308,8 @@
308Querying an index308Querying an index
309^^^^^^^^^^^^^^^^^309^^^^^^^^^^^^^^^^^
310310
311Pass an index key or a tuple of index keys (if the index is on multiple fields)311Pass an index key or multiple index keys (if the index is on multiple fields)
312to ``get_from_index``; the last index key in each tuple (and *only* the last312to ``get_from_index``; the last index key (and *only* the last
313one) can end with an asterisk, which matches initial substrings. So, querying313one) can end with an asterisk, which matches initial substrings. So, querying
314our ``by-firstname`` index from above:314our ``by-firstname`` index from above:
315315
@@ -332,6 +332,30 @@
332 >>> assert(jb.doc_id in js)332 >>> assert(jb.doc_id in js)
333 >>> assert(jm.doc_id in js)333 >>> assert(jm.doc_id in js)
334334
335Index key values used when querying are always strings. If querying an
336index built with ``bool()`` use the values '0' and '1' to query for
337false and true respectively. For an index built with ``number()`` turn
338key number values into strings with the appropriate left zero-padding
339(and note in particular that querying a ``number()`` index with an int
340value, such as ``db.get_from_index('by-number', 9)``, will throw an error).
341
342.. doctest ::
343
344 >>> db = u1db.open('mydb11.u1db', create=True)
345 >>> db.create_index('done', "bool(done)")
346 >>> doc1 = db.create_doc({'task': 'milk', 'done': False, 'hours': 1})
347 >>> doc2 = db.create_doc({'task': 'coding', 'done': True, 'hours': 12})
348 >>> [doc.content['task'] for doc in db.get_from_index('done', '1')]
349 [u'coding']
350 >>> db.create_index('by-hours', "number(hours, 3)")
351 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '12')]
352 []
353 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '012')]
354 [u'coding']
355 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '001')]
356 [u'milk']
357
358
335Index functions359Index functions
336^^^^^^^^^^^^^^^360^^^^^^^^^^^^^^^
337361
@@ -399,4 +423,5 @@
399 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))423 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))
400 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))424 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))
401 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))425 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))
426 os.remove(os.path.join(tmp_dir, "mydb11.u1db"))
402 os.rmdir(tmp_dir)427 os.rmdir(tmp_dir)

Subscribers

People subscribed via source and target branches