77from ._types import (
88 BaseRequestOptions ,
99 SDKAxonPublishParams ,
10+ SDKAxonSqlBatchParams ,
11+ SDKAxonSqlQueryParams ,
1012)
1113from .._client import AsyncRunloop
1214from .._streaming import AsyncStream
1315from ..types .axon_view import AxonView
1416from ..types .axon_event_view import AxonEventView
1517from ..types .publish_result_view import PublishResultView
18+ from ..types .axons .sql_batch_result_view import SqlBatchResultView
19+ from ..types .axons .sql_query_result_view import SqlQueryResultView
20+
21+
22+ class AsyncAxonSqlOps :
23+ """[Beta] Async SQL operations for an axon's SQLite database.
24+
25+ Access via ``axon.sql``.
26+
27+ Example:
28+ >>> axon = await runloop.axon.create()
29+ >>> await axon.sql.query(sql="CREATE TABLE tasks (id INTEGER PRIMARY KEY, name TEXT)")
30+ >>> result = await axon.sql.query(sql="SELECT * FROM tasks WHERE id = ?", params=[1])
31+ """
32+
33+ def __init__ (self , client : AsyncRunloop , axon_id : str ) -> None :
34+ self ._client = client
35+ self ._axon_id = axon_id
36+
37+ async def query (self , ** params : Unpack [SDKAxonSqlQueryParams ]) -> SqlQueryResultView :
38+ """[Beta] Execute a single parameterized SQL statement against this axon's SQLite database."""
39+ return await self ._client .axons .sql .query (self ._axon_id , ** params )
40+
41+ async def batch (self , ** params : Unpack [SDKAxonSqlBatchParams ]) -> SqlBatchResultView :
42+ """[Beta] Execute multiple SQL statements atomically within a single transaction."""
43+ return await self ._client .axons .sql .batch (self ._axon_id , ** params )
1644
1745
1846class AsyncAxon :
1947 """[Beta] Wrapper around asynchronous axon operations.
2048
21- Axons are event communication channels that support publishing events
22- and subscribing to event streams via server-sent events (SSE).
49+ Axons are event communication channels that support publishing events,
50+ subscribing to event streams via server-sent events (SSE), and executing
51+ SQL queries against an embedded SQLite database.
2352 Obtain instances via ``runloop.axon.create()`` or ``runloop.axon.from_id()``.
2453
2554 Example:
@@ -29,11 +58,17 @@ class AsyncAxon:
2958 >>> async with await axon.subscribe_sse() as stream:
3059 ... async for event in stream:
3160 ... print(event.event_type, event.payload)
61+ >>> await axon.sql.query(sql="CREATE TABLE tasks (id INTEGER PRIMARY KEY, name TEXT)")
3262 """
3363
3464 def __init__ (self , client : AsyncRunloop , axon_id : str ) -> None :
3565 self ._client = client
3666 self ._id = axon_id
67+ self ._sql = AsyncAxonSqlOps (client , axon_id )
68+
69+ @property
70+ def sql (self ) -> AsyncAxonSqlOps :
71+ return self ._sql
3772
3873 @override
3974 def __repr__ (self ) -> str :
0 commit comments