MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / find_posts_in_page

Method find_posts_in_page

examples/tonic_example/service/src/query.rs:12–25  ·  view source on GitHub ↗

If ok, returns (post models, num pages).

(
        db: &DbConn,
        page: u64,
        posts_per_page: u64,
    )

Source from the content-addressed store, hash-verified

10
11 /// If ok, returns (post models, num pages).
12 pub async fn find_posts_in_page(
13 db: &DbConn,
14 page: u64,
15 posts_per_page: u64,
16 ) -> Result<(Vec<post::Model>, u64), DbErr> {
17 // Setup paginator
18 let paginator = Post::find()
19 .order_by_asc(post::Column::Id)
20 .paginate(db, posts_per_page);
21 let num_pages = paginator.num_pages().await?;
22
23 // Fetch paginated posts
24 paginator.fetch_page(page - 1).await.map(|p| (p, num_pages))
25 }
26}

Callers

nothing calls this directly

Calls 4

paginateMethod · 0.80
order_by_ascMethod · 0.80
num_pagesMethod · 0.80
fetch_pageMethod · 0.80

Tested by

no test coverage detected