Skip to content

Commit d652e0f

Browse files
committed
Add a couple of docs to Query #52
Removed QueryBuilder from overview.rst again as using it directly is not a typical thing to do.
1 parent 8fad368 commit d652e0f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

doc/overview.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ These are the main classes to interact with:
4646

4747
Store
4848
Box
49-
QueryBuilder
5049
Query
5150

5251
What's next

objectbox/query.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
class Query:
1919
"""
20-
Query expression
20+
Query is a reusable object that allows you to find objects in the database.
21+
It is created by calling ``Box.query()`` with conditions inside and finalizing with ``build()``.
22+
Note: Query objects are not thread-safe and should not be shared between threads.
2123
"""
2224
def __init__(self, c_query, box: 'Box'):
25+
""" This is an internal constructor. Use ``Box.query()`` instead. """
2326
self._c_query = c_query
2427
self._box = box
2528
self._entity = self._box._entity
@@ -122,20 +125,31 @@ def find_ids_by_score_numpy(self) -> np.array:
122125
obx_id_array_free(c_id_array_p)
123126

124127
def count(self) -> int:
128+
""" Counts the objects that are matched by this query.
129+
In other words, it gives the size of the result set). """
125130
count = ctypes.c_uint64()
126131
obx_query_count(self._c_query, ctypes.byref(count))
127132
return int(count.value)
128133

129134
def remove(self) -> int:
135+
""" Removes the objects that are matched by this query. """
130136
count = ctypes.c_uint64()
131137
obx_query_remove(self._c_query, ctypes.byref(count))
132138
return int(count.value)
133139

134140
def offset(self, offset: int) -> 'Query':
141+
""" Configure an offset for this query.
142+
All methods that support offset will return/process objects starting at this offset.
143+
Example use case: use together with limit to get a slice of the whole result, e.g. for "result paging".
144+
Call with offset=0 to reset to the default behavior, i.e. starting from the first element. """
135145
obx_query_offset(self._c_query, offset)
136146
return self
137147

138148
def limit(self, limit: int) -> 'Query':
149+
""" Configure a limit for this query.
150+
All methods that support limit will return/process only the given number of objects.
151+
Example use case: use together with offset to get a slice of the whole result, e.g. for "result paging".
152+
Call with limit=0 to reset to the default behavior - zero limit means no limit applied. """
139153
obx_query_limit(self._c_query, limit)
140154
return self
141155

0 commit comments

Comments
 (0)