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

Function find_all_stream

examples/basic/src/select.rs:292–338  ·  view source on GitHub ↗
(db: &DbConn)

Source from the content-addressed store, hash-verified

290}
291
292async fn find_all_stream(db: &DbConn) -> Result<(), DbErr> {
293 use async_std::task::sleep;
294 use futures::TryStreamExt;
295 use std::time::Duration;
296
297 println!("find all cakes paginated: ");
298 let mut cake_paginator = cake::Entity::find().paginate(db, 3);
299 while let Some(cake_res) = cake_paginator.fetch_and_next().await? {
300 for cake in cake_res {
301 println!("{cake:?}");
302 }
303 }
304
305 println!();
306 println!("find all fruits paginated: ");
307 let mut fruit_paginator = fruit::Entity::find().paginate(db, 3);
308 while let Some(fruit_res) = fruit_paginator.fetch_and_next().await? {
309 for fruit in fruit_res {
310 println!("{fruit:?}");
311 }
312 }
313
314 println!();
315 println!("find all fruits with stream: ");
316 let mut fruit_stream = fruit::Entity::find().paginate(db, 3).into_stream();
317 while let Some(fruits) = fruit_stream.try_next().await? {
318 for fruit in fruits {
319 println!("{fruit:?}");
320 }
321 sleep(Duration::from_millis(250)).await;
322 }
323
324 println!();
325 println!("find all fruits in json with stream: ");
326 let mut json_stream = fruit::Entity::find()
327 .into_json()
328 .paginate(db, 3)
329 .into_stream();
330 while let Some(jsons) = json_stream.try_next().await? {
331 for json in jsons {
332 println!("{json:?}");
333 }
334 sleep(Duration::from_millis(250)).await;
335 }
336
337 Ok(())
338}
339
340async fn find_first_page(db: &DbConn) -> Result<(), DbErr> {
341 println!("fruits first page: ");

Callers 1

all_about_selectFunction · 0.85

Calls 4

paginateMethod · 0.80
fetch_and_nextMethod · 0.80
into_streamMethod · 0.80
into_jsonMethod · 0.45

Tested by

no test coverage detected