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ยง
Sourceยงimpl<'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: u64) -> Result<Vec<S::Item>, DbErr>
pub async fn fetch_page(&self, page: u64) -> 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ยง
Auto Trait Implementationsยง
impl<'db, C, S> Freeze for Paginator<'db, C, S>
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ยง
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงunsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
๐ฌThis is a nightly-only experimental API. (
clone_to_uninit
)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