Skip to main content

PagedQuery

Struct PagedQuery 

Source
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: PagedQueryParams

Base params to reuse across calls.

§current_cursor: Option<Cursor>

Last cursor that was seen (advanced after each page).

Implementations§

Source§

impl<TRow> PagedQuery<TRow>
where TRow: Clone + Serialize + DeserializeOwned + Send + 'static,

Source

pub fn new(fetch: PagedFetch<TRow>, params: PagedQueryParams) -> Self

Source

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}
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more