pub struct Collection { /* private fields */ }Expand description
Use ditto.store().collection("...")? to query or mutate documents in a Collection.
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the name of this Collection.
§Example
let cars = ditto.store().collection("cars")?;
assert_eq!(cars.name(), "cars");Sourcepub fn find_all(&self) -> PendingCursorOperation<'_>
pub fn find_all(&self) -> PendingCursorOperation<'_>
Query all documents in the named collection.
This produces a PendingCursorOperation which may be used to perform
subsequent operations on the queried documents, in this case all documents
in the named collection.
§Example
use dittolive_ditto::prelude::*;
let collection = ditto.store().collection("cars")?;
let pending_op = collection.find_all();
let documents: Vec<_> = pending_op.exec()?;Sourcepub fn find(&self, query: &str) -> PendingCursorOperation<'_>
pub fn find(&self, query: &str) -> PendingCursorOperation<'_>
Queries documents in the named collection according to the given QueryBuilder query string.
Note: The query strings accepted here are NOT Ditto-Query-Language (DQL) queries. If you can achieve your use-case via a DQL query, we recommend you do that instead. See the DQL module docs for more info about DQL.
This produces a PendingCursorOperation which may be used to perform
subsequent operations on the queried documents, in this case all documents
in the named collection.
For more details about the query syntax accepted here, see the query_builder
module documentation
Sourcepub fn find_with_args<V: Serialize, C: Borrow<V>>(
&self,
query: &str,
query_args: C,
) -> PendingCursorOperation<'_>
pub fn find_with_args<V: Serialize, C: Borrow<V>>( &self, query: &str, query_args: C, ) -> PendingCursorOperation<'_>
Generates a PendingCursorOperation with the provided query and query arguments that can
be used to find the documents matching the query at a point in time or you can chain a call
to PendingCursorOperation::observe_local or PendingCursorOperation::subscribe if
you want to get updates about documents matching the query as they occur. It can also be
used to update, remove, or evict documents.
This is the recommended function to use when performing queries on a collection if you have
any dynamic data included in the query string. It allows you to provide a query string with
placeholders, in the form of $args.my_arg_name, along with an accompanying dictionary of
arguments, in the form of { "my_arg_name": "some value" }, and the placeholders will be
appropriately replaced by the matching provided arguments from the dictionary. This includes
handling things like wrapping strings in quotation marks and arrays in square brackets, for
example.
Sourcepub fn find_by_id(
&self,
doc_id: impl Into<DocumentId>,
) -> PendingIdSpecificOperation
pub fn find_by_id( &self, doc_id: impl Into<DocumentId>, ) -> PendingIdSpecificOperation
Generates a PendingIdSpecificOperation with the provided document Id that can be used
to find the document at a point in time or you can chain a call to
PendingIdSpecificOperation::observe_local or PendingIdSpecificOperation::subscribe
if you want to get updates about the document over time. It can also be used to update,
remove, or evict the document.
Source§impl Collection
impl Collection
Sourcepub fn upsert<V: Serialize, C: Borrow<V>>(
&self,
content: C,
) -> Result<DocumentId, DittoError>
pub fn upsert<V: Serialize, C: Borrow<V>>( &self, content: C, ) -> Result<DocumentId, DittoError>
Inserts a new document into the collection and returns its Id. If the document already exists, the provided document content will be merged with the existing document’s content.
Sourcepub fn upsert_with_strategy<V: Serialize, C: Borrow<V>>(
&self,
content: C,
write_strategy: WriteStrategy,
) -> Result<DocumentId, DittoError>
pub fn upsert_with_strategy<V: Serialize, C: Borrow<V>>( &self, content: C, write_strategy: WriteStrategy, ) -> Result<DocumentId, DittoError>
Inserts a new document into the collection and returns its Id. If the
document already exists, the behavior is determined by the provided
write_strategy.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more