pub struct CursorPagination {
pub cursor: Option<String>,
pub limit: u32,
pub include_cursor: bool,
pub has_next: bool,
pub has_prev: bool,
pub next_cursor: Option<String>,
pub prev_cursor: Option<String>,
pub total: Option<u64>,
}
Expand description
Cursor-based pagination for better performance with large datasets
Cursor-based pagination uses a cursor (typically a timestamp or ID) to mark the position in the dataset, providing consistent results even when data is being added or removed during pagination.
§Advantages
- Consistent results: No duplicate or missing items when data changes
- Better performance: No need to count total items or skip large offsets
- Real-time friendly: Works well with live data streams
§Examples
use libsql_orm::CursorPagination;
// First page
let pagination = CursorPagination::new(10);
// Subsequent pages using cursor from previous result
let next_pagination = CursorPagination::with_cursor(10, Some("cursor_value".to_string()));
Fields§
§cursor: Option<String>
Cursor for the next page
limit: u32
Number of items per page
include_cursor: bool
Whether to include the cursor item in results
has_next: bool
Whether there are more items
has_prev: bool
Whether there are previous items
next_cursor: Option<String>
Cursor for the next page
prev_cursor: Option<String>
Cursor for the previous page
total: Option<u64>
Total number of items
Implementations§
Source§impl CursorPagination
impl CursorPagination
Sourcepub fn with_cursor(limit: u32, cursor: Option<String>) -> Self
pub fn with_cursor(limit: u32, cursor: Option<String>) -> Self
Create with a specific cursor
Sourcepub fn with_cursor_old(cursor: String, limit: u32) -> Self
pub fn with_cursor_old(cursor: String, limit: u32) -> Self
Create with a specific cursor (deprecated, use with_cursor(limit, cursor) instead)
Sourcepub fn set_cursor(&mut self, cursor: Option<String>)
pub fn set_cursor(&mut self, cursor: Option<String>)
Set the cursor
Trait Implementations§
Source§impl Clone for CursorPagination
impl Clone for CursorPagination
Source§fn clone(&self) -> CursorPagination
fn clone(&self) -> CursorPagination
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CursorPagination
impl Debug for CursorPagination
Source§impl Default for CursorPagination
impl Default for CursorPagination
Source§impl<'de> Deserialize<'de> for CursorPagination
impl<'de> Deserialize<'de> for CursorPagination
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for CursorPagination
impl RefUnwindSafe for CursorPagination
impl Send for CursorPagination
impl Sync for CursorPagination
impl Unpin for CursorPagination
impl UnwindSafe for CursorPagination
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more