pub trait SerializedCollection: Collection {
    type Contents: Send + Sync;
    type Format: OwnedDeserializer<Self::Contents>;

Show 33 methods // Required method fn format() -> Self::Format; // Provided methods fn natural_id(contents: &Self::Contents) -> Option<Self::PrimaryKey> where Self: Sized { ... } fn deserialize(data: &[u8]) -> Result<Self::Contents, Error> { ... } fn document_contents<D: Document<Self>>( doc: &D ) -> Result<Self::Contents, Error> where Self: Sized { ... } fn set_document_contents<D: Document<Self>>( doc: &mut D, contents: Self::Contents ) -> Result<(), Error> where Self: Sized { ... } fn serialize(item: &Self::Contents) -> Result<Vec<u8>, Error> { ... } fn get<C, PrimaryKey>( id: &PrimaryKey, connection: &C ) -> Result<Option<CollectionDocument<Self>>, Error> where C: Connection, PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: Sized { ... } fn get_async<'life0, 'life1, 'async_trait, C, PrimaryKey>( id: &'life0 PrimaryKey, connection: &'life1 C ) -> Pin<Box<dyn Future<Output = Result<Option<CollectionDocument<Self>>, Error>> + Send + 'async_trait>> where C: AsyncConnection + 'async_trait, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Self: Sized + Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn get_multiple<'id, C, DocumentIds, PrimaryKey, I>( ids: DocumentIds, connection: &C ) -> Result<Vec<CollectionDocument<Self>>, Error> where C: Connection, DocumentIds: IntoIterator<Item = &'id PrimaryKey, IntoIter = I> + Send + Sync, I: Iterator<Item = &'id PrimaryKey> + Send + Sync, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'id, Self: Sized { ... } fn get_multiple_async<'id, 'life0, 'async_trait, C, DocumentIds, PrimaryKey, I>( ids: DocumentIds, connection: &'life0 C ) -> Pin<Box<dyn Future<Output = Result<Vec<CollectionDocument<Self>>, Error>> + Send + 'async_trait>> where C: AsyncConnection + 'async_trait, DocumentIds: IntoIterator<Item = &'id PrimaryKey, IntoIter = I> + Send + Sync + 'async_trait, I: Iterator<Item = &'id PrimaryKey> + Send + Sync + 'async_trait, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'id + 'async_trait, Self: Sized + Send + 'async_trait, 'id: 'async_trait, 'life0: 'async_trait { ... } fn list<'id, R, PrimaryKey, C>( ids: R, connection: &'id C ) -> List<'id, C, Self, PrimaryKey> where R: Into<RangeRef<'id, Self::PrimaryKey, PrimaryKey>>, C: Connection, PrimaryKey: KeyEncoding<Self::PrimaryKey> + PartialEq + 'id, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>, Self: Sized { ... } fn list_async<'id, R, PrimaryKey, C>( ids: R, connection: &'id C ) -> AsyncList<'id, C, Self, PrimaryKey> where R: Into<RangeRef<'id, Self::PrimaryKey, PrimaryKey>>, C: AsyncConnection, PrimaryKey: KeyEncoding<Self::PrimaryKey> + PartialEq + 'id + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>, Self: Sized { ... } fn list_with_prefix<'a, PrimaryKey, C>( prefix: &'a PrimaryKey, connection: &'a C ) -> List<'a, C, Self, PrimaryKey> where C: Connection, Self: Sized, PrimaryKey: IntoPrefixRange<'a, Self::PrimaryKey> + KeyEncoding<Self::PrimaryKey> + PartialEq + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey> { ... } fn list_with_prefix_async<'a, PrimaryKey, C>( prefix: &'a PrimaryKey, connection: &'a C ) -> AsyncList<'a, C, Self, PrimaryKey> where C: AsyncConnection, Self: Sized, PrimaryKey: IntoPrefixRange<'a, Self::PrimaryKey> + KeyEncoding<Self::PrimaryKey> + PartialEq + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey> { ... } fn all<C: Connection>(connection: &C) -> List<'_, C, Self, Self::PrimaryKey> where Self: Sized { ... } fn all_async<C: AsyncConnection>( connection: &C ) -> AsyncList<'_, C, Self, Self::PrimaryKey> where Self: Sized { ... } fn push<Cn: Connection>( contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>> where Self: Sized + 'static { ... } fn push_async<'life0, 'async_trait, Cn>( contents: Self::Contents, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>> where Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait { ... } fn push_all<Contents: IntoIterator<Item = Self::Contents>, Cn: Connection>( contents: Contents, connection: &Cn ) -> Result<Vec<CollectionDocument<Self>>, Error> where Self: Sized + 'static, Self::PrimaryKey: Default { ... } fn push_all_async<'life0, 'async_trait, Contents, Cn>( contents: Contents, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<Vec<CollectionDocument<Self>>, Error>> + Send + 'async_trait>> where Self: Sized + 'static + Send + 'async_trait, Self::PrimaryKey: Default, Contents::IntoIter: Send, Contents: 'async_trait + IntoIterator<Item = Self::Contents> + Send, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait { ... } fn push_into<Cn: Connection>( self, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>> where Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn push_into_async<'life0, 'async_trait, Cn>( self, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>> where Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait { ... } fn push_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error> where Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn insert<PrimaryKey, Cn>( id: &PrimaryKey, contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>> where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: Sized + 'static { ... } fn insert_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( id: &'life0 PrimaryKey, contents: Self::Contents, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>> where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn insert_into<PrimaryKey, Cn>( self, id: &PrimaryKey, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>> where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn insert_into_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( self, id: &'life0 PrimaryKey, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>> where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn insert_in_transaction( &self, key: &Self::PrimaryKey, transaction: &mut Transaction ) -> Result<(), Error> where Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn overwrite<PrimaryKey, Cn>( id: &PrimaryKey, contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>> where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: Sized + 'static { ... } fn overwrite_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( id: &'life0 PrimaryKey, contents: Self::Contents, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>> where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn overwrite_into<Cn: Connection, PrimaryKey>( self, id: &PrimaryKey, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>> where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn overwrite_in_transaction<PrimaryKey>( &self, id: &PrimaryKey, transaction: &mut Transaction ) -> Result<(), Error> where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: SerializedCollection<Contents = Self> + Sized + 'static { ... } fn overwrite_into_async<'life0, 'life1, 'async_trait, Cn, PrimaryKey>( self, id: &'life0 PrimaryKey, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>> where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

A collection that knows how to serialize and deserialize documents to an associated type.

These examples for this type use this basic collection definition:

use bonsaidb_core::schema::{Collection, DefaultSerialization, Schematic};
use bonsaidb_core::Error;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Default, Collection)]
#[collection(name = "MyCollection")]
pub struct MyCollection {
    pub rank: u32,
    pub score: f32,
}

Required Associated Types§

source

type Contents: Send + Sync

The type of the contents stored in documents in this collection.

source

type Format: OwnedDeserializer<Self::Contents>

The serialization format for this collection.

Required Methods§

source

fn format() -> Self::Format

Returns the configured instance of Self::Format.

Provided Methods§

source

fn natural_id(contents: &Self::Contents) -> Option<Self::PrimaryKey>
where Self: Sized,

Returns the natural identifier of contents. This is called when pushing values into a collection, before attempting to automatically assign a unique id.

source

fn deserialize(data: &[u8]) -> Result<Self::Contents, Error>

Deserialize data as Self::Contents using this collection’s format.

source

fn document_contents<D: Document<Self>>( doc: &D ) -> Result<Self::Contents, Error>
where Self: Sized,

Returns the deserialized contents of doc.

source

fn set_document_contents<D: Document<Self>>( doc: &mut D, contents: Self::Contents ) -> Result<(), Error>
where Self: Sized,

Sets the contents of doc to contents.

source

fn serialize(item: &Self::Contents) -> Result<Vec<u8>, Error>

Serialize item using this collection’s format.

source

fn get<C, PrimaryKey>( id: &PrimaryKey, connection: &C ) -> Result<Option<CollectionDocument<Self>>, Error>
where C: Connection, PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: Sized,

Gets a CollectionDocument with id from connection.

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

fn get_async<'life0, 'life1, 'async_trait, C, PrimaryKey>( id: &'life0 PrimaryKey, connection: &'life1 C ) -> Pin<Box<dyn Future<Output = Result<Option<CollectionDocument<Self>>, Error>> + Send + 'async_trait>>
where C: AsyncConnection + 'async_trait, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Self: Sized + Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets a CollectionDocument with id from connection.

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

fn get_multiple<'id, C, DocumentIds, PrimaryKey, I>( ids: DocumentIds, connection: &C ) -> Result<Vec<CollectionDocument<Self>>, Error>
where C: Connection, DocumentIds: IntoIterator<Item = &'id PrimaryKey, IntoIter = I> + Send + Sync, I: Iterator<Item = &'id PrimaryKey> + Send + Sync, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'id, Self: Sized,

Retrieves all documents matching ids. Documents that are not found are not returned, but no error will be generated.

for doc in MyCollection::get_multiple(&[42, 43], &db)? {
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn get_multiple_async<'id, 'life0, 'async_trait, C, DocumentIds, PrimaryKey, I>( ids: DocumentIds, connection: &'life0 C ) -> Pin<Box<dyn Future<Output = Result<Vec<CollectionDocument<Self>>, Error>> + Send + 'async_trait>>
where C: AsyncConnection + 'async_trait, DocumentIds: IntoIterator<Item = &'id PrimaryKey, IntoIter = I> + Send + Sync + 'async_trait, I: Iterator<Item = &'id PrimaryKey> + Send + Sync + 'async_trait, PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'id + 'async_trait, Self: Sized + Send + 'async_trait, 'id: 'async_trait, 'life0: 'async_trait,

Retrieves all documents matching ids. Documents that are not found are not returned, but no error will be generated.

for doc in MyCollection::get_multiple_async(&[42, 43], &db).await? {
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn list<'id, R, PrimaryKey, C>( ids: R, connection: &'id C ) -> List<'id, C, Self, PrimaryKey>
where R: Into<RangeRef<'id, Self::PrimaryKey, PrimaryKey>>, C: Connection, PrimaryKey: KeyEncoding<Self::PrimaryKey> + PartialEq + 'id, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>, Self: Sized,

Retrieves all documents matching the range of ids.

for doc in MyCollection::list(42.., &db)
    .descending()
    .limit(20)
    .query()?
{
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn list_async<'id, R, PrimaryKey, C>( ids: R, connection: &'id C ) -> AsyncList<'id, C, Self, PrimaryKey>
where R: Into<RangeRef<'id, Self::PrimaryKey, PrimaryKey>>, C: AsyncConnection, PrimaryKey: KeyEncoding<Self::PrimaryKey> + PartialEq + 'id + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>, Self: Sized,

Retrieves all documents matching the range of ids.

for doc in MyCollection::list_async(42.., &db)
    .descending()
    .limit(20)
    .await?
{
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn list_with_prefix<'a, PrimaryKey, C>( prefix: &'a PrimaryKey, connection: &'a C ) -> List<'a, C, Self, PrimaryKey>
where C: Connection, Self: Sized, PrimaryKey: IntoPrefixRange<'a, Self::PrimaryKey> + KeyEncoding<Self::PrimaryKey> + PartialEq + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>,

Retrieves all documents with ids that start with prefix.

use bonsaidb_core::connection::Connection;
use bonsaidb_core::document::CollectionDocument;
use bonsaidb_core::schema::{Collection, Schematic, SerializedCollection};
use bonsaidb_core::Error;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Default, Collection)]
#[collection(name = "MyCollection", primary_key = String)]
pub struct MyCollection;

async fn starts_with_a<C: Connection>(
    db: &C,
) -> Result<Vec<CollectionDocument<MyCollection>>, Error> {
    MyCollection::list_with_prefix("a", db).query()
}
source

fn list_with_prefix_async<'a, PrimaryKey, C>( prefix: &'a PrimaryKey, connection: &'a C ) -> AsyncList<'a, C, Self, PrimaryKey>
where C: AsyncConnection, Self: Sized, PrimaryKey: IntoPrefixRange<'a, Self::PrimaryKey> + KeyEncoding<Self::PrimaryKey> + PartialEq + ?Sized, Self::PrimaryKey: Borrow<PrimaryKey> + PartialEq<PrimaryKey>,

Retrieves all documents with ids that start with prefix.

use bonsaidb_core::connection::AsyncConnection;
use bonsaidb_core::document::CollectionDocument;
use bonsaidb_core::schema::{Collection, Schematic, SerializedCollection};
use bonsaidb_core::Error;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Default, Collection)]
#[collection(name = "MyCollection", primary_key = String)]
pub struct MyCollection;

async fn starts_with_a<C: AsyncConnection>(
    db: &C,
) -> Result<Vec<CollectionDocument<MyCollection>>, Error> {
    MyCollection::list_with_prefix_async("a", db).await
}
source

fn all<C: Connection>(connection: &C) -> List<'_, C, Self, Self::PrimaryKey>
where Self: Sized,

Retrieves all documents.

for doc in MyCollection::all(&db).query()? {
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn all_async<C: AsyncConnection>( connection: &C ) -> AsyncList<'_, C, Self, Self::PrimaryKey>
where Self: Sized,

Retrieves all documents.

for doc in MyCollection::all_async(&db).await? {
    println!(
        "Retrieved #{} with deserialized contents: {:?}",
        doc.header.id, doc.contents
    );
}
source

fn push<Cn: Connection>( contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>>
where Self: Sized + 'static,

Pushes this value into the collection, returning the created document. This function is useful when Self != Self::Contents.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from contents. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let document = MyCollection::push(MyCollection::default(), &db)?;
println!(
    "Inserted {:?} with id {} with revision {}",
    document.contents, document.header.id, document.header.revision
);
source

fn push_async<'life0, 'async_trait, Cn>( contents: Self::Contents, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>>
where Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait,

Pushes this value into the collection, returning the created document. This function is useful when Self != Self::Contents.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from contents. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let document = MyCollection::push_async(MyCollection::default(), &db).await?;
println!(
    "Inserted {:?} with id {} with revision {}",
    document.contents, document.header.id, document.header.revision
);
source

fn push_all<Contents: IntoIterator<Item = Self::Contents>, Cn: Connection>( contents: Contents, connection: &Cn ) -> Result<Vec<CollectionDocument<Self>>, Error>
where Self: Sized + 'static, Self::PrimaryKey: Default,

Pushes all contents in a single transaction. If successful, all collection documents will be returned. If an error occurs during this operation, no documents will be pushed.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from each instance of contents. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let documents = MyCollection::push_all(
    [
        MyCollection::default(),
        MyCollection::default(),
        MyCollection::default(),
    ],
    &db,
)?;
for document in documents {
    println!(
        "Inserted {:?} with id {} with revision {}",
        document.contents, document.header.id, document.header.revision
    );
}
source

fn push_all_async<'life0, 'async_trait, Contents, Cn>( contents: Contents, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<Vec<CollectionDocument<Self>>, Error>> + Send + 'async_trait>>
where Self: Sized + 'static + Send + 'async_trait, Self::PrimaryKey: Default, Contents::IntoIter: Send, Contents: 'async_trait + IntoIterator<Item = Self::Contents> + Send, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait,

Pushes all contents in a single transaction. If successful, all collection documents will be returned. If an error occurs during this operation, no documents will be pushed.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from each instance of contents. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let documents = MyCollection::push_all_async(
    [
        MyCollection::default(),
        MyCollection::default(),
        MyCollection::default(),
    ],
    &db,
)
.await?;
for document in documents {
    println!(
        "Inserted {:?} with id {} with revision {}",
        document.contents, document.header.id, document.header.revision
    );
}
source

fn push_into<Cn: Connection>( self, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>>
where Self: SerializedCollection<Contents = Self> + Sized + 'static,

Pushes this value into the collection, returning the created document.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from self. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let document = MyCollection::default().push_into(&db)?;
println!(
    "Inserted {:?} with id {} with revision {}",
    document.contents, document.header.id, document.header.revision
);
source

fn push_into_async<'life0, 'async_trait, Cn>( self, connection: &'life0 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>>
where Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait,

Pushes this value into the collection, returning the created document.

Automatic ID Assignment

This function calls Self::natural_id() to try to retrieve a primary key value from self. If an id is returned, the item is inserted with that id. If an id is not returned, an id will be automatically assigned, if possible, by the storage backend, which uses the Key trait to assign ids.

let document = MyCollection::default().push_into_async(&db).await?;
println!(
    "Inserted {:?} with id {} with revision {}",
    document.contents, document.header.id, document.header.revision
);
source

fn push_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error>
where Self: SerializedCollection<Contents = Self> + Sized + 'static,

Pushes an insert Operation without a key to the transaction for this document, allowing the database to generate the primary key for the document.

The document will be inserted once the transaction is applied.

source

fn insert<PrimaryKey, Cn>( id: &PrimaryKey, contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: Sized + 'static,

Inserts this value into the collection with the specified id, returning the created document.

let document = MyCollection::insert(&42, MyCollection::default(), &db)?;
assert_eq!(document.header.id, 42);
println!(
    "Inserted {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn insert_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( id: &'life0 PrimaryKey, contents: Self::Contents, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Inserts this value into the collection with the specified id, returning the created document.

let document = MyCollection::insert_async(&42, MyCollection::default(), &db).await?;
assert_eq!(document.header.id, 42);
println!(
    "Inserted {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn insert_into<PrimaryKey, Cn>( self, id: &PrimaryKey, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: SerializedCollection<Contents = Self> + Sized + 'static,

Inserts this value into the collection with the given id, returning the created document.

let document = MyCollection::default().insert_into(&42, &db)?;
assert_eq!(document.header.id, 42);
println!(
    "Inserted {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn insert_into_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( self, id: &'life0 PrimaryKey, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Inserts this value into the collection with the given id, returning the created document.

let document = MyCollection::default().insert_into_async(&42, &db).await?;
assert_eq!(document.header.id, 42);
println!(
    "Inserted {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn insert_in_transaction( &self, key: &Self::PrimaryKey, transaction: &mut Transaction ) -> Result<(), Error>
where Self: SerializedCollection<Contents = Self> + Sized + 'static,

Pushes an insert Operation to the transaction for this document.

The document will be inserted once the transaction is applied.

source

fn overwrite<PrimaryKey, Cn>( id: &PrimaryKey, contents: Self::Contents, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self::Contents>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Cn: Connection, Self: Sized + 'static,

Overwrites this value into the collection with the specified id, returning the created or updated document.

let document = MyCollection::overwrite(&42, MyCollection::default(), &db)?;
assert_eq!(document.header.id, 42);
println!(
    "Overwrote {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn overwrite_async<'life0, 'life1, 'async_trait, PrimaryKey, Cn>( id: &'life0 PrimaryKey, contents: Self::Contents, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self::Contents>>> + Send + 'async_trait>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Cn: AsyncConnection + 'async_trait, Self: Sized + 'static + Send + 'async_trait, Self::Contents: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Overwrites this value into the collection with the specified id, returning the created or updated document.

let document = MyCollection::overwrite_async(&42, MyCollection::default(), &db).await?;
assert_eq!(document.header.id, 42);
println!(
    "Overwrote {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn overwrite_into<Cn: Connection, PrimaryKey>( self, id: &PrimaryKey, connection: &Cn ) -> Result<CollectionDocument<Self>, InsertError<Self>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: SerializedCollection<Contents = Self> + Sized + 'static,

Overwrites this value into the collection with the given id, returning the created or updated document.

let document = MyCollection::default().overwrite_into(&42, &db)?;
assert_eq!(document.header.id, 42);
println!(
    "Overwrote {:?} with revision {}",
    document.contents, document.header.revision
);
source

fn overwrite_in_transaction<PrimaryKey>( &self, id: &PrimaryKey, transaction: &mut Transaction ) -> Result<(), Error>
where PrimaryKey: KeyEncoding<Self::PrimaryKey>, Self: SerializedCollection<Contents = Self> + Sized + 'static,

Pushes an overwrite Operation to the transaction for this document.

The document will be overwritten once the transaction is applied.

source

fn overwrite_into_async<'life0, 'life1, 'async_trait, Cn, PrimaryKey>( self, id: &'life0 PrimaryKey, connection: &'life1 Cn ) -> Pin<Box<dyn Future<Output = Result<CollectionDocument<Self>, InsertError<Self>>> + Send + 'async_trait>>
where PrimaryKey: KeyEncoding<Self::PrimaryKey> + 'async_trait, Self: SerializedCollection<Contents = Self> + Sized + 'static + Send + 'async_trait, Cn: 'async_trait + AsyncConnection, 'life0: 'async_trait, 'life1: 'async_trait,

Overwrites this value into the collection with the given id, returning the created or updated document.

let document = MyCollection::default()
    .overwrite_into_async(&42, &db)
    .await?;
assert_eq!(document.header.id, 42);
println!(
    "Overwrote {:?} with revision {}",
    document.contents, document.header.revision
);

Object Safety§

This trait is not object safe.

Implementors§