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
use crate::DbType;
use crate::QueryIds;
use crate::SelectAliasesQuery;
use crate::SelectEdgeCountQuery;
use crate::SelectKeyCountQuery;
use crate::SelectKeysQuery;
use crate::SelectValuesQuery;
use crate::db::db_value::DbValues;
use crate::query_builder::search::Search;
use crate::query_builder::select_aliases::SelectAliases;
use crate::query_builder::select_edge_count::SelectEdgeCount;
use crate::query_builder::select_ids::SelectIds;
use crate::query_builder::select_indexes::SelectIndexes;
use crate::query_builder::select_key_count::SelectKeyCount;
use crate::query_builder::select_keys::SelectKeys;
use crate::query_builder::select_node_count::SelectNodeCount;
use crate::query_builder::select_values::SelectValues;
/// Select builder that lets you choose what
/// data you want to select form the database.
#[cfg_attr(feature = "api", derive(agdb::TypeDef))]
pub struct Select {}
#[cfg_attr(feature = "api", agdb::impl_def())]
impl Select {
/// Select aliases. If no ids are given all aliases
/// in the database will be selected. Each element
/// of the result will have a property `String("alias")`
/// holding the alias. If `ids` are specified and any
/// of them does not have an alias an error will occur
/// when running such query.
pub fn aliases(self) -> SelectAliases {
SelectAliases(SelectAliasesQuery(QueryIds::Ids(vec![])))
}
/// Select number of outgoing and incoming edges. Each
/// element of the result withll have a proeprty `String("edge_count")`
/// with u64 as the value.
pub fn edge_count(self) -> SelectEdgeCount {
SelectEdgeCount(SelectEdgeCountQuery {
ids: QueryIds::Ids(vec![]),
from: true,
to: true,
})
}
/// Select number of outgoing edges. Each
/// element of the result withll have a proeprty `String("edge_count")`
/// with u64 as the value.
pub fn edge_count_from(self) -> SelectEdgeCount {
SelectEdgeCount(SelectEdgeCountQuery {
ids: QueryIds::Ids(vec![]),
from: true,
to: false,
})
}
/// Select number of incoming edges. Each
/// element of the result withll have a proeprty `String("edge_count")`
/// with u64 as the value.
pub fn edge_count_to(self) -> SelectEdgeCount {
SelectEdgeCount(SelectEdgeCountQuery {
ids: QueryIds::Ids(vec![]),
from: false,
to: true,
})
}
/// Select single element with `T::db_keys()`
/// properties (key-values) that also satisfies T::db_element_id()
/// if it returns `Some`.
pub fn element<T: DbType>(self) -> SelectValues {
SelectValues {
query: SelectValuesQuery {
keys: T::db_keys(),
ids: QueryIds::Ids(vec![]),
},
element_id: T::db_element_id(),
limit: 1,
}
}
/// Select elements with `T::db_keys()`
/// properties (key-values) that must exist on all
/// selected elements. If T::db_element_id()
/// returns `Some` this condition is automatically added
/// if used in search.
pub fn elements<T: DbType>(self) -> SelectValues {
SelectValues {
query: SelectValuesQuery {
keys: T::db_keys(),
ids: QueryIds::Ids(vec![]),
},
element_id: T::db_element_id(),
limit: 0,
}
}
/// Select elements with `ids` with all properties (key-values).
/// All ids specified must exist in the database.
pub fn ids<T: Into<QueryIds>>(self, ids: T) -> SelectIds {
SelectIds(SelectValuesQuery {
keys: vec![],
ids: ids.into(),
})
}
/// Select all indexes in the database. The returned result
/// will contain single element with each value representing
/// index name and number of indexed values in that index.
pub fn indexes(self) -> SelectIndexes {
SelectIndexes {}
}
/// Select keys only (values will be empty).
pub fn keys(self) -> SelectKeys {
SelectKeys(SelectKeysQuery(QueryIds::Ids(vec![])))
}
/// Select number of keys. Each element of the result will have
/// a property `String("key_count")` with `u64` as the value.
pub fn key_count(self) -> SelectKeyCount {
SelectKeyCount(SelectKeyCountQuery(QueryIds::Ids(vec![])))
}
/// Select number of nodes in the database. The result will be a
/// single element with a property `String("node_count")` with `u64`
/// as the value.
pub fn node_count(self) -> SelectNodeCount {
SelectNodeCount {}
}
/// Select with all properties (key-values) using result
/// of the search query as ids. Equivalent to `ids(QueryBuilder::search()/* ... */)`.
pub fn search(self) -> Search<SelectValuesQuery> {
Search(SelectValuesQuery {
keys: vec![],
ids: QueryIds::Search(crate::SearchQuery::new()),
})
}
/// Select elements with `ids` with only `keys` properties (key-values).
/// All ids specified must exist in the database.
pub fn values<T: Into<DbValues>>(self, keys: T) -> SelectValues {
SelectValues {
query: SelectValuesQuery {
keys: Into::<DbValues>::into(keys).0,
ids: QueryIds::Ids(vec![]),
},
element_id: None,
limit: 0,
}
}
}