Skip to content

Commit 3ed7f4b

Browse files
fix: update 05_queries.py to new query api
1 parent a67f3ff commit 3ed7f4b

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

β€Žpyproject.tomlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Starter template for Arkiv Python SDK"
55
readme = "README.md"
66
requires-python = ">=3.10"
77
dependencies = [
8-
"arkiv-sdk[dev]>=1.0.0a10",
8+
"arkiv-sdk[dev]>=1.0.0b1",
99
]
1010

1111
[build-system]

β€Žsrc/arkiv_starter/03_clients.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from arkiv.provider import ProviderBuilder
1919
from urllib.parse import urlparse
2020

21-
EXTERNAL_RPC_URL: str = "https://mendoza.hoodi.arkiv.network/rpc"
21+
EXTERNAL_RPC_URL: str = "https://rosario.hoodi.arkiv.network/rpc"
2222

2323
def is_rpc_reachable(rpc_url: str, timeout: float = 2.0) -> bool:
2424
"""Check if RPC endpoint is reachable using a simple socket connection."""

β€Žsrc/arkiv_starter/05_queries.pyβ€Ž

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
"""
2-
Example 3: Querying Entities with Filters
2+
Example 5: Querying Entities with Filters
33
44
This example demonstrates:
55
- Creating multiple entities
6-
- Querying with filters (owner, content type)
6+
- Querying with the fluent query builder
7+
- Filtering with typed attributes
78
- Sorting results
8-
- Pagination
99
10-
Run this example: uv run python -m arkiv_starter.03_queries
10+
Run this example: uv run python -m arkiv_starter.05_queries
1111
"""
1212

13-
from arkiv.provider import ProviderBuilder
14-
from arkiv import Arkiv, NamedAccount
15-
from arkiv.node import ArkivNode
16-
from arkiv.types import OrderByAttribute, QueryOptions, INT, DESC, Attributes
13+
from arkiv import Arkiv, IntAttr, IntSort, StrAttr
14+
from arkiv.types import DESC, Attributes
1715

1816
# Setup: Start node and create client
1917
print("πŸš€ Starting local Arkiv node and client ...")
@@ -50,20 +48,30 @@
5048
entities.append(entity_key)
5149
print(f" Created JSON entity: {entity_key}")
5250

51+
# Query 1: Retrieve all entities with details
52+
# Define typed attributes
53+
owner = StrAttr("$owner")
54+
idx = IntAttr("idx")
55+
5356
print(f"\nπŸ” Query 1: Retrieving all entities with details...")
54-
all_with_details = list(client.arkiv.query_entities(f'$owner = "{account}"'))
57+
all_with_details = list(client.arkiv.select().where(owner == account).fetch())
5558
print(f"βœ… Found {len(all_with_details)} entities:")
5659
for entity in all_with_details:
5760
if entity.payload:
5861
content = entity.payload.decode('utf-8')
5962
print(f" Type: {entity.content_type:20} | {content:30} | {entity.attributes}")
6063

64+
# Query 2: Retrieve entities filtered by idx and sorted by idx descending
65+
idx_desc = IntSort("idx", DESC)
66+
6167
print("\nπŸ” Query 2: Retrieving filtered (idx > 1 and idx < 5) and sorted (idx desc) entities")
62-
sort = OrderByAttribute("idx", INT, DESC)
63-
options = QueryOptions(order_by=[sort])
64-
filtered_and_sorted = list(client.arkiv.query_entities(f"idx > 1 and idx < 5", options=options))
68+
filtered_and_sorted = list(client.arkiv.select().where((idx > 1) & (idx < 5)).order_by(idx_desc).fetch())
6569
print(f"βœ… Found {len(filtered_and_sorted)} entities:")
6670
for entity in filtered_and_sorted:
6771
if entity.payload:
6872
content = entity.payload.decode('utf-8')
6973
print(f" Type: {entity.content_type:20} | {content:30} | {entity.attributes}")
74+
75+
# Cleanup
76+
client.node.stop()
77+
print("\nβœ… Node stopped.")

β€Žuv.lockβ€Ž

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)