Struct memquery::collection::Collection[][src]

pub struct Collection {
    pub data: DocumentCollection,
}

Stores JSON documents.

Fields

data: DocumentCollection

Implementations

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]

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]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.