Struct bonsaidb_core::transaction::Operation
source · pub struct Operation {
pub collection: CollectionName,
pub command: Command,
}
Expand description
A single operation performed on a Collection
.
Fields§
§collection: CollectionName
The id of the Collection
.
command: Command
The command being performed.
Implementations§
source§impl Operation
impl Operation
sourcepub fn insert(
collection: CollectionName,
id: Option<DocumentId>,
contents: impl Into<Bytes>
) -> Self
pub fn insert( collection: CollectionName, id: Option<DocumentId>, contents: impl Into<Bytes> ) -> Self
Inserts a new document with contents
into collection
. If id
is
None
a unique id will be generated. If an id is provided and a
document already exists with that id, a conflict error will be returned.
sourcepub fn insert_serialized<C: SerializedCollection>(
id: Option<&C::PrimaryKey>,
contents: &C::Contents
) -> Result<Self, Error>
pub fn insert_serialized<C: SerializedCollection>( id: Option<&C::PrimaryKey>, contents: &C::Contents ) -> Result<Self, Error>
Inserts a new document with the serialized representation of contents
into collection
. If id
is None
a unique id will be generated. If
an id is provided and a document already exists with that id, a conflict
error will be returned.
sourcepub fn push_serialized<C: SerializedCollection>(
contents: &C::Contents
) -> Result<Self, Error>
pub fn push_serialized<C: SerializedCollection>( contents: &C::Contents ) -> Result<Self, Error>
Pushes a new document with the serialized representation of contents
into collection
.
Automatic ID Assignment
This function calls SerializedCollection::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.
sourcepub fn update(
collection: CollectionName,
header: Header,
contents: impl Into<Bytes>
) -> Self
pub fn update( collection: CollectionName, header: Header, contents: impl Into<Bytes> ) -> Self
Updates a document in collection
.
sourcepub fn update_serialized<C: SerializedCollection>(
header: CollectionHeader<C::PrimaryKey>,
contents: &C::Contents
) -> Result<Self, Error>
pub fn update_serialized<C: SerializedCollection>( header: CollectionHeader<C::PrimaryKey>, contents: &C::Contents ) -> Result<Self, Error>
Updates a document with the serialized representation of contents
in
collection
.
sourcepub fn overwrite(
collection: CollectionName,
id: DocumentId,
contents: impl Into<Bytes>
) -> Self
pub fn overwrite( collection: CollectionName, id: DocumentId, contents: impl Into<Bytes> ) -> Self
Overwrites a document in collection
. If a document with id
exists,
it will be overwritten. If a document with id
doesn’t exist, it will
be created.
sourcepub fn overwrite_serialized<C: SerializedCollection, Key>(
id: &Key,
contents: &C::Contents
) -> Result<Self, Error>
pub fn overwrite_serialized<C: SerializedCollection, Key>( id: &Key, contents: &C::Contents ) -> Result<Self, Error>
Overwrites a document with the serialized representation of contents
in collection
. If a document with id
exists, it will be overwritten.
If a document with id
doesn’t exist, it will be created.
sourcepub const fn delete(collection: CollectionName, header: Header) -> Self
pub const fn delete(collection: CollectionName, header: Header) -> Self
Deletes a document from a collection
.
sourcepub const fn check_document_id_exists(
collection: CollectionName,
id: DocumentId
) -> Self
pub const fn check_document_id_exists( collection: CollectionName, id: DocumentId ) -> Self
Check that the document id
still exists in collection
. If a document
with that id is not present, the transaction will not be applied and
Error::DocumentNotFound
will be returned.
Upon success, OperationResult::Success
will be included in the
transaction’s results.
sourcepub fn check_document_exists<C: Collection>(
id: &C::PrimaryKey
) -> Result<Self, Error>
pub fn check_document_exists<C: Collection>( id: &C::PrimaryKey ) -> Result<Self, Error>
Check that the document id
still exists in Collection
C
. If a
document with that id is not present, the transaction will not be
applied and Error::DocumentNotFound
will be returned.
Upon success, OperationResult::Success
will be included in the
transaction’s results.
sourcepub fn check_document_is_current<C: Collection, H: HasHeader>(
doc_or_header: &H
) -> Result<Self, Error>
pub fn check_document_is_current<C: Collection, H: HasHeader>( doc_or_header: &H ) -> Result<Self, Error>
Check that the header of doc_or_header
is the current revision of the
stored document in Collection
C
. If a document with the header’s
id is not present, the transaction will not be applied and
Error::DocumentNotFound
will be returned. If a document with the
header’s id is present and the revision does not match, the transaction
will not be applied and Error::DocumentConflict
will be returned.
Upon success, OperationResult::Success
will be included in the
transaction’s results.