[][src]Struct ejdb::query::Query

pub struct Query { /* fields omitted */ }

An EJDB query.

This structure represents both a find query and an update query, because both kinds of queries are executed in the same way.

A query internally is a BSON document of a certain format, very similar to MongoDB queries. This structure provides convenience methods to build such a document. Additionally, a query may have hints, i.e. non-data parameters affecting its behavior. These parameters are encapsulated in the QueryHints structure and are passed to the Collection::query() method separately.

This structure implements Deref<Target=bson::Document> and DerefMut, and it also has as_bson()/as_bson_mut()/into_bson() methods and Into<bson::Document>/From<bson::Document> implementations, so it is possible to work with the query as with a regular BSON document. Note, however, that an invalid query will result in an error when it is executed, so it is recommended to use the builder API to construct queries.

Most of the building methods here are as generic as possible; e.g. they take Into<String> instead of &str or String; same with iterable objects. This is done for maximum flexibility - these methods will consume almost anything which is sensible to pass to them.

Methods

impl Query[src]

pub fn new() -> Query[src]

Creates a new empty query with empty hints.

This method can be a starting point for building a query; see Q struct, however.

pub fn and<I>(self, queries: I) -> Query where
    I: IntoIterator,
    I::Item: Into<Document>, 
[src]

Builds $and query.

Selects all records which satisfy all of the provided queries simultaneously.

pub fn or<I>(self, queries: I) -> Query where
    I: IntoIterator,
    I::Item: Into<Document>, 
[src]

Builds $or query.

Selects all records which satisfy at least one of the provided queries.

pub fn id<V: Into<Bson>>(self, value: V) -> Query[src]

Sets equality constraint for _id field.

This is just a shortcut for query.field("_id").eq(value).

pub fn field<S: Into<String>>(self, name: S) -> FieldConstraint[src]

Returns a builder object for a field constraint.

This is the main method to set query constraints. Usually a query contains one or more such constraints.

pub fn join<S: Into<String>, C: Into<String>>(self, key: S, coll: C) -> Query[src]

Constructs a $join query.

Joins this collection with another one by the value of _id field.

pub fn add_to_set<S: Into<String>, V: Into<Bson>>(
    self,
    key: S,
    value: V
) -> Query
[src]

Constructs an $addToSet update query.

Adds value to the set (represented as a BSON array) at the field key.

pub fn add_to_set_all<S, I>(self, key: S, values: I) -> Query where
    S: Into<String>,
    I: IntoIterator,
    I::Item: Into<Bson>, 
[src]

Constructs a multi-valued $addToSet update query.

Adds all items from values to the set (represented as a BSON array) at the field key.

pub fn unset<S: Into<String>>(self, key: S) -> Query[src]

Constructs an $unset update query.

Removes the field key.

pub fn inc<S: Into<String>, D: BsonNumber>(self, key: S, delta: D) -> Query[src]

Constructs an $inc update query.

Increments the numerical value in field key by delta. Use negative delta for decrements.

pub fn drop_all(self) -> Query[src]

Constructs a $dropall update query.

Removes all records from the collection.

pub fn set<S: Into<String>, V: Into<Bson>>(self, key: S, value: V) -> Query[src]

Constructs a $set update query for a single field.

Sets the field key to the value value in all matched records. Multiple sequential set()s will be merged.

pub fn set_many<D: Into<Document>>(self, document: D) -> Query[src]

Constructs an entire $set update query.

Sets all fields from the document to their respective values in all matched records. Overwrites all previous set() and set_many() invocations.

pub fn upsert<S: Into<String>, V: Into<Bson>>(self, key: S, value: V) -> Query[src]

Constructs an $upsert update query for a single field.

Like set(), but will insert new record if none matched. Multiple sequential set()s will be merged.

pub fn upsert_many<D: Into<Document>>(self, document: D) -> Query[src]

Constructs an entire $upsert update query.

Like set(), but will insert new record if none matched. Overwrites all previous upsert() and upsert_field() calls.

pub fn pull<S: Into<String>, V: Into<Bson>>(self, key: S, value: V) -> Query[src]

Constructs a $pull update query.

Removes the value from an array at the field key in all matched records.

pub fn pull_all<S, I>(self, key: S, values: I) -> Query where
    S: Into<String>,
    I: IntoIterator,
    I::Item: Into<Bson>, 
[src]

Constructs a multiple-valued $pull update query.

Removes all values from values from an array at the field key in all matched records. Multiple push_all() calls will be merged.

pub fn push<S: Into<String>, V: Into<Bson>>(self, key: S, value: V) -> Query[src]

Constructs a $push update query.

Appends the provided value to an array field key in all matched records. Multiple push() calls will be merged.

pub fn push_all<S, I>(self, key: S, values: I) -> Query where
    S: Into<String>,
    I: IntoIterator,
    I::Item: Into<Bson>, 
[src]

Constructs a multiple-valued $push update query.

Appends all values from values to an array field key in all matched records. Multiple push_all() calls will be merged.

pub fn rename<S1: Into<String>, S2: Into<String>>(
    self,
    key: S1,
    new_key: S2
) -> Query
[src]

Constructs a $rename update query.

Renames field key to new_key in all matched records. Multiple rename() calls will be merged.

pub fn slice<S: Into<String>>(self, key: S, limit: i64) -> Query[src]

Constructs a limit-only $slice query.

Limits the number of array items of the field key in the returned result. limit is the number of elements which will be taken from the beginning of the array.

pub fn slice_with_offset<S: Into<String>>(
    self,
    key: S,
    offset: i64,
    limit: i64
) -> Query
[src]

Constructs a full $slice query.

Limits the number of array items of the field key in the returned result. limit is the maximum number of elements to be returned starting from offset.

pub fn into_bson(self) -> Document[src]

Converts this query to a BSON document.

pub fn as_bson(&self) -> &Document[src]

Returns a reference to this query as a BSON document.

pub fn as_bson_mut(&mut self) -> &mut Document[src]

Returns a mutable reference to this query as a BSON document.

Be careful when modifying the document directly because it may lead to invalid queries.

Trait Implementations

impl PartialEq<Query> for Query[src]

impl Clone for Query[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl From<OrderedDocument> for Query[src]

impl Into<OrderedDocument> for Query[src]

impl Debug for Query[src]

impl DerefMut for Query[src]

impl Deref for Query[src]

type Target = Document

The resulting type after dereferencing.

Auto Trait Implementations

impl Send for Query

impl Sync for Query

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Err = <U as TryFrom<T>>::Err