pub struct Paginator<'db, C, S> where
C: ConnectionTrait,
S: SelectorTrait + 'db, { /* private fields */ }
Expand description
Defined a structure to handle pagination of a result from a query operation on a Model
Implementations
sourceimpl<'db, C, S> Paginator<'db, C, S> where
C: ConnectionTrait,
S: SelectorTrait + 'db,
impl<'db, C, S> Paginator<'db, C, S> where
C: ConnectionTrait,
S: SelectorTrait + 'db,
sourcepub async fn fetch_page(&self, page: usize) -> Result<Vec<S::Item>, DbErr>
pub async fn fetch_page(&self, page: usize) -> Result<Vec<S::Item>, DbErr>
Fetch a specific page; page index starts from zero
sourcepub async fn num_items_and_pages(&self) -> Result<ItemsAndPagesNumber, DbErr>
pub async fn num_items_and_pages(&self) -> Result<ItemsAndPagesNumber, DbErr>
Get the total number of items and pages
sourcepub async fn fetch_and_next(&mut self) -> Result<Option<Vec<S::Item>>, DbErr>
pub async fn fetch_and_next(&mut self) -> Result<Option<Vec<S::Item>>, DbErr>
Fetch one page and increment the page counter
use sea_orm::{entity::*, query::*, tests_cfg::cake};
let mut cake_pages = cake::Entity::find()
.order_by_asc(cake::Column::Id)
.paginate(db, 50);
while let Some(cakes) = cake_pages.fetch_and_next().await? {
// Do something on cakes: Vec<cake::Model>
}
sourcepub fn into_stream(self) -> PinBoxStream<'db, Result<Vec<S::Item>, DbErr>>
pub fn into_stream(self) -> PinBoxStream<'db, Result<Vec<S::Item>, DbErr>>
Convert self into an async stream
use futures::TryStreamExt;
use sea_orm::{entity::*, query::*, tests_cfg::cake};
let mut cake_stream = cake::Entity::find()
.order_by_asc(cake::Column::Id)
.paginate(db, 50)
.into_stream();
while let Some(cakes) = cake_stream.try_next().await? {
// Do something on cakes: Vec<cake::Model>
}
Trait Implementations
sourceimpl<'db, C: Clone, S: Clone> Clone for Paginator<'db, C, S> where
C: ConnectionTrait,
S: SelectorTrait + 'db,
impl<'db, C: Clone, S: Clone> Clone for Paginator<'db, C, S> where
C: ConnectionTrait,
S: SelectorTrait + 'db,
Auto Trait Implementations
impl<'db, C, S> !RefUnwindSafe for Paginator<'db, C, S>
impl<'db, C, S> Send for Paginator<'db, C, S> where
S: Send,
impl<'db, C, S> Sync for Paginator<'db, C, S> where
S: Sync,
impl<'db, C, S> Unpin for Paginator<'db, C, S> where
S: Unpin,
impl<'db, C, S> !UnwindSafe for Paginator<'db, C, S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more