pub trait NamedCollection: Collection + Unpin {
    type ByNameView: SerializedView<Key = String, Collection = Self>;

    // Provided methods
    fn load<'name, N, C>(
        id: N,
        connection: &C
    ) -> Result<Option<CollectionDocument<Self>>, Error>
       where N: Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: Connection,
             Self: SerializedCollection + Sized + 'static { ... }
    fn load_async<'name, 'life0, 'async_trait, N, C>(
        id: N,
        connection: &'life0 C
    ) -> Pin<Box<dyn Future<Output = Result<Option<CollectionDocument<Self>>, Error>> + Send + 'async_trait>>
       where 'name: 'async_trait,
             'life0: 'async_trait,
             Self: SerializedCollection + Sized + 'static + Send + 'async_trait,
             N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: 'async_trait + AsyncConnection { ... }
    fn entry<'name, N, C, 'connection>(
        id: N,
        connection: &'connection C
    ) -> Entry<'connection, 'name, C, Self, (), ()>
       where N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync,
             C: Connection,
             Self: SerializedCollection + Sized { ... }
    fn entry_async<'name, N, C, 'connection>(
        id: N,
        connection: &'connection C
    ) -> AsyncEntry<'connection, 'name, C, Self, (), ()> 
       where N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync,
             C: AsyncConnection,
             Self: SerializedCollection + Sized { ... }
    fn load_document<'name, N, C>(
        name: N,
        connection: &C
    ) -> Result<Option<OwnedDocument>, Error>
       where N: Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: Connection,
             Self: SerializedCollection + Sized { ... }
    fn load_document_async<'name, 'life0, 'async_trait, N, C>(
        name: N,
        connection: &'life0 C
    ) -> Pin<Box<dyn Future<Output = Result<Option<OwnedDocument>, Error>> + Send + 'async_trait>>
       where 'name: 'async_trait,
             'life0: 'async_trait,
             Self: SerializedCollection + Sized + Send + 'async_trait,
             N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: 'async_trait + AsyncConnection { ... }
    fn delete_by_name<C>(name: &str, connection: &C) -> Result<bool, Error>
       where C: Connection,
             Self: SerializedCollection + Sized { ... }
    fn delete_by_name_async<'life0, 'life1, 'async_trait, C>(
        name: &'life0 str,
        connection: &'life1 C
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: SerializedCollection + Sized + Send + 'async_trait,
             C: 'async_trait + AsyncConnection { ... }
}
Expand description

A collection with a unique name column.

Finding a document by unique name

if let Some(doc) = MyCollection::load("unique name", &db)? {
    println!(
        "Retrieved revision {} with deserialized contents: {:?}",
        doc.header.revision, doc.contents
    );
}

Load accepts either a string or a DocumentId. This enables building methods that accept either the unique ID or the unique name:

if let Some(doc) = MyCollection::load(42, &db)? {
    println!(
        "Retrieved revision {} with deserialized contents: {:?}",
        doc.header.revision, doc.contents
    );
}

Executing an insert or update

let upserted = MyCollection::entry("unique name", &db)
    .update_with(|existing: &mut MyCollection| {
        existing.rank += 1;
    })
    .or_insert_with(MyCollection::default)
    .execute()?
    .unwrap();
println!("Rank: {:?}", upserted.contents.rank);

Required Associated Types§

source

type ByNameView: SerializedView<Key = String, Collection = Self>

The name view defined for the collection.

Provided Methods§

source

fn load<'name, N, C>( id: N, connection: &C ) -> Result<Option<CollectionDocument<Self>>, Error>
where N: Nameable<'name, Self::PrimaryKey> + Send + Sync, C: Connection, Self: SerializedCollection + Sized + 'static,

Gets a CollectionDocument with id from connection.

source

fn load_async<'name, 'life0, 'async_trait, N, C>( id: N, connection: &'life0 C ) -> Pin<Box<dyn Future<Output = Result<Option<CollectionDocument<Self>>, Error>> + Send + 'async_trait>>
where 'name: 'async_trait, 'life0: 'async_trait, Self: SerializedCollection + Sized + 'static + Send + 'async_trait, N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync, C: 'async_trait + AsyncConnection,

Gets a CollectionDocument with id from connection.

source

fn entry<'name, N, C, 'connection>( id: N, connection: &'connection C ) -> Entry<'connection, 'name, C, Self, (), ()>
where N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync, C: Connection, Self: SerializedCollection + Sized,

Gets a CollectionDocument with id from connection.

source

fn entry_async<'name, N, C, 'connection>( id: N, connection: &'connection C ) -> AsyncEntry<'connection, 'name, C, Self, (), ()>

Gets a CollectionDocument with id from connection.

source

fn load_document<'name, N, C>( name: N, connection: &C ) -> Result<Option<OwnedDocument>, Error>
where N: Nameable<'name, Self::PrimaryKey> + Send + Sync, C: Connection, Self: SerializedCollection + Sized,

Loads a document from this collection by name, if applicable. Return Ok(None) if unsupported.

source

fn load_document_async<'name, 'life0, 'async_trait, N, C>( name: N, connection: &'life0 C ) -> Pin<Box<dyn Future<Output = Result<Option<OwnedDocument>, Error>> + Send + 'async_trait>>
where 'name: 'async_trait, 'life0: 'async_trait, Self: SerializedCollection + Sized + Send + 'async_trait, N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync, C: 'async_trait + AsyncConnection,

Loads a document from this collection by name, if applicable. Return Ok(None) if unsupported.

source

fn delete_by_name<C>(name: &str, connection: &C) -> Result<bool, Error>

Deletes a document by its name. Returns true if a document was deleted.

source

fn delete_by_name_async<'life0, 'life1, 'async_trait, C>( name: &'life0 str, connection: &'life1 C ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: SerializedCollection + Sized + Send + 'async_trait, C: 'async_trait + AsyncConnection,

Deletes a document by its name. Returns true if a document was deleted.

Object Safety§

This trait is not object safe.

Implementors§