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