pub struct AppTransaction { /* private fields */ }Expand description
A canonical transaction: operations and preconditions the application contract validates and authorizes, committed atomically.
Implementations§
Source§impl AppTransaction
impl AppTransaction
Sourcepub fn new(transaction_id: impl Into<String>) -> Self
pub fn new(transaction_id: impl Into<String>) -> Self
A transaction with this identity; resubmitting it after an uncertain outcome is safe.
pub fn id(&self) -> &str
Sourcepub fn insert(
self,
collection: impl Into<String>,
id: impl Into<String>,
value: Value,
) -> Self
pub fn insert( self, collection: impl Into<String>, id: impl Into<String>, value: Value, ) -> Self
Create a record that must not exist.
Sourcepub fn update(
self,
collection: impl Into<String>,
id: impl Into<String>,
value: Value,
) -> Self
pub fn update( self, collection: impl Into<String>, id: impl Into<String>, value: Value, ) -> Self
Write a record.
pub fn delete( self, collection: impl Into<String>, id: impl Into<String>, ) -> Self
Sourcepub fn update_if_version(
self,
collection: impl Into<String>,
id: impl Into<String>,
value: Value,
version: u64,
) -> Self
pub fn update_if_version( self, collection: impl Into<String>, id: impl Into<String>, value: Value, version: u64, ) -> Self
Merge value into a record only if its __version is still version. Refused with
PRECONDITION_FAILED otherwise; nothing in the transaction is written.
Sourcepub fn delete_if_version(
self,
collection: impl Into<String>,
id: impl Into<String>,
version: u64,
) -> Self
pub fn delete_if_version( self, collection: impl Into<String>, id: impl Into<String>, version: u64, ) -> Self
Delete a record only if its __version is still version. With an
AppTransaction::insert of the same id after it, an atomic, fenced replace.
Sourcepub fn operation(self, operation: TransactionOperation) -> Self
pub fn operation(self, operation: TransactionOperation) -> Self
Any operation of the canonical contract, as the wire document states it.
Sourcepub fn precondition(self, precondition: TransactionPrecondition) -> Self
pub fn precondition(self, precondition: TransactionPrecondition) -> Self
Any precondition of the canonical contract, e.g. a record’s __version:
let tx = AppTransaction::new("tx-1").precondition(TransactionPrecondition::Record {
collection: "Order".into(),
id: "o-1".into(),
require_absent: false,
expected_version: Some(3),
expected_epoch: None,
expected_lease_id: None,
});Sourcepub fn expect_version(
self,
collection: impl Into<String>,
id: impl Into<String>,
version: u64,
) -> Self
pub fn expect_version( self, collection: impl Into<String>, id: impl Into<String>, version: u64, ) -> Self
Commit only if the record’s __version is still version.
Sourcepub fn expect_absent(
self,
collection: impl Into<String>,
id: impl Into<String>,
) -> Self
pub fn expect_absent( self, collection: impl Into<String>, id: impl Into<String>, ) -> Self
Commit only if the record does not exist.
Sourcepub fn fence(self, basis: ReadBasis) -> Self
pub fn fence(self, basis: ReadBasis) -> Self
Commit only if the state basis covers is unchanged since Application::read_basis.