Struct bonsaidb::core::transaction::Operation
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§
§impl Operation
impl Operation
pub fn insert(
collection: CollectionName,
id: Option<DocumentId>,
contents: impl Into<Bytes>
) -> Operation
pub fn insert( collection: CollectionName, id: Option<DocumentId>, contents: impl Into<Bytes> ) -> Operation
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.
pub fn insert_serialized<C>(
id: Option<&<C as Collection>::PrimaryKey>,
contents: &<C as SerializedCollection>::Contents
) -> Result<Operation, Error>where
C: SerializedCollection,
pub fn insert_serialized<C>( id: Option<&<C as Collection>::PrimaryKey>, contents: &<C as SerializedCollection>::Contents ) -> Result<Operation, Error>where C: SerializedCollection,
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.
pub fn push_serialized<C>(
contents: &<C as SerializedCollection>::Contents
) -> Result<Operation, Error>where
C: SerializedCollection,
pub fn push_serialized<C>( contents: &<C as SerializedCollection>::Contents ) -> Result<Operation, Error>where C: SerializedCollection,
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.
pub fn update(
collection: CollectionName,
header: Header,
contents: impl Into<Bytes>
) -> Operation
pub fn update( collection: CollectionName, header: Header, contents: impl Into<Bytes> ) -> Operation
Updates a document in collection
.
pub fn update_serialized<C>(
header: CollectionHeader<<C as Collection>::PrimaryKey>,
contents: &<C as SerializedCollection>::Contents
) -> Result<Operation, Error>where
C: SerializedCollection,
pub fn update_serialized<C>( header: CollectionHeader<<C as Collection>::PrimaryKey>, contents: &<C as SerializedCollection>::Contents ) -> Result<Operation, Error>where C: SerializedCollection,
Updates a document with the serialized representation of contents
in
collection
.
pub fn overwrite(
collection: CollectionName,
id: DocumentId,
contents: impl Into<Bytes>
) -> Operation
pub fn overwrite( collection: CollectionName, id: DocumentId, contents: impl Into<Bytes> ) -> Operation
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.
pub fn overwrite_serialized<C, Key>(
id: &Key,
contents: &<C as SerializedCollection>::Contents
) -> Result<Operation, Error>where
C: SerializedCollection,
Key: KeyEncoding<<C as Collection>::PrimaryKey> + ?Sized,
pub fn overwrite_serialized<C, Key>( id: &Key, contents: &<C as SerializedCollection>::Contents ) -> Result<Operation, Error>where C: SerializedCollection, Key: KeyEncoding<<C as Collection>::PrimaryKey> + ?Sized,
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.
pub const fn delete(collection: CollectionName, header: Header) -> Operation
pub const fn delete(collection: CollectionName, header: Header) -> Operation
Deletes a document from a collection
.
pub const fn check_document_id_exists(
collection: CollectionName,
id: DocumentId
) -> Operation
pub const fn check_document_id_exists( collection: CollectionName, id: DocumentId ) -> Operation
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.
pub fn check_document_exists<C>(
id: &<C as Collection>::PrimaryKey
) -> Result<Operation, Error>where
C: Collection,
pub fn check_document_exists<C>( id: &<C as Collection>::PrimaryKey ) -> Result<Operation, Error>where C: Collection,
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.
pub fn check_document_is_current<C, H>(
doc_or_header: &H
) -> Result<Operation, Error>where
C: Collection,
H: HasHeader,
pub fn check_document_is_current<C, H>( doc_or_header: &H ) -> Result<Operation, Error>where C: Collection, H: HasHeader,
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.