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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
//! Types of options related to document
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
/// Options for document insertion.
#[derive(Debug, Serialize, Deserialize, PartialEq, TypedBuilder, Clone)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct InsertOptions {
/// Wait until document has been synced to disk.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
wait_for_sync: Option<bool>,
/// Additionally return the complete new document under the attribute new in
/// the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_new: Option<bool>,
/// Additionally return the complete old document under the attribute old in
/// the result. Only available if the overwrite option is used.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_old: Option<bool>,
/// If set to true, an empty object will be returned as response.
/// No meta-data will be returned for the created document.
/// This option can be used to save some network traffic.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
silent: Option<bool>,
/// If set to true, the insert becomes a replace-insert.
/// If a document with the same _key already exists the new document is not
/// rejected with unique constraint violated but will replace the old
/// document.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
overwrite: Option<bool>,
/// TODO add nice formatted documentation from official doc
#[cfg(feature = "arango3_7")]
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
overwrite_mode: Option<OverwriteMode>,
/// If the intention is to delete existing attributes with the update-insert
/// command, the URL query parameter keepNull can be used with a value
/// of false. This will modify the behavior of the patch command to
/// remove any attributes from the existing document that are contained
/// in the patch document with an attribute value of null. This option
/// controls the update-insert behavior only.
#[cfg(feature = "arango3_7")]
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
keep_null: Option<bool>,
/// Controls whether objects (not arrays) will be merged if present in both
/// the existing and the update-insert document.
/// If set to false, the value in the patch document will overwrite the
/// existing document’s value. If set to true, objects will be merged.
/// The default is true. This option controls the update-insert behavior
/// only.
#[cfg(feature = "arango3_7")]
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
merge_objects: Option<bool>,
}
impl Default for InsertOptions {
fn default() -> Self {
Self::builder().build()
}
}
/// Options for document update,
#[derive(Debug, Serialize, Deserialize, PartialEq, TypedBuilder, Clone)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct UpdateOptions {
/// If the intention is to delete existing attributes with the patch
/// command, the URL query parameter keepNull can be used with a value of
/// false. This will modify the behavior of the patch command to remove any
/// attributes from the existing document that are contained in the patch
/// document with an attribute value of null.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
keep_null: Option<bool>,
/// Controls whether objects (not arrays) will be merged if present in both
/// the existing and the patch document. If set to false, the value in the
/// patch document will overwrite the existing document’s value. If set to
/// true, objects will be merged. The default is true.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
merge_objects: Option<bool>,
/// Wait until document has been synced to disk.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
wait_for_sync: Option<bool>,
/// By default, or if this is set to true, the _rev attributes in the given
/// document is ignored. If this is set to false, then the _rev
/// attribute given in the body document is taken as a precondition. The
/// document is only update if the current revision is the one specified.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
ignore_revs: Option<bool>,
/// Additionally return the complete new document under the attribute new in
/// the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_new: Option<bool>,
/// Return additionally the complete previous revision of the changed
/// document under the attribute old in the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_old: Option<bool>,
/// If set to true, an empty object will be returned as response.
/// No meta-data will be returned for the updated document.
/// This option can be used to save some network traffic.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
silent: Option<bool>,
}
impl Default for UpdateOptions {
fn default() -> Self {
Self::builder().build()
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub enum OverwriteMode {
/// If a document with the specified _key value exists already,
/// nothing will be done and no write operation will be carried out.
/// The insert operation will return success in this case.
/// This mode does not support returning the old document version using
/// RETURN OLD. When using RETURN NEW, null will be returned in case the
/// document already existed.
Ignore,
/// If a document with the specified _key value exists already, it will be
/// overwritten with the specified document value. This mode will also
/// be used when no overwrite mode is specified but the overwrite flag is
/// set to true.
Replace,
/// If a document with the specified _key value exists already, it will be
/// patched (partially updated) with the specified document value.
/// The overwrite mode can be further controlled via the keepNull and
/// mergeObjects parameters
Update,
/// if a document with the specified _key value exists already, return a
/// unique constraint violation error so that the insert operation fails.
/// This is also the default behavior in case the overwrite mode is not set,
/// and the overwrite flag is false or not set either.
///
/// keepNull (optional): If the intention is to delete existing attributes
/// with the update-insert command, the URL query parameter keepNull can be
/// used with a value of false. This will modify the behavior of the patch
/// command to remove any attributes from the existing document that are
/// contained in the patch document with an attribute value of null.
/// This option controls the update-insert behavior only.
///
/// mergeObjects (optional): Controls whether objects (not arrays) will be
/// merged if present in both the existing and the update-insert document.
/// If set to false, the value in the patch document will overwrite the
/// existing document’s value. If set to true, objects will be merged. The
/// default is true. This option controls the update-insert behavior only.
/// TODO need to implement the two extra modes keepNull & mergeObjects
Conflict,
}
/// Options for document replace,
#[derive(Debug, Serialize, Deserialize, TypedBuilder, Clone)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct ReplaceOptions {
/// Wait until document has been synced to disk.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
wait_for_sync: Option<bool>,
/// By default, or if this is set to true, the _rev attributes in the given
/// document is ignored. If this is set to false, then the _rev
/// attribute given in the body document is taken as a precondition. The
/// document is only replaced if the current revision is the one specified.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
ignore_revs: Option<bool>,
/// Additionally return the complete new document under the attribute new in
/// the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_new: Option<bool>,
/// Additionally return the complete old document under the attribute old in
/// the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_old: Option<bool>,
/// If set to true, an empty object will be returned as response.
/// No meta-data will be returned for the replaced document.
/// This option can be used to save some network traffic.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
silent: Option<bool>,
}
impl Default for ReplaceOptions {
fn default() -> Self {
Self::builder().build()
}
}
/// Options for document reading.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum ReadOptions {
/// If the “If-None-Match” header is given, then it must contain exactly one
/// Etag. The document is returned, if it has a different revision than
/// the given Etag. Otherwise an HTTP 304 is returned.
IfNoneMatch(String),
/// If the “If-Match” header is given, then it must contain exactly one
/// Etag. The document is returned, if it has the same revision as the
/// given Etag. Otherwise a HTTP 412 is returned.
IfMatch(String),
NoHeader,
}
impl Default for ReadOptions {
fn default() -> Self {
Self::NoHeader
}
}
/// Options for document removes,
#[derive(Debug, Serialize, Deserialize, TypedBuilder, Clone)]
#[builder(doc)]
#[serde(rename_all = "camelCase")]
pub struct RemoveOptions {
/// Wait until document has been synced to disk.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
wait_for_sync: Option<bool>,
/// Additionally return the complete old document under the attribute old in
/// the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
return_old: Option<bool>,
/// If set to true, an empty object will be returned as response.
/// No meta-data will be returned for the created document.
/// This option can be used to save some network traffic.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
silent: Option<bool>,
}
impl Default for RemoveOptions {
fn default() -> Self {
Self::builder().build()
}
}