Skip to content

Commit f36d327

Browse files
author
Matthias Zimmermann
committed
docs: add sorting to readme
1 parent da0ba06 commit f36d327

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,51 @@ query = 'email GLOB "*@example.com"' # Emails ending with @example.com
242242
**Note:** String values in queries must be enclosed in double quotes (`"`). Numeric values do not require quotes. The `GLOB` operator supports pattern matching using `*` as a wildcard character.
243243
Note that the GLOB operator might be replace by a SQL standard LIKE operator in the future.
244244

245+
### Sorting
246+
247+
Query results can be sorted by one or more attribute fields in ascending or descending order. Sorting supports both string and numeric attributes, with multi-field sorting following priority order (first field has highest priority).
248+
249+
#### Basic Sorting
250+
251+
```python
252+
from arkiv import Arkiv, ASC, DESC, STR, INT, OrderByAttribute, QueryOptions
253+
254+
client = Arkiv()
255+
256+
# Sort by string attribute (default sorting: ascending)
257+
order_by = [OrderByAttribute(attribute="name", type=STR)]
258+
options = QueryOptions(order_by=order_by)
259+
entities = list(client.arkiv.query_entities('type = "user"', options=options))
260+
261+
# Sort by numeric attribute (descending, needs to be set explicitly)
262+
order_by = [OrderByAttribute(attribute="age", type=INT, direction=DESC)]
263+
options = QueryOptions(order_by=order_by)
264+
entities = list(client.arkiv.query_entities('type = "user"', options=options))
265+
```
266+
267+
#### Multi-Attribute Sorting
268+
269+
When sorting by multiple attributes, the first attribute has the highest priority, with subsequent attributes acting as tie-breakers:
270+
271+
```python
272+
# Sort by status (ascending), then by age (descending)
273+
order_by = [
274+
OrderByAttribute(attribute="status", type=STR, direction=ASC),
275+
OrderByAttribute(attribute="age", type=INT, direction=DESC),
276+
]
277+
options = QueryOptions(order_by=order_by)
278+
entities = list(client.arkiv.query_entities('type = "user"', options=options))
279+
280+
# Three-level sorting: type, then priority, then name
281+
order_by = [
282+
OrderByAttribute(attribute="type", type=STR),
283+
OrderByAttribute(attribute="priority", type=INT, direction=DESC),
284+
OrderByAttribute(attribute="name", type=STR),
285+
]
286+
options = QueryOptions(order_by=order_by)
287+
entities = list(client.arkiv.query_entities('status = "active"', options=options))
288+
```
289+
245290
### Watch Entity Events
246291

247292
Arkiv provides near real-time event monitoring for entity lifecycle changes. You can watch for entity creation, updates, extensions, deletions, and ownership changes using callback-based event filters.

0 commit comments

Comments
 (0)