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
//! A module for managing CRUD parameters in Charybdis operations.
//!
//! This module provides the `CrudParams` struct, which encapsulates the
//! configuration options for performing Create, Read, Update, and Delete
//! (CRUD) operations with Charybdis. It allows users to specify consistency
//! levels, timeouts, and timestamps for their operations, ensuring that
//! these settings are consistently applied across different database
//! interactions.
//!
//! The module includes methods to apply these parameters to both batch
//! operations and individual queries, facilitating a streamlined approach
//! to managing database interactions in a scalable manner.
//!
//! # Examples
//!
//! ```rust,no_run
//! use std::time::Duration;
//! use scylla::statement::Consistency;
//! use grapple_db::scylla::CrudParams;
//! use grapple_db::scylla::operations::Find;
//! use grapple_db::scylla::operations::ModelBatch;
//!
//! // 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,
//! # }
//!
//! // Creating CRUD parameters with specific settings
//! let params = CrudParams {
//! consistency: Consistency::Quorum,
//! timeout: Some(Duration::from_secs(5)),
//! timestamp: Some(1625078400),
//! };
//!
//! // Applying parameters to a batch operation
//! let batch = User::batch(); // Assume this initializes a batch
//! let configured_batch = params.apply_batch(batch);
//!
//! // Applying parameters to a query
//! let query = User::find_all(); // Assume this initializes a query
//! let configured_query = params.apply_query(query);
//! ```
use Model;
use ;
use ;
use ;
use Duration;
/// Parameters for CRUD operations in Charybdis.
///
/// This struct encapsulates the configuration options for performing CRUD
/// operations with Charybdis, including consistency levels, timeouts, and
/// timestamps. It provides methods to apply these parameters to batch
/// operations and queries, ensuring that the desired settings are used
/// consistently across different operations.
///
/// # Examples
///
/// ```rust,no_run
/// use std::time::Duration;
/// use scylla::statement::Consistency;
/// use grapple_db::scylla::CrudParams;
/// use grapple_db::scylla::operations::Find;
/// use grapple_db::scylla::operations::ModelBatch;
///
/// // 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,
/// # }
///
/// // Creating CRUD parameters with specific settings
/// let params = CrudParams {
/// consistency: Consistency::Quorum,
/// timeout: Some(Duration::from_secs(5)),
/// timestamp: Some(1625078400),
/// };
///
/// // Applying parameters to a batch operation
/// let batch = User::batch(); // Assume this initializes a batch
/// let configured_batch = params.apply_batch(batch);
///
/// // Applying parameters to a query
/// let query = User::find_all(); // Assume this initializes a query
/// let configured_query = params.apply_query(query);
/// ```
/// Converts a reference to `CrudParams` into an owned `CrudParams`.
///
/// This implementation allows for easy conversion from a reference to an
/// owned instance, enabling flexibility in how parameters are passed
/// around in the code.