Struct bonsaidb::core::document::CollectionDocument
pub struct CollectionDocument<C>where
C: SerializedCollection,{
pub header: CollectionHeader<<C as Collection>::PrimaryKey>,
pub contents: <C as SerializedCollection>::Contents,
}
Expand description
A document with serializable contents.
Fields§
§header: CollectionHeader<<C as Collection>::PrimaryKey>
The header of the document, which contains the id and Revision
.
contents: <C as SerializedCollection>::Contents
The document’s contents.
Implementations§
§impl<C> CollectionDocument<C>where
C: SerializedCollection,
impl<C> CollectionDocument<C>where C: SerializedCollection,
pub fn update<Cn>(&mut self, connection: &Cn) -> Result<(), Error>where
Cn: Connection,
pub fn update<Cn>(&mut self, connection: &Cn) -> Result<(), Error>where Cn: Connection,
Updates the document stored in the database with the contents of this collection document.
if let Some(mut document) = MyCollection::get(&42, &db)? {
// ... do something `document`
document.update(&db)?;
println!(
"The document has been updated: {:?}",
document.header.revision
);
}
pub fn update_in_transaction(
&self,
transaction: &mut Transaction
) -> Result<(), Error>
pub fn update_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error>
Pushes an update Operation
to the transaction for this document.
The changes will happen once the transaction is applied.
pub async fn update_async<Cn>(
&mut self,
connection: &Cn
) -> impl Future<Output = Result<(), Error>>where
Cn: AsyncConnection,
pub async fn update_async<Cn>( &mut self, connection: &Cn ) -> impl Future<Output = Result<(), Error>>where Cn: AsyncConnection,
Stores the new value of contents
in the document.
if let Some(mut document) = MyCollection::get_async(&42, &db).await? {
// modify the document
document.update_async(&db).await?;
println!("Updated revision: {:?}", document.header.revision);
}
pub fn modify<Cn, Modifier>(
&mut self,
connection: &Cn,
modifier: Modifier
) -> Result<(), Error>where
Cn: Connection,
Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync,
<C as SerializedCollection>::Contents: Clone,
pub fn modify<Cn, Modifier>( &mut self, connection: &Cn, modifier: Modifier ) -> Result<(), Error>where Cn: Connection, Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync, <C as SerializedCollection>::Contents: Clone,
Modifies self
, automatically retrying the modification if the document
has been updated on the server.
Data loss warning
If you’ve modified self
before calling this function and a conflict
occurs, all changes to self will be lost when the current document is
fetched before retrying the process again. When you use this function,
you should limit the edits to the value to within the modifier
callback.
pub async fn modify_async<Cn, Modifier>(
&mut self,
connection: &Cn,
modifier: Modifier
) -> impl Future<Output = Result<(), Error>>where
Cn: AsyncConnection,
Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync,
<C as SerializedCollection>::Contents: Clone,
pub async fn modify_async<Cn, Modifier>( &mut self, connection: &Cn, modifier: Modifier ) -> impl Future<Output = Result<(), Error>>where Cn: AsyncConnection, Modifier: FnMut(&mut CollectionDocument<C>) + Send + Sync, <C as SerializedCollection>::Contents: Clone,
Modifies self
, automatically retrying the modification if the document
has been updated on the server.
Data loss warning
If you’ve modified self
before calling this function and a conflict
occurs, all changes to self will be lost when the current document is
fetched before retrying the process again. When you use this function,
you should limit the edits to the value to within the modifier
callback.
pub fn delete<Cn>(&self, connection: &Cn) -> Result<(), Error>where
Cn: Connection,
pub fn delete<Cn>(&self, connection: &Cn) -> Result<(), Error>where Cn: Connection,
Removes the document from the collection.
if let Some(document) = MyCollection::get(&42, &db)? {
document.delete(&db)?;
}
pub async fn delete_async<Cn>(
&self,
connection: &Cn
) -> impl Future<Output = Result<(), Error>>where
Cn: AsyncConnection,
pub async fn delete_async<Cn>( &self, connection: &Cn ) -> impl Future<Output = Result<(), Error>>where Cn: AsyncConnection,
Removes the document from the collection.
if let Some(document) = MyCollection::get_async(&42, &db).await? {
document.delete_async(&db).await?;
}
pub fn delete_in_transaction(
&self,
transaction: &mut Transaction
) -> Result<(), Error>
pub fn delete_in_transaction( &self, transaction: &mut Transaction ) -> Result<(), Error>
Pushes a delete Operation
to the transaction for this document.
The document will be deleted once the transaction is applied.
pub fn refresh<Cn>(&mut self, connection: &Cn) -> Result<(), Error>where
Cn: Connection,
pub fn refresh<Cn>(&mut self, connection: &Cn) -> Result<(), Error>where Cn: Connection,
Refreshes this instance from connection
. If the document is no longer
present, Error::DocumentNotFound
will be returned.
pub async fn refresh_async<Cn>(
&mut self,
connection: &Cn
) -> impl Future<Output = Result<(), Error>>where
Cn: AsyncConnection,
pub async fn refresh_async<Cn>( &mut self, connection: &Cn ) -> impl Future<Output = Result<(), Error>>where Cn: AsyncConnection,
Refreshes this instance from connection
. If the document is no longer
present, Error::DocumentNotFound
will be returned.
pub fn to_document(&self) -> Result<OwnedDocument, Error>
pub fn to_document(&self) -> Result<OwnedDocument, Error>
Converts this value to a serialized Document
.
Trait Implementations§
§impl<C> Clone for CollectionDocument<C>where
C: Clone + SerializedCollection,
<C as Collection>::PrimaryKey: Clone,
<C as SerializedCollection>::Contents: Clone,
impl<C> Clone for CollectionDocument<C>where C: Clone + SerializedCollection, <C as Collection>::PrimaryKey: Clone, <C as SerializedCollection>::Contents: Clone,
§fn clone(&self) -> CollectionDocument<C>
fn clone(&self) -> CollectionDocument<C>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<C> Debug for CollectionDocument<C>where
C: Debug + SerializedCollection,
<C as Collection>::PrimaryKey: Debug,
<C as SerializedCollection>::Contents: Debug,
impl<C> Debug for CollectionDocument<C>where C: Debug + SerializedCollection, <C as Collection>::PrimaryKey: Debug, <C as SerializedCollection>::Contents: Debug,
§impl<'de, C> Deserialize<'de> for CollectionDocument<C>where
C: SerializedCollection,
<C as Collection>::PrimaryKey: Deserialize<'de>,
<C as SerializedCollection>::Contents: Deserialize<'de>,
impl<'de, C> Deserialize<'de> for CollectionDocument<C>where C: SerializedCollection, <C as Collection>::PrimaryKey: Deserialize<'de>, <C as SerializedCollection>::Contents: Deserialize<'de>,
§fn deserialize<D>(
deserializer: D
) -> Result<CollectionDocument<C>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<CollectionDocument<C>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
§impl<C> HasHeader for CollectionDocument<C>where
C: SerializedCollection,
impl<C> HasHeader for CollectionDocument<C>where C: SerializedCollection,
§impl<'a, C> Nameable<'a, <C as Collection>::PrimaryKey> for &'a CollectionDocument<C>where
C: SerializedCollection,
impl<'a, C> Nameable<'a, <C as Collection>::PrimaryKey> for &'a CollectionDocument<C>where C: SerializedCollection,
§fn name(
self
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
fn name( self ) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
NamedReference
.§impl<C> PartialEq<CollectionDocument<C>> for CollectionDocument<C>where
C: PartialEq<C> + SerializedCollection,
<C as Collection>::PrimaryKey: PartialEq<<C as Collection>::PrimaryKey>,
<C as SerializedCollection>::Contents: PartialEq<<C as SerializedCollection>::Contents>,
impl<C> PartialEq<CollectionDocument<C>> for CollectionDocument<C>where C: PartialEq<C> + SerializedCollection, <C as Collection>::PrimaryKey: PartialEq<<C as Collection>::PrimaryKey>, <C as SerializedCollection>::Contents: PartialEq<<C as SerializedCollection>::Contents>,
§fn eq(&self, other: &CollectionDocument<C>) -> bool
fn eq(&self, other: &CollectionDocument<C>) -> bool
self
and other
values to be equal, and is used
by ==
.§impl<C> Serialize for CollectionDocument<C>where
C: SerializedCollection,
<C as SerializedCollection>::Contents: Serialize,
<C as Collection>::PrimaryKey: Serialize,
impl<C> Serialize for CollectionDocument<C>where C: SerializedCollection, <C as SerializedCollection>::Contents: Serialize, <C as Collection>::PrimaryKey: Serialize,
§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
§impl<'a, C> TryFrom<&'a BorrowedDocument<'a>> for CollectionDocument<C>where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a BorrowedDocument<'a>> for CollectionDocument<C>where C: SerializedCollection,
§fn try_from(
value: &'a BorrowedDocument<'a>
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a BorrowedDocument<'a>>>::Error>
fn try_from( value: &'a BorrowedDocument<'a> ) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a BorrowedDocument<'a>>>::Error>
§impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C>where
C: SerializedCollection,
impl<'a, C> TryFrom<&'a OwnedDocument> for CollectionDocument<C>where C: SerializedCollection,
§fn try_from(
value: &'a OwnedDocument
) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a OwnedDocument>>::Error>
fn try_from( value: &'a OwnedDocument ) -> Result<CollectionDocument<C>, <CollectionDocument<C> as TryFrom<&'a OwnedDocument>>::Error>
§impl<'a, 'b, C> TryFrom<&'b CollectionDocument<C>> for BorrowedDocument<'a>where
C: SerializedCollection,
impl<'a, 'b, C> TryFrom<&'b CollectionDocument<C>> for BorrowedDocument<'a>where C: SerializedCollection,
§fn try_from(
value: &'b CollectionDocument<C>
) -> Result<BorrowedDocument<'a>, <BorrowedDocument<'a> as TryFrom<&'b CollectionDocument<C>>>::Error>
fn try_from( value: &'b CollectionDocument<C> ) -> Result<BorrowedDocument<'a>, <BorrowedDocument<'a> as TryFrom<&'b CollectionDocument<C>>>::Error>
§impl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, <C as Collection>::PrimaryKey>where
C: SerializedCollection,
impl<'a, 'c, C> TryFrom<&'c CollectionDocument<C>> for NamedReference<'a, <C as Collection>::PrimaryKey>where C: SerializedCollection,
§fn try_from(
doc: &'c CollectionDocument<C>
) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
fn try_from( doc: &'c CollectionDocument<C> ) -> Result<NamedReference<'a, <C as Collection>::PrimaryKey>, Error>
impl<C> Eq for CollectionDocument<C>where C: Eq + SerializedCollection, <C as Collection>::PrimaryKey: Eq, <C as SerializedCollection>::Contents: Eq,
impl<C> StructuralEq for CollectionDocument<C>where C: SerializedCollection,
impl<C> StructuralPartialEq for CollectionDocument<C>where C: SerializedCollection,
Auto Trait Implementations§
impl<C> RefUnwindSafe for CollectionDocument<C>where <C as SerializedCollection>::Contents: RefUnwindSafe, <C as Collection>::PrimaryKey: RefUnwindSafe,
impl<C> Send for CollectionDocument<C>
impl<C> Sync for CollectionDocument<C>
impl<C> Unpin for CollectionDocument<C>where <C as SerializedCollection>::Contents: Unpin, <C as Collection>::PrimaryKey: Unpin,
impl<C> UnwindSafe for CollectionDocument<C>where <C as SerializedCollection>::Contents: UnwindSafe, <C as Collection>::PrimaryKey: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.