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
use super::CollectionMandatory;
use serde::{Deserialize, Serialize};
use serde_json::value::Value;
use std::collections::BTreeMap;

#[derive(Debug, Default, Serialize, PartialEq)]
pub struct ArangoQuery {
    pub(crate) query: String,

    #[serde(skip_serializing_if = "BTreeMap::is_empty", rename = "bindVars")]
    pub(crate) bind_vars: BTreeMap<String, Value>,

    #[serde(skip_serializing_if = "Option::is_none", rename = "batchSize")]
    pub(crate) batch_size: Option<usize>,
}

#[derive(Debug)]
pub struct CursorExtractor(pub String);

pub trait ExecuteArangoQuery {
    type Output;

    fn execute_query(&self, query: ArangoQuery) -> Self::Output;
}

// pub trait ExecuteArangoQueryFut {
//     fn execute_query<T>(&self, query: ArangoQuery) -> Box<Future<Item = ArangoResponse<T>, Error = Error> + Send>;
// }

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum CollectionType {
    Document = 2,
    Edge = 3,
}
impl Default for CollectionType {
    fn default() -> Self {
        CollectionType::Document
    }
}

#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)]
pub struct Collection {
    #[serde(rename = "type", default)]
    pub(crate) collection_type: CollectionType,

    pub id: String,
    pub name: String,
    pub status: u8,
    #[serde(rename = "isSystem", default)]
    pub is_system: bool,
    #[serde(rename = "globallyUniqueId", default)]
    pub globally_unique_id: String,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)]
pub struct Edge {
    pub(crate) _from: String,
    pub(crate) _to: String,

    #[serde(flatten)]
    pub(crate) mandatory: CollectionMandatory,
}

impl Edge {
    /// ```ignore
    /// let e = Edge::new("users/1234", "orders/5678");
    /// ```
    #[must_use]
    pub fn new(_from: &str, _to: &str) -> Self {
        Self { _from: _from.to_owned(), _to: _to.to_owned(), ..Self::default() }
    }
}

// Create

pub trait Insert {
    fn insert<Elem: Serialize>(&self, elem: &Elem) -> ArangoQuery;
}

// Read

pub trait GetAll {
    fn get_all(&self) -> ArangoQuery;
}

pub trait GetByKey {
    fn get_by_key<Key: Serialize>(&self, key: Key) -> ArangoQuery;
}

pub trait GetByKeys {
    fn get_by_keys<Key: Serialize>(&self, keys: &[Key]) -> ArangoQuery;
}

// Update

pub trait Replace {
    fn replace<Key: Serialize, Elem: Serialize>(&self, key: Key, elem: Elem) -> ArangoQuery;
    fn replace_with_id<Key: Serialize, Replace: Serialize>(
        &self,
        key: Key,
        replace: Replace,
    ) -> ArangoQuery;
}

pub trait Update {
    fn update<Key: Serialize, Update: Serialize>(&self, key: Key, update: Update) -> ArangoQuery;
    fn update_with_id<Key: Serialize, Update: Serialize>(
        &self,
        key: Key,
        update: Update,
    ) -> ArangoQuery;
}

// Delete

pub trait Remove {
    fn remove<Key: Serialize>(&self, key: Key) -> ArangoQuery;
    fn remove_with_id<Id: Serialize>(&self, id: Id) -> ArangoQuery;
}

pub trait Truncate {
    fn truncate(&self) -> ArangoQuery;
}

pub enum QueryType {
    Create,
    Read,
    Update,
    Delete,
}

pub enum SortingDirection {
    Asc,
    Desc,
}

pub trait BuilderTag {}

pub trait Buildable: BuilderTag {}

pub trait Conditionable: BuilderTag {}

pub trait LogicallyOperatable: BuilderTag {}

pub trait Filterable: BuilderTag {}

pub trait Limitable: BuilderTag {}

pub trait UpdateWith: BuilderTag {}

pub trait Sortable: BuilderTag {}

pub struct EmptyBuilder;

pub struct CreateQuery;

pub struct ReadQuery;

pub struct UpdateQuery;

pub struct DeleteQuery;

pub struct Conditional;

pub struct Filtering;

pub struct LogicalOperator;

pub struct UpdateField;

pub struct Sorting;

impl BuilderTag for EmptyBuilder {}

impl BuilderTag for CreateQuery {}

impl BuilderTag for ReadQuery {}

impl BuilderTag for UpdateQuery {}

impl BuilderTag for DeleteQuery {}

impl BuilderTag for Conditional {}

impl BuilderTag for Filtering {}

impl BuilderTag for LogicalOperator {}

impl BuilderTag for UpdateField {}

impl BuilderTag for Sorting {}

impl Buildable for ReadQuery {}

impl Buildable for DeleteQuery {}

impl Buildable for CreateQuery {}

impl Buildable for UpdateField {}

impl Buildable for Conditional {}

impl Buildable for Sorting {}

impl Conditionable for LogicalOperator {}

impl Conditionable for Filtering {}

impl Filterable for ReadQuery {}

impl Filterable for UpdateQuery {}

impl Filterable for DeleteQuery {}

impl Filterable for Conditional {}

impl Filterable for Sorting {}

impl Limitable for ReadQuery {}

impl Limitable for Conditional {}

impl Limitable for Sorting {}

impl LogicallyOperatable for Conditional {}

impl UpdateWith for Conditional {}

impl UpdateWith for UpdateQuery {}

impl Sortable for ReadQuery {}

impl Sortable for Filtering {}