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
#![allow(clippy::option_if_let_else)]
use arangors_lite::document::options::{InsertOptions, RemoveOptions, UpdateOptions};
#[derive(Clone, Debug)]
/// Struct defining some options for database `write` operations (create, update, delete)
pub struct OperationOptions {
/// Defines if aragog should wait for the operation to be written on disk
///
/// If set on `true` the requests might be slower. By default, the collection behavior is picked
pub wait_for_sync: Option<bool>,
/// Defines if aragog should ignore the `ArangoDB` document revision system (`_rev` field)
///
/// If set on `false` the requests might be slower. By default, `true` is used as it is the
/// default `ArangoDB` behaviour
pub ignore_revs: bool,
/// Defines if the operation should ignore [`Record`] hooks. By default set to `true`
///
/// [`Record`]: crate::Record
pub ignore_hooks: bool,
}
impl OperationOptions {
/// Sets the `wait_for_sync` value
#[inline]
#[must_use]
pub const fn wait_for_sync(mut self, value: bool) -> Self {
self.wait_for_sync = Some(value);
self
}
/// Sets the `ignore_revs` value
#[inline]
#[must_use]
pub const fn ignore_revs(mut self, value: bool) -> Self {
self.ignore_revs = value;
self
}
/// Sets the `ignore_hooks` value
#[inline]
#[must_use]
pub const fn ignore_hooks(mut self, value: bool) -> Self {
self.ignore_hooks = value;
self
}
}
impl Default for OperationOptions {
fn default() -> Self {
Self {
wait_for_sync: None, // We keep it at None to use the collection value
ignore_revs: true,
ignore_hooks: false,
}
}
}
impl From<OperationOptions> for InsertOptions {
fn from(option: OperationOptions) -> Self {
let builder = Self::builder()
.return_new(true) // TODO: allow customization on this option
.return_old(false)
.silent(false);
if let Some(value) = option.wait_for_sync {
builder.wait_for_sync(value).build()
} else {
builder.build()
}
}
}
impl From<OperationOptions> for UpdateOptions {
fn from(option: OperationOptions) -> Self {
let builder = Self::builder()
.keep_null(true)
.ignore_revs(option.ignore_revs)
.return_new(true) // TODO: allow customization on this option
.return_old(false)
.silent(false);
if let Some(value) = option.wait_for_sync {
builder.wait_for_sync(value).build()
} else {
builder.build()
}
}
}
impl From<OperationOptions> for RemoveOptions {
fn from(option: OperationOptions) -> Self {
let builder = Self::builder().return_old(false).silent(true); // On deletion we don't need meta data
if let Some(value) = option.wait_for_sync {
builder.wait_for_sync(value).build()
} else {
builder.build()
}
}
}