Skip to content

Commit cadd11c

Browse files
authored
feat: paginate without mapper (#17)
1 parent af0e6d3 commit cadd11c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ids_std_sea/src/paginator/mod.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@ use sea_orm::{ConnectionTrait, Paginator, SelectorTrait};
66

77
use crate::convert::into::IntoDomain;
88

9-
pub async fn fetch_page<C, S, O, F>(
9+
pub async fn fetch_page<C, S>(
10+
paginator: &Paginator<'_, C, S>,
11+
query: &PaginationQuery,
12+
) -> Result<Page<S>, SelectRepoFailure>
13+
where
14+
S: SelectorTrait<Item = S>,
15+
C: ConnectionTrait,
16+
{
17+
let page_info = paginator
18+
.num_items_and_pages()
19+
.await
20+
.map_err(|err| err.into_domain())?;
21+
22+
let model_items: Vec<<S as SelectorTrait>::Item> = paginator
23+
.fetch_page(query.page)
24+
.await
25+
.map_err(|err| err.into_domain())?;
26+
27+
Ok(Page {
28+
data: model_items,
29+
total: page_info.number_of_items,
30+
page: page_info.number_of_pages,
31+
page_size: query.page_size,
32+
})
33+
}
34+
35+
pub async fn fetch_page_mapper<C, S, O, F>(
1036
paginator: &Paginator<'_, C, S>,
1137
query: &PaginationQuery,
1238
mapper: F,

0 commit comments

Comments
 (0)