arangors/document/options.rs
1//! Types of options related to document
2use serde::{Deserialize, Serialize};
3use typed_builder::TypedBuilder;
4
5/// Options for document insertion.
6#[derive(Debug, Serialize, Deserialize, PartialEq, TypedBuilder, Clone)]
7#[builder(doc)]
8#[serde(rename_all = "camelCase")]
9pub struct InsertOptions {
10 /// Wait until document has been synced to disk.
11 #[serde(skip_serializing_if = "Option::is_none")]
12 #[builder(default, setter(strip_option))]
13 wait_for_sync: Option<bool>,
14 /// Additionally return the complete new document under the attribute new in
15 /// the result.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 #[builder(default, setter(strip_option))]
18 return_new: Option<bool>,
19 /// Additionally return the complete old document under the attribute old in
20 /// the result. Only available if the overwrite option is used.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 #[builder(default, setter(strip_option))]
23 return_old: Option<bool>,
24 /// If set to true, an empty object will be returned as response.
25 /// No meta-data will be returned for the created document.
26 /// This option can be used to save some network traffic.
27 #[serde(skip_serializing_if = "Option::is_none")]
28 #[builder(default, setter(strip_option))]
29 silent: Option<bool>,
30 /// If set to true, the insert becomes a replace-insert.
31 /// If a document with the same _key already exists the new document is not
32 /// rejected with unique constraint violated but will replace the old
33 /// document.
34 #[serde(skip_serializing_if = "Option::is_none")]
35 #[builder(default, setter(strip_option))]
36 overwrite: Option<bool>,
37 /// TODO add nice formatted documentation from official doc
38 #[cfg(feature = "arango3_7")]
39 #[serde(skip_serializing_if = "Option::is_none")]
40 #[builder(default, setter(strip_option))]
41 overwrite_mode: Option<OverwriteMode>,
42
43 /// If the intention is to delete existing attributes with the update-insert
44 /// command, the URL query parameter keepNull can be used with a value
45 /// of false. This will modify the behavior of the patch command to
46 /// remove any attributes from the existing document that are contained
47 /// in the patch document with an attribute value of null. This option
48 /// controls the update-insert behavior only.
49 #[cfg(feature = "arango3_7")]
50 #[serde(skip_serializing_if = "Option::is_none")]
51 #[builder(default, setter(strip_option))]
52 keep_null: Option<bool>,
53
54 /// Controls whether objects (not arrays) will be merged if present in both
55 /// the existing and the update-insert document.
56 /// If set to false, the value in the patch document will overwrite the
57 /// existing document’s value. If set to true, objects will be merged.
58 /// The default is true. This option controls the update-insert behavior
59 /// only.
60 #[cfg(feature = "arango3_7")]
61 #[serde(skip_serializing_if = "Option::is_none")]
62 #[builder(default, setter(strip_option))]
63 merge_objects: Option<bool>,
64}
65
66impl Default for InsertOptions {
67 fn default() -> Self {
68 Self::builder().build()
69 }
70}
71
72/// Options for document update,
73#[derive(Debug, Serialize, Deserialize, PartialEq, TypedBuilder, Clone)]
74#[builder(doc)]
75#[serde(rename_all = "camelCase")]
76pub struct UpdateOptions {
77 /// If the intention is to delete existing attributes with the patch
78 /// command, the URL query parameter keepNull can be used with a value of
79 /// false. This will modify the behavior of the patch command to remove any
80 /// attributes from the existing document that are contained in the patch
81 /// document with an attribute value of null.
82 #[serde(skip_serializing_if = "Option::is_none")]
83 #[builder(default, setter(strip_option))]
84 keep_null: Option<bool>,
85 /// Controls whether objects (not arrays) will be merged if present in both
86 /// the existing and the patch document. If set to false, the value in the
87 /// patch document will overwrite the existing document’s value. If set to
88 /// true, objects will be merged. The default is true.
89 #[serde(skip_serializing_if = "Option::is_none")]
90 #[builder(default, setter(strip_option))]
91 merge_objects: Option<bool>,
92 /// Wait until document has been synced to disk.
93 #[serde(skip_serializing_if = "Option::is_none")]
94 #[builder(default, setter(strip_option))]
95 wait_for_sync: Option<bool>,
96 /// By default, or if this is set to true, the _rev attributes in the given
97 /// document is ignored. If this is set to false, then the _rev
98 /// attribute given in the body document is taken as a precondition. The
99 /// document is only update if the current revision is the one specified.
100 #[serde(skip_serializing_if = "Option::is_none")]
101 #[builder(default, setter(strip_option))]
102 ignore_revs: Option<bool>,
103 /// Additionally return the complete new document under the attribute new in
104 /// the result.
105 #[serde(skip_serializing_if = "Option::is_none")]
106 #[builder(default, setter(strip_option))]
107 return_new: Option<bool>,
108 /// Return additionally the complete previous revision of the changed
109 /// document under the attribute old in the result.
110 #[serde(skip_serializing_if = "Option::is_none")]
111 #[builder(default, setter(strip_option))]
112 return_old: Option<bool>,
113 /// If set to true, an empty object will be returned as response.
114 /// No meta-data will be returned for the updated document.
115 /// This option can be used to save some network traffic.
116 #[serde(skip_serializing_if = "Option::is_none")]
117 #[builder(default, setter(strip_option))]
118 silent: Option<bool>,
119}
120
121impl Default for UpdateOptions {
122 fn default() -> Self {
123 Self::builder().build()
124 }
125}
126
127#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
128#[serde(rename_all = "camelCase")]
129pub enum OverwriteMode {
130 /// If a document with the specified _key value exists already,
131 /// nothing will be done and no write operation will be carried out.
132 /// The insert operation will return success in this case.
133 /// This mode does not support returning the old document version using
134 /// RETURN OLD. When using RETURN NEW, null will be returned in case the
135 /// document already existed.
136 Ignore,
137 /// If a document with the specified _key value exists already, it will be
138 /// overwritten with the specified document value. This mode will also
139 /// be used when no overwrite mode is specified but the overwrite flag is
140 /// set to true.
141 Replace,
142 /// If a document with the specified _key value exists already, it will be
143 /// patched (partially updated) with the specified document value.
144 /// The overwrite mode can be further controlled via the keepNull and
145 /// mergeObjects parameters
146 Update,
147 /// if a document with the specified _key value exists already, return a
148 /// unique constraint violation error so that the insert operation fails.
149 /// This is also the default behavior in case the overwrite mode is not set,
150 /// and the overwrite flag is false or not set either.
151 ///
152 /// keepNull (optional): If the intention is to delete existing attributes
153 /// with the update-insert command, the URL query parameter keepNull can be
154 /// used with a value of false. This will modify the behavior of the patch
155 /// command to remove any attributes from the existing document that are
156 /// contained in the patch document with an attribute value of null.
157 /// This option controls the update-insert behavior only.
158 ///
159 /// mergeObjects (optional): Controls whether objects (not arrays) will be
160 /// merged if present in both the existing and the update-insert document.
161 /// If set to false, the value in the patch document will overwrite the
162 /// existing document’s value. If set to true, objects will be merged. The
163 /// default is true. This option controls the update-insert behavior only.
164 /// TODO need to implement the two extra modes keepNull & mergeObjects
165 Conflict,
166}
167
168/// Options for document replace,
169#[derive(Debug, Serialize, Deserialize, TypedBuilder, Clone)]
170#[builder(doc)]
171#[serde(rename_all = "camelCase")]
172pub struct ReplaceOptions {
173 /// Wait until document has been synced to disk.
174 #[serde(skip_serializing_if = "Option::is_none")]
175 #[builder(default, setter(strip_option))]
176 wait_for_sync: Option<bool>,
177 /// By default, or if this is set to true, the _rev attributes in the given
178 /// document is ignored. If this is set to false, then the _rev
179 /// attribute given in the body document is taken as a precondition. The
180 /// document is only replaced if the current revision is the one specified.
181 #[serde(skip_serializing_if = "Option::is_none")]
182 #[builder(default, setter(strip_option))]
183 ignore_revs: Option<bool>,
184 /// Additionally return the complete new document under the attribute new in
185 /// the result.
186 #[serde(skip_serializing_if = "Option::is_none")]
187 #[builder(default, setter(strip_option))]
188 return_new: Option<bool>,
189 /// Additionally return the complete old document under the attribute old in
190 /// the result.
191 #[serde(skip_serializing_if = "Option::is_none")]
192 #[builder(default, setter(strip_option))]
193 return_old: Option<bool>,
194 /// If set to true, an empty object will be returned as response.
195 /// No meta-data will be returned for the replaced document.
196 /// This option can be used to save some network traffic.
197 #[serde(skip_serializing_if = "Option::is_none")]
198 #[builder(default, setter(strip_option))]
199 silent: Option<bool>,
200}
201
202impl Default for ReplaceOptions {
203 fn default() -> Self {
204 Self::builder().build()
205 }
206}
207
208/// Options for document reading.
209#[derive(Debug, Serialize, Deserialize, Clone)]
210#[serde(rename_all = "camelCase")]
211pub enum ReadOptions {
212 /// If the “If-None-Match” header is given, then it must contain exactly one
213 /// Etag. The document is returned, if it has a different revision than
214 /// the given Etag. Otherwise an HTTP 304 is returned.
215 IfNoneMatch(String),
216 /// If the “If-Match” header is given, then it must contain exactly one
217 /// Etag. The document is returned, if it has the same revision as the
218 /// given Etag. Otherwise a HTTP 412 is returned.
219 IfMatch(String),
220 NoHeader,
221}
222
223impl Default for ReadOptions {
224 fn default() -> Self {
225 Self::NoHeader
226 }
227}
228
229/// Options for document removes,
230#[derive(Debug, Serialize, Deserialize, TypedBuilder, Clone)]
231#[builder(doc)]
232#[serde(rename_all = "camelCase")]
233pub struct RemoveOptions {
234 /// Wait until document has been synced to disk.
235 #[serde(skip_serializing_if = "Option::is_none")]
236 #[builder(default, setter(strip_option))]
237 wait_for_sync: Option<bool>,
238 /// Additionally return the complete old document under the attribute old in
239 /// the result.
240 #[serde(skip_serializing_if = "Option::is_none")]
241 #[builder(default, setter(strip_option))]
242 return_old: Option<bool>,
243 /// If set to true, an empty object will be returned as response.
244 /// No meta-data will be returned for the created document.
245 /// This option can be used to save some network traffic.
246 #[serde(skip_serializing_if = "Option::is_none")]
247 #[builder(default, setter(strip_option))]
248 silent: Option<bool>,
249}
250
251impl Default for RemoveOptions {
252 fn default() -> Self {
253 Self::builder().build()
254 }
255}