1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! A module for paginating Charybdis model streams.
//!
//! This module provides the `PagableCharybdisStream` struct, which allows for
//! efficient pagination of items retrieved from a Charybdis model stream. It
//! encapsulates the logic for managing the current state of the stream, including
//! fetching the next set of items and skipping pages as needed.
//!
//! The `Pagable` trait is implemented for `PagableCharybdisStream`, enabling
//! asynchronous operations to retrieve and manage paginated data. This module
//! is particularly useful for applications that require handling large datasets
//! in a memory-efficient manner, allowing users to process items in manageable
//! chunks.
//!
//! # Examples
//!
//! ```rust,no_run
//! use grapple_db::scylla::{model::Model, stream::CharybdisModelStream};
//! use grapple_db::scylla::stream::PagableCharybdisStream;
//! use grapple_db::Pagable;
//! use grapple_db::scylla::Client;
//! use grapple_db::scylla::operations::Find;
//!
//! // Assuming you have a `User` model defined with `Charybdis`
//! # #[grapple_db::scylla::macros::charybdis_model(
//! # table_name = users,
//! # partition_keys = [id],
//! # clustering_keys = [],
//! # )]
//! # #[derive(Debug, Default)]
//! # struct User {
//! # id: String,
//! # }
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::default().await?;
//!
//! // Initialize a Charybdis model stream
//! let stream = client.stream(User::find_all()).await?;
//!
//! // Create a paginated stream with 10 items per page
//! let mut paginated_stream = PagableCharybdisStream::new(stream, 10);
//!
//! // Fetch and process items page by page
//! while let Some(items) = paginated_stream.next_page().await {
//! for item in items {
//! // Process each item
//! }
//! }
//!
//! Ok(())
//! # }
//! ```
use Model;
use async_trait;
use StreamExt;
pub use *;
use cratePagable;
/// A paginated stream for Charybdis models.
///
/// This struct provides a way to paginate through a stream of Charybdis models,
/// allowing users to retrieve a specified number of items per page. It manages
/// the internal state of the stream and provides methods to fetch the next page
/// or skip pages as needed.
///
/// # Fields
///
/// - `stream`: The underlying Charybdis model stream from which items are fetched.
/// - `per_page`: The number of items to retrieve per page.
/// - `page_items`: A vector that holds the items of the current page.
///
/// # Examples
///
/// ```rust,no_run
/// use grapple_db::scylla::{model::Model, stream::CharybdisModelStream};
/// use grapple_db::scylla::stream::PagableCharybdisStream;
/// use grapple_db::Pagable;
/// # use grapple_db::scylla::Client;
/// # use grapple_db::scylla::macros::charybdis_model;
/// # use grapple_db::scylla::operations::Find;
///
/// // Assuming you have a User model defined
/// # #[charybdis_model(
/// # table_name = users,
/// # partition_keys = [id],
/// # clustering_keys = [],
/// # )]
/// # #[derive(Debug, Default)]
/// # struct User {
/// # id: String
/// # }
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
///
/// let client = Client::default().await?;
///
/// // Creating a new paginated stream with a specified number of items per page
/// // Initialize stream from client
/// let stream = client.stream(User::find_all()).await?;
/// let mut paginated_stream = PagableCharybdisStream::new(stream, 10);
///
/// // Fetching the next page of items
/// if let Some(items) = paginated_stream.next_page().await {
/// for item in items {
/// // Process each item
/// }
/// }
///
/// # Ok(())
///
/// # }
/// ```