pub struct CosmosSaga { /* private fields */ }Expand description
A CosmosSaga represents a transaction to CosmosDB. Modifications made with the saga can be
aborted with abort() and will then be reverted. They will also automatically be reverted if
any error occurs.
Implementations§
Source§impl CosmosSaga
impl CosmosSaga
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new saga object which can be used to perform several cosmos operations in sequence. If any operation fails then all previous operations performed with the saga object will be reversed.
pub async fn delete<D: DeserializeOwned + ErasedCosmosEntity<Entity = String> + Send + Sync + 'static, C: ToString + Clone, S: ToString + Clone, P: Into<PartitionKeyIntermediate> + Clone>( &mut self, collection_name: C, pk: P, document_id: S, etag: Option<String>, ) -> Result<(), CosmosErrorStruct>
pub async fn modify<D: DeserializeOwned + ErasedCosmosEntity<Entity = String> + CosmosObject + Clone + Send + Sync + 'static, P: Into<PartitionKeyIntermediate> + Clone, F: Fn(D) -> Fut, C: ToString + Clone, S: ToString + Clone, Fut: Future<Output = Result<D, Rejection>>>( &mut self, collection_name: C, pk: P, document_id: S, transform: F, ) -> Result<D, CosmosErrorStruct>
pub async fn upsert<'de, D: CosmosObject + ErasedCosmosEntity<Entity = String> + DeserializeOwned + Send + Sync + 'static, P: Into<PartitionKeyIntermediate> + Clone, I: ToString, C: ToString + Clone>( &mut self, collection_name: C, pk: P, document: &'de D, document_id: I, etag: Option<&String>, ) -> Result<String, CosmosErrorStruct>
pub async fn insert<'de, D: CosmosObject + DeserializeOwned + Send + Sync + 'static, P: Into<PartitionKeyIntermediate> + Clone, I: ToString, C: ToString + Clone>( &mut self, collection_name: C, pk: P, document: &'de D, document_id: I, etag: Option<&String>, ) -> Result<String, CosmosErrorStruct>
Sourcepub async fn abort(&mut self) -> Result<(), CosmosErrorStruct>
pub async fn abort(&mut self) -> Result<(), CosmosErrorStruct>
Aborts the saga and reverses all of the operations that have been made previously with this saga.
Sourcepub async fn finalize(self)
pub async fn finalize(self)
Consumes the saga and makes adding new things to it impossible This currently does no execution but is async in order to allow async operations to be done here in the future. Currently sagas are eagerly executed, meaning that the operations is performed when the method is called.