Struct memquery::collection::Collection [−][src]
pub struct Collection { pub data: DocumentCollection, }
Stores JSON documents.
Fields
data: DocumentCollection
Implementations
impl Collection
[src]
impl Collection
[src]pub fn new() -> Collection
[src]
Make a new collection.
pub async fn insert(&self, document: Value) -> Result<(), Error>
[src]
Insert new document (async).
use memquery::{doc, errors::Error, memdb::MemDb, query}; async fn play() -> Result<(), Error> { let memdb = MemDb::new(); memdb.create_collection("TestCollection").await; let coll = memdb.collection("TestCollection").await?; coll.insert(doc!({ "name": "Tom", "age": 25 })).await?; Ok(()) }
pub async fn find(&self, query: Value) -> Result<Documents, Error>
[src]
Return documents that match specified criteria (async).
use memquery::{doc, errors::Error, memdb::MemDb, query}; async fn play() -> Result<(), Error> { let memdb = MemDb::new(); memdb.create_collection("TestCollection").await; let coll = memdb.collection("TestCollection").await?; coll.insert(doc!({ "name": "Tom", "age": 25 })).await?; let docs = coll.find(query!({"name": "Tom", "age": 25})).await?; Ok(()) }
pub async fn find_and_update(
&self,
query: Value,
update: Value
) -> Result<u64, Error>
[src]
&self,
query: Value,
update: Value
) -> Result<u64, Error>
Updates documents that match search criteria.
use memquery::{doc, errors::Error, memdb::MemDb, query, update}; async fn play() -> Result<(), Error> { let memdb = MemDb::new(); memdb.create_collection("TestCollection").await; let coll = memdb.collection("TestCollection").await?; coll.insert(doc!({ "name": "Tom", "age": 25 })).await?; let docs_updated = coll .find_and_update( query!({"name": "Tom"}), update!({"nickname": "Bobcat", "voice": "meow"}), ) .await?; Ok(()) }
pub async fn find_and_delete(&self, query: Value) -> Result<Documents, Error>
[src]
Delete documents that match search criteria.
use memquery::{doc, errors::Error, memdb::MemDb, query}; async fn play() -> Result<(), Error> { let memdb = MemDb::new(); memdb.create_collection("TestCollection").await; let coll = memdb.collection("TestCollection").await?; coll.insert(doc!({ "name": "Tom", "age": 25 })).await?; let docs = coll.find_and_delete(query!({"name": "Tom"})).await?; Ok(()) }
Trait Implementations
impl Clone for Collection
[src]
impl Clone for Collection
[src]fn clone(&self) -> Collection
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl !RefUnwindSafe for Collection
impl !RefUnwindSafe for Collection
impl Send for Collection
impl Send for Collection
impl Sync for Collection
impl Sync for Collection
impl Unpin for Collection
impl Unpin for Collection
impl !UnwindSafe for Collection
impl !UnwindSafe for Collection