Trait bonsaidb::core::schema::NamedCollection[][src]

pub trait NamedCollection: Collection + Unpin {
    type ByNameView: SerializedView;
    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: 'static + SerializedCollection
, { ... }
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, Global>>
    where
        'name: 'async_trait,
        'life0: 'async_trait,
        Self: 'static + SerializedCollection + 'async_trait + Send,
        N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
        C: 'async_trait + AsyncConnection
, { ... }
fn entry<'name, N, C>(
        id: N,
        connection: &'connection C
    ) -> Entry<'connection, 'name, C, Self, (), ()>
    where
        N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync,
        C: Connection,
        Self: SerializedCollection
, { ... }
fn entry_async<'name, N, C>(
        id: N,
        connection: &'connection C
    ) -> AsyncEntry<'connection, 'name, C, Self, (), ()>
Notable traits for AsyncEntry<'a, 'name, Conn, Col, EI, EU>
impl<'a, 'name, Conn, Col, EI, EU> Future for AsyncEntry<'a, 'name, Conn, Col, EI, EU> where
    'name: 'a,
    Col: 'static + NamedCollection + SerializedCollection,
    Conn: AsyncConnection,
    EI: 'a + EntryInsert<Col>,
    EU: 'a + EntryUpdate<Col>,
    <Col as Collection>::PrimaryKey: Unpin
type Output = Result<Option<CollectionDocument<Col>>, Error>;

    where
        N: Into<NamedReference<'name, Self::PrimaryKey>> + Send + Sync,
        C: AsyncConnection,
        Self: SerializedCollection
, { ... }
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
, { ... }
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, Global>>
    where
        'name: 'async_trait,
        'life0: 'async_trait,
        Self: SerializedCollection + 'async_trait + Send,
        N: 'async_trait + Nameable<'name, Self::PrimaryKey> + Send + Sync,
        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);

Associated Types

The name view defined for the collection.

Provided methods

Gets a CollectionDocument with id from connection.

Gets a CollectionDocument with id from connection.

Gets a CollectionDocument with id from connection.

Gets a CollectionDocument with id from connection.

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

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

Implementors