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

    // Provided methods
    fn load<'name, N: Nameable<'name, Self::PrimaryKey> + Send + Sync, C: Connection>(
        id: N,
        connection: &C
    ) -> Result<Option<CollectionDocument<Self>>, Error>
       where 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 Self: SerializedCollection + Sized + 'static + Send + 'async_trait,
             N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: 'async_trait + AsyncConnection,
             'name: 'async_trait,
             'life0: 'async_trait { ... }
    fn entry<'connection, 'name, N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync, C: Connection>(
        id: N,
        connection: &'connection C
    ) -> Entry<'connection, 'name, C, Self, (), ()>
       where Self: SerializedCollection + Sized { ... }
    fn entry_async<'connection, 'name, N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync, C: AsyncConnection>(
        id: N,
        connection: &'connection C
    ) -> AsyncEntry<'connection, 'name, C, Self, (), ()> 
       where Self: SerializedCollection + Sized { ... }
    fn load_document<'name, N: Nameable<'name, Self::PrimaryKey> + Send + Sync, C: Connection>(
        name: N,
        connection: &C
    ) -> Result<Option<OwnedDocument>, Error>
       where 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 Self: SerializedCollection + Sized + Send + 'async_trait,
             N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
             C: 'async_trait + AsyncConnection,
             'name: 'async_trait,
             'life0: 'async_trait { ... }
    fn delete_by_name<C: Connection>(
        name: &str,
        connection: &C
    ) -> Result<bool, Error>
       where 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 Self: SerializedCollection + Sized + Send + 'async_trait,
             C: 'async_trait + AsyncConnection,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
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: Nameable<'name, Self::PrimaryKey> + Send + Sync, C: Connection>( id: N, connection: &C ) -> Result<Option<CollectionDocument<Self>>, Error>
where 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 Self: SerializedCollection + Sized + 'static + Send + 'async_trait, N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync, C: 'async_trait + AsyncConnection, 'name: 'async_trait, 'life0: 'async_trait,

Gets a CollectionDocument with id from connection.

source

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

Gets a CollectionDocument with id from connection.

source

fn entry_async<'connection, 'name, N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync, C: AsyncConnection>( id: N, connection: &'connection C ) -> AsyncEntry<'connection, 'name, C, Self, (), ()>

Gets a CollectionDocument with id from connection.

source

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

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 Self: SerializedCollection + Sized + Send + 'async_trait, N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync, C: 'async_trait + AsyncConnection, 'name: 'async_trait, 'life0: 'async_trait,

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

source

fn delete_by_name<C: Connection>( 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 Self: SerializedCollection + Sized + Send + 'async_trait, C: 'async_trait + AsyncConnection, 'life0: 'async_trait, 'life1: 'async_trait,

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

Object Safety§

This trait is not object safe.

Implementors§