pub struct PagedQuery<TRow: Clone + Serialize> {
pub params: PagedQueryParams,
pub current_cursor: Option<Cursor>,
/* private fields */
}Expand description
Generic paginator that wraps the circles_query RPC method.
The fetcher function is responsible for honoring current_cursor if desired.
Fields§
§params: PagedQueryParamsBase params to reuse across calls.
current_cursor: Option<Cursor>Last cursor that was seen (advanced after each page).
Implementations§
Source§impl<TRow> PagedQuery<TRow>
impl<TRow> PagedQuery<TRow>
pub fn new(fetch: PagedFetch<TRow>, params: PagedQueryParams) -> Self
Sourcepub async fn next_page(&mut self) -> Result<Option<Page<TRow>>>
pub async fn next_page(&mut self) -> Result<Option<Page<TRow>>>
Fetch the next page. Consumers can track current_cursor to drive cursor-based filters.
Examples found in repository?
examples/paged_and_ws.rs (line 46)
27async fn main() -> Result<()> {
28 let rpc_url = std::env::var("CIRCLES_RPC_URL").unwrap_or_else(|_| DEFAULT_RPC_URL.to_string());
29 let rpc = CirclesRpc::try_from(rpc_url.as_str())?;
30
31 let avatar: Address = SAMPLE_AVATAR.parse().expect("valid sample address");
32
33 // --- Paged query example (first page) ---
34 let params = PagedQueryParams {
35 namespace: "V_Crc".to_string(),
36 table: "Avatars".to_string(),
37 sort_order: SortOrder::DESC,
38 columns: vec!["avatar".into(), "timestamp".into()],
39 filter: None,
40 cursor_columns: None,
41 order_columns: None,
42 limit: 10,
43 };
44
45 let mut pager = rpc.paged_query::<AvatarRow>(params);
46 if let Some(page) = pager.next_page().await? {
47 println!(
48 "Fetched {} avatar rows (has_more={})",
49 page.items.len(),
50 page.has_more
51 );
52 for row in page.items {
53 println!("avatar {} @ {}", row.avatar, row.timestamp);
54 }
55 } else {
56 println!("No rows returned");
57 }
58
59 // --- WebSocket events example (requires `ws` feature) ---
60 #[cfg(feature = "ws")]
61 {
62 let ws_url =
63 std::env::var("CIRCLES_RPC_WS_URL").unwrap_or_else(|_| DEFAULT_WS_URL.to_string());
64 match CirclesRpc::try_from_ws(ws_url.as_str()).await {
65 Ok(rpc_ws) => stream_events(&rpc_ws, avatar).await?,
66 Err(e) => println!("WebSocket connect failed, skipping subscription: {e}"),
67 }
68 }
69 #[cfg(not(feature = "ws"))]
70 {
71 println!("WebSocket example skipped; enable the `ws` feature to run it.");
72 }
73
74 Ok(())
75}Sourcepub fn into_stream(self) -> impl Stream<Item = Result<TRow>>
pub fn into_stream(self) -> impl Stream<Item = Result<TRow>>
Convert this paginator into a stream of rows.
Auto Trait Implementations§
impl<TRow> Freeze for PagedQuery<TRow>
impl<TRow> !RefUnwindSafe for PagedQuery<TRow>
impl<TRow> Send for PagedQuery<TRow>
impl<TRow> Sync for PagedQuery<TRow>
impl<TRow> Unpin for PagedQuery<TRow>
impl<TRow> UnsafeUnpin for PagedQuery<TRow>
impl<TRow> !UnwindSafe for PagedQuery<TRow>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more