|
17 | 17 |
|
18 | 18 | class Query: |
19 | 19 | """ |
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. |
21 | 23 | """ |
22 | 24 | def __init__(self, c_query, box: 'Box'): |
| 25 | + """ This is an internal constructor. Use ``Box.query()`` instead. """ |
23 | 26 | self._c_query = c_query |
24 | 27 | self._box = box |
25 | 28 | self._entity = self._box._entity |
@@ -122,20 +125,31 @@ def find_ids_by_score_numpy(self) -> np.array: |
122 | 125 | obx_id_array_free(c_id_array_p) |
123 | 126 |
|
124 | 127 | 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). """ |
125 | 130 | count = ctypes.c_uint64() |
126 | 131 | obx_query_count(self._c_query, ctypes.byref(count)) |
127 | 132 | return int(count.value) |
128 | 133 |
|
129 | 134 | def remove(self) -> int: |
| 135 | + """ Removes the objects that are matched by this query. """ |
130 | 136 | count = ctypes.c_uint64() |
131 | 137 | obx_query_remove(self._c_query, ctypes.byref(count)) |
132 | 138 | return int(count.value) |
133 | 139 |
|
134 | 140 | 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. """ |
135 | 145 | obx_query_offset(self._c_query, offset) |
136 | 146 | return self |
137 | 147 |
|
138 | 148 | 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. """ |
139 | 153 | obx_query_limit(self._c_query, limit) |
140 | 154 | return self |
141 | 155 |
|
|
0 commit comments