|
5 | 5 |
|
6 | 6 | use serde::{Deserialize, Serialize}; |
7 | 7 | use serde_json::Value; |
| 8 | +use typed_builder::TypedBuilder; |
8 | 9 |
|
9 | 10 | /// Represents a Redis Cloud database instance |
10 | 11 | /// |
@@ -92,46 +93,71 @@ pub struct ThroughputMeasurement { |
92 | 93 | /// |
93 | 94 | /// ```rust,no_run |
94 | 95 | /// use redis_cloud::CreateDatabaseRequest; |
95 | | -/// use serde_json::json; |
96 | 96 | /// |
97 | | -/// let request = json!({ |
98 | | -/// "name": "production-cache", |
99 | | -/// "memory_limit_in_gb": 5.0, |
100 | | -/// "data_persistence": "aof-every-1-sec", |
101 | | -/// "replication": true, |
102 | | -/// "password": "secure-password-123", |
103 | | -/// "support_oss_cluster_api": false |
104 | | -/// }); |
| 97 | +/// let request = CreateDatabaseRequest::builder() |
| 98 | +/// .name("production-cache") |
| 99 | +/// .memory_limit_in_gb(5.0) |
| 100 | +/// .data_persistence("aof-every-1-sec") |
| 101 | +/// .replication(true) |
| 102 | +/// .password("secure-password-123") |
| 103 | +/// .support_oss_cluster_api(false) |
| 104 | +/// .build(); |
105 | 105 | /// ``` |
106 | | -#[derive(Debug, Serialize)] |
| 106 | +#[derive(Debug, Serialize, TypedBuilder)] |
107 | 107 | pub struct CreateDatabaseRequest { |
| 108 | + #[builder(setter(into))] |
108 | 109 | pub name: String, |
109 | 110 | pub memory_limit_in_gb: f64, |
| 111 | + #[builder(setter(into))] |
110 | 112 | pub data_persistence: String, |
| 113 | + #[builder(default)] |
111 | 114 | pub replication: bool, |
112 | 115 | #[serde(skip_serializing_if = "Option::is_none")] |
| 116 | + #[builder(default, setter(into, strip_option))] |
113 | 117 | pub data_eviction: Option<String>, |
114 | 118 | #[serde(skip_serializing_if = "Option::is_none")] |
| 119 | + #[builder(default, setter(into, strip_option))] |
115 | 120 | pub password: Option<String>, |
116 | 121 | #[serde(skip_serializing_if = "Option::is_none")] |
| 122 | + #[builder(default, setter(strip_option))] |
117 | 123 | pub support_oss_cluster_api: Option<bool>, |
118 | 124 | #[serde(skip_serializing_if = "Option::is_none")] |
| 125 | + #[builder(default, setter(strip_option))] |
119 | 126 | pub use_external_endpoint_for_oss_cluster_api: Option<bool>, |
120 | 127 | } |
121 | 128 |
|
122 | 129 | /// Update database request |
123 | | -#[derive(Debug, Serialize)] |
| 130 | +/// |
| 131 | +/// All fields are optional - only provide the fields you want to update. |
| 132 | +/// |
| 133 | +/// # Examples |
| 134 | +/// |
| 135 | +/// ```rust,no_run |
| 136 | +/// use redis_cloud::UpdateDatabaseRequest; |
| 137 | +/// |
| 138 | +/// let request = UpdateDatabaseRequest::builder() |
| 139 | +/// .memory_limit_in_gb(10.0) |
| 140 | +/// .replication(true) |
| 141 | +/// .build(); |
| 142 | +/// ``` |
| 143 | +#[derive(Debug, Serialize, TypedBuilder)] |
124 | 144 | pub struct UpdateDatabaseRequest { |
125 | 145 | #[serde(skip_serializing_if = "Option::is_none")] |
| 146 | + #[builder(default, setter(into, strip_option))] |
126 | 147 | pub name: Option<String>, |
127 | 148 | #[serde(skip_serializing_if = "Option::is_none")] |
| 149 | + #[builder(default, setter(strip_option))] |
128 | 150 | pub memory_limit_in_gb: Option<f64>, |
129 | 151 | #[serde(skip_serializing_if = "Option::is_none")] |
| 152 | + #[builder(default, setter(into, strip_option))] |
130 | 153 | pub data_persistence: Option<String>, |
131 | 154 | #[serde(skip_serializing_if = "Option::is_none")] |
| 155 | + #[builder(default, setter(strip_option))] |
132 | 156 | pub replication: Option<bool>, |
133 | 157 | #[serde(skip_serializing_if = "Option::is_none")] |
| 158 | + #[builder(default, setter(into, strip_option))] |
134 | 159 | pub data_eviction: Option<String>, |
135 | 160 | #[serde(skip_serializing_if = "Option::is_none")] |
| 161 | + #[builder(default, setter(into, strip_option))] |
136 | 162 | pub password: Option<String>, |
137 | 163 | } |
0 commit comments