Struct aragog::query::Query [−][src]
A query utility for ArangoDB to avoid writing simple AQL strings. After building can be rendered
as an AQL string with the to_aql
method.
Examples
#[derive(Clone, Serialize, Deserialize, Record)] pub struct User { pub username: String } // You can init a query in three ways, the following lines do the exact same thing let query = Query::new("Users"); let query2 = User::query(); // `User` needs to implement `Record` let query3 = query!("Users");
Implementations
impl Query
[src]
pub fn new(collection_name: &str) -> Self
[src]
Creates a new empty Query
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
collection_name
- The name of the queried collection
Example
let query = Query::new("User");
pub fn outbound(min: u16, max: u16, edge_collection: &str, vertex: &str) -> Self
[src]
Creates a new outbound traversing Query
though a edge_collection
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestedge_collection
- The name of the traversed edge collectionvertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::outbound(1, 2, "ChildOf", "User/123");
pub fn outbound_graph(
min: u16,
max: u16,
named_graph: &str,
vertex: &str
) -> Self
[src]
min: u16,
max: u16,
named_graph: &str,
vertex: &str
) -> Self
Creates a new outbound traversing Query
though a named_grah
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- The named graph to traversevertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::outbound_graph(1, 2, "SomeGraph", "User/123");
pub fn any(min: u16, max: u16, edge_collection: &str, vertex: &str) -> Self
[src]
Creates a new ANY
traversing Query
though a edge_collection
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestedge_collection
- The name of the traversed edge collectionvertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::outbound(1, 2, "ChildOf", "User/123");
pub fn any_graph(min: u16, max: u16, named_graph: &str, vertex: &str) -> Self
[src]
Creates a new ANY
traversing Query
though a named_grah
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- The named graph to traversevertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::outbound_graph(1, 2, "SomeGraph", "User/123");
pub fn inbound(min: u16, max: u16, edge_collection: &str, vertex: &str) -> Self
[src]
Creates a new inbound traversing Query
though a edge_collection
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestedge_collection
- The name of the traversed edge collectionvertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::inbound(1, 2, "ChildOf", "User/123");
pub fn inbound_graph(
min: u16,
max: u16,
named_graph: &str,
vertex: &str
) -> Self
[src]
min: u16,
max: u16,
named_graph: &str,
vertex: &str
) -> Self
Creates a new inbound traversing Query
though a named_grah
.
You can call filter
, sort
, limit
and distinct
to customize the query afterwards
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- The named graph to traversevertex
- The_id
of the starting document (User/123
for example)
Example
let query = Query::inbound_graph(1, 2, "SomeGraph", "User/123");
pub fn join_outbound(
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
[src]
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
Adds an outbound traversing query to the current Query
.
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- Is the following query on a Named graph?query
- The sub query to add
Example
let query = Query::new("User").join_outbound(1, 2, false, Query::new("ChildOf")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 OUTBOUND b ChildOf \ return a\ ")); let query = Query::new("User").join_outbound(1, 2, true, Query::new("NamedGraph")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 OUTBOUND b GRAPH NamedGraph \ return a\ "));
pub fn join_inbound(
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
[src]
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
Adds an inbound traversing query to the current Query
.
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- Is the following query on a Named graph?query
- The sub query to add
Example
let query = Query::new("User").join_inbound(1, 2, false, Query::new("ChildOf")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 INBOUND b ChildOf \ return a\ ")); let query = Query::new("User").join_inbound(1, 2, true, Query::new("NamedGraph")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 INBOUND b GRAPH NamedGraph \ return a\ "));
pub fn join_any(
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
[src]
self,
min: u16,
max: u16,
named_graph: bool,
query: Query
) -> Self
Adds an ANY
traversing query to the current Query
.
Arguments
min
- The minimum depth of the graph requestmax
- The maximum depth of the graph requestnamed_graph
- Is the following query on a Named graph?query
- The sub query to add
Example
let query = Query::new("User").join_any(1, 2, false, Query::new("ChildOf")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 ANY b ChildOf \ return a\ ")); let query = Query::new("User").join_any(1, 2, true, Query::new("NamedGraph")); assert_eq!(query.to_aql(), String::from("\ FOR b in User \ FOR a in 1..2 ANY b GRAPH NamedGraph \ return a\ "));
pub fn with_collections(self, collections: &[&str]) -> Self
[src]
Allow the current traversing Query
to filter the traversed collections and avoid potentian deadlocks.
Arguments
collections
- The names of the collections the query can traverse
Example
let query = Query::new("User").with_collections(&["User", "Client"]).join_any(1, 2, false, Query::new("ChildOf")); assert_eq!(query.to_aql(), String::from("\ WITH User, Client \ FOR b in User \ FOR a in 1..2 ANY b ChildOf \ return a\ "));
pub fn sort(self, field: &str, direction: Option<SortDirection>) -> Self
[src]
Allows to sort a current Query
by different field names. The fields must exist or the query won't work.
Every time the method is called, a new sorting condition is added.
Note
If you add mutliple sort
calls it will result in something like SORT a.field, b.field, c.field
.
If you separate the calls by a limit
or other operation, the order will be respected and the resulting query
will look like `SORT a.field LIMIT 10 SORT b.field, c.field
Arguments
field
: The field name, must exist in the collectiondirection
: Optional sorting direction for that field. The direction is optional becauseArangoDB
usesASC
sorting by default
Example
let query = Query::new("User") .sort("username", Some(SortDirection::Desc)) .sort("age", Some(SortDirection::Asc) );
pub fn filter(self, filter: Filter) -> Self
[src]
Allows to filter a current Query
by different comparisons.
Example
let query = Query::new("User").filter(Filter::new(Comparison::field("age").greater_than(18))); // or let query = Query::new("User").filter(Comparison::field("age").greater_than(18).into());
pub fn prune(self, filter: Filter) -> Self
[src]
Allows to filter a current Query
by different comparisons but using the PRUNE
keyword.
Note
The prune
operation only works for graph queries (See ArangoDB documentation)
Example
let query = Query::outbound(1, 2, "ChildOf", "User/123").prune(Filter::new(Comparison::field("age").greater_than(18))); // or let query = Query::outbound(1, 2, "ChildOf", "User/123").prune(Comparison::field("age").greater_than(18).into());
pub fn limit(self, limit: u32, skip: Option<u32>) -> Self
[src]
Allows to paginate a current Query
.
Arguments
limit
- the maximum returned elementsskip
- optional number of skipped elements
Example
// We want maximum 10 elements but skip the first 5 let query = Query::new("User").limit(10, Some(5));
pub fn distinct(self) -> Self
[src]
Allows to avoid duplicate elements for a Query
.
Note
If you use sub-queries, only the distinct
on the last sub query will be used.
Example
let query = Query::new("User") .filter(Filter::new(Comparison::field("age").greater_than(18))) .distinct();
pub fn to_aql(&self) -> String
[src]
Renders the AQL string corresponding to the current Query
Example
let mut query = Query::new("User").filter(Filter::new(Comparison::field("age").greater_than(10)). or(Comparison::field("username").in_str_array(&["Felix", "Bianca"]))).distinct(); assert_eq!(query.to_aql(), String::from("\ FOR a in User \ FILTER a.age > 10 || a.username IN [\"Felix\", \"Bianca\"] \ return DISTINCT a\ "));
pub async fn call<D>(self, db_pool: &D) -> Result<JsonQueryResult, ServiceError> where
D: DatabaseAccess,
[src]
D: DatabaseAccess,
Finds all documents in database matching the current Query
.
This will return a wrapper for serde_json
::Value
Simple wrapper for DatabaseRecord
<T
>::get
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl UnwindSafe for Query
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,