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

Function cursor_pagination

tests/cursor_tests.rs:54–512  ·  view source on GitHub ↗
(db: &DatabaseConnection)

Source from the content-addressed store, hash-verified

52}
53
54pub async fn cursor_pagination(db: &DatabaseConnection) -> Result<(), DbErr> {
55 use insert_default::*;
56
57 // Before 5, i.e. id < 5
58
59 let mut cursor = Entity::find().cursor_by(Column::Id);
60
61 cursor.before(5);
62
63 assert_eq!(
64 cursor.first(4).all(db).await?,
65 [
66 Model { id: 1 },
67 Model { id: 2 },
68 Model { id: 3 },
69 Model { id: 4 },
70 ]
71 );
72
73 assert_eq!(
74 cursor.first(5).all(db).await?,
75 [
76 Model { id: 1 },
77 Model { id: 2 },
78 Model { id: 3 },
79 Model { id: 4 },
80 ]
81 );
82
83 assert_eq!(
84 cursor.last(4).all(db).await?,
85 [
86 Model { id: 1 },
87 Model { id: 2 },
88 Model { id: 3 },
89 Model { id: 4 },
90 ]
91 );
92
93 assert_eq!(
94 cursor.last(5).all(db).await?,
95 [
96 Model { id: 1 },
97 Model { id: 2 },
98 Model { id: 3 },
99 Model { id: 4 },
100 ]
101 );
102
103 // Before 5 DESC, i.e. id > 5
104
105 let mut cursor = Entity::find().cursor_by(Column::Id);
106
107 cursor.before(5).desc();
108
109 assert_eq!(
110 cursor.first(4).all(db).await?,
111 [

Callers 1

cursor_testsFunction · 0.85

Calls 6

cursor_byMethod · 0.80
beforeMethod · 0.80
descMethod · 0.80
afterMethod · 0.80
firstMethod · 0.80
into_jsonMethod · 0.45

Tested by

no test coverage detected