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§
source§impl<'db, C, S> Clone for Paginator<'db, C, S>where
C: ConnectionTrait + Clone,
S: SelectorTrait + 'db + Clone,
impl<'db, C, S> Clone for Paginator<'db, C, S>where C: ConnectionTrait + Clone, S: SelectorTrait + 'db + Clone,
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§
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