[−][src]Struct transistor::types::query::Query
A Query
is a special kind of body that we submit to the query
function. It has the following fields:
find
is responsible for defining which elements of the query you want shown in the response, it is required. Argument is a vector with elements to be queried,vec!["a", "b", "c"]
. It is parsed as:find [a b c]
, qherea, b, c
are the elements defined inwhere
clause.where_clause
is responsible for defining which rules will be applied to filter elements, it is required. Argument is a vector with the strings containing the filtering function,vec!["a :db-key1 b", "a :db-key2 c", "a :db-key3 <some value>"]
. It is parsed as:where [ [a :db-key1 b] [a :db-key2 c] [a :db-key3 <some value>] ]
.args
is responsible for defining arguments to be replaced inwhere_clause
, optional. Argument is a vector with strings containing the matchesvec!["?n \"Ivan\" ?l \"Ivanov\"", "?n \"Petr\" ?l \"Petrov\""]
.order_by
is responsible for defining the order in which the response will be represented, optional. Argument is a vector with strings containing the element and how to order (:asc
or:desc
)vec!["time :desc", "device-id :asc"]
.limit
is responsible for defining the limit size of the response, optional. Argument is a usize.offset
is responsible for defining the offset of the response, optional. Argument is a usize.
Implementations
impl Query
[src]
pub fn find(find: Vec<&str>) -> Result<Self, CruxError>
[src]
find
is the function responsible for defining the :find
key in the query.
Input should be the elements to be queried by the where_clause
.
Ex: vec!["time", "device-id", "temperature", "humidity"]
.
Becomes: :find [time, device-id, temperature, humidity]
.
Error cases:
- All elements should start with
?
, examplevec!["?p1", "?n", "?g"]
. If theey do not start the CruxError::QueryFormatError containingAll elements of find clause should start with '?', element '{}' doesn't conform
is thrown.
pub fn where_clause(self, where_: Vec<&str>) -> Result<Self, CruxError>
[src]
where_clause
is the function responsible for defining the required :where
key in the query.
Input should be element1 :key element2
, element2
may have a modifier like #inst
. The order matters.
Ex: vec!["c :condition/time time", "c :condition/device-id device-id", "c :condition/temperature temperature", "c :condition/humidity humidity"]
.
Becomes:
:where [[c :condition/time time] [c :condition/device-id device-id] [c :condition/temperature temperature] [c :condition/humidity humidity]]
.
Error cases:
- All elements present in find clause should be present in where clause. If your find clause is
"?p", "?n", "?s"
, and your where clause is"?p1 :alpha ?n", "?p1 :beta true"
an errorNot all element of find,
"?p", "?n", "?s", are present in the where clause, ?s is missing
is thrown.
pub fn args(self, args: Vec<&str>) -> Result<Self, CruxError>
[src]
args
is the function responsible for defining the optional :args
key in the query.
Input are elements you want to replace in the where_clause
, a good practice is to name them with ?
before.
Ex: vec!["?n \"Ivan\" ?l \"Ivanov\"", "?n \"Petr\" ?l \"Petrov\""]
.
Becomes: :args [{?n "Ivan" ?l "Ivanov"} {?n "Petr" ?l "Petrov"}]
.
Error cases:
- The first element of the argument key-value tuple should start with
?
. An inputvec!["n true"]
will return an errorAll elements should start with '?'
. - All arguments key should be present in the where clause. If the where clause
?p1 :name ?n", "?p1 :is-sql ?s", "?p1 :is-sql true"
and an args clausevec!["?s true ?x 1243"]
will return an errorAll elements should be present in where clause
.
pub fn order_by(self, order_by: Vec<&str>) -> Result<Self, CruxError>
[src]
order_by
is the function responsible for defining the optional :order-by
key in the query.
Input is the elements to be ordered by, the first element is the first order, the second is the further orthers. Allowed keys are :Asc
and :desc
.
Ex: vec!["time :desc", "device-id :asc"]
.
Becomes: :order-by [[time :desc] [device-id :asc]]
.
Error cases:
- The second element of each order clause should be
:asc
or:desc
, if different, like:eq
in"?p1 :asc", "?n :desc", "?s :eq"
, errorOrder element should be ':asc' or ':desc'
is thrown. - The first element of each order clause should be present in the find clause. If the order clause is
"?p1 :asc", "?n :desc", "?g :asc"
and the find clause is"?p1", "?n"
the errorAll elements to be ordered should be present in find clause, ?g not present
is thrown.
pub fn limit(self, limit: usize) -> Self
[src]
limit
is the function responsible for defining the optional :limit
key in the query.
Input is a usize with the query limit size.
.limit(5usize)
Becomes: :limit 5
.
pub fn offset(self, offset: usize) -> Self
[src]
offset
is the function responsible for defining the optional :offset
key in the query.
Input is a usize with the query offset.
.offset(5usize)
Becomes: :offset 5
.
pub fn with_full_results(self) -> Self
[src]
with_full_results
adds :full-results? true
to the query map to easily retrieve the source documents relating to the entities in the result set.
pub fn build(self) -> Result<Self, CruxError>
[src]
build
function helps you assert that required fields were implemented.
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[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.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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.
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>,