Struct automerge::transaction::Transaction
source · pub struct Transaction<'a> { /* private fields */ }
Expand description
A transaction on a document. Transactions group operations into a single change so that no other operations can happen in-between.
Created from Automerge::transaction
.
Drop
This transaction should be manually committed or rolled back. If not done manually then it will
be rolled back when it is dropped. This is to prevent the document being in an unsafe
intermediate state.
This is consistent with ?
error handling.
Implementations§
source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
sourcepub fn hash_for_opid(&self, opid: &ExId) -> Option<ChangeHash>
pub fn hash_for_opid(&self, opid: &ExId) -> Option<ChangeHash>
Get the hash of the change that contains the given opid.
Returns none if the opid:
- is the root object id
- does not exist in this document
- is for an operation in this transaction
source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
sourcepub fn get_heads(&self) -> Vec<ChangeHash>
pub fn get_heads(&self) -> Vec<ChangeHash>
Get the heads of the document before this transaction was started.
sourcepub fn commit(self) -> (Option<ChangeHash>, PatchLog)
pub fn commit(self) -> (Option<ChangeHash>, PatchLog)
Commit the operations performed in this transaction, returning the hashes corresponding to the new heads.
sourcepub fn commit_with(
self,
options: CommitOptions
) -> (Option<ChangeHash>, PatchLog)
pub fn commit_with( self, options: CommitOptions ) -> (Option<ChangeHash>, PatchLog)
Commit the operations in this transaction with some options.
let mut doc = Automerge::new();
let mut tx = doc.transaction();
tx.put_object(ROOT, "todos", ObjType::List).unwrap();
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as
i64;
tx.commit_with(CommitOptions::default().with_message("Create todos list").with_time(now));
Trait Implementations§
source§impl<'a> Debug for Transaction<'a>
impl<'a> Debug for Transaction<'a>
source§impl<'a> Drop for Transaction<'a>
impl<'a> Drop for Transaction<'a>
source§impl<'a> ReadDoc for Transaction<'a>
impl<'a> ReadDoc for Transaction<'a>
source§fn keys<O: AsRef<ExId>>(&self, obj: O) -> Keys<'_> ⓘ
fn keys<O: AsRef<ExId>>(&self, obj: O) -> Keys<'_> ⓘ
obj
. Read moresource§fn map_range<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>(
&'b self,
obj: O,
range: R
) -> MapRange<'b, R> ⓘ
fn map_range<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>( &'b self, obj: O, range: R ) -> MapRange<'b, R> ⓘ
obj
in the given range. Read moresource§fn map_range_at<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>(
&'b self,
obj: O,
range: R,
heads: &[ChangeHash]
) -> MapRange<'b, R> ⓘ
fn map_range_at<'b, O: AsRef<ExId>, R: RangeBounds<String> + 'b>( &'b self, obj: O, range: R, heads: &[ChangeHash] ) -> MapRange<'b, R> ⓘ
source§fn list_range<O: AsRef<ExId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R
) -> ListRange<'_, R> ⓘ
fn list_range<O: AsRef<ExId>, R: RangeBounds<usize>>( &self, obj: O, range: R ) -> ListRange<'_, R> ⓘ
obj
in the given range. Read moresource§fn list_range_at<O: AsRef<ExId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
heads: &[ChangeHash]
) -> ListRange<'_, R> ⓘ
fn list_range_at<O: AsRef<ExId>, R: RangeBounds<usize>>( &self, obj: O, range: R, heads: &[ChangeHash] ) -> ListRange<'_, R> ⓘ
obj
in the given range as at heads
Read moresource§fn values<O: AsRef<ExId>>(&self, obj: O) -> Values<'_> ⓘ
fn values<O: AsRef<ExId>>(&self, obj: O) -> Values<'_> ⓘ
source§fn values_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
fn values_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> Values<'_> ⓘ
heads
Read moresource§fn length<O: AsRef<ExId>>(&self, obj: O) -> usize
fn length<O: AsRef<ExId>>(&self, obj: O) -> usize
source§fn length_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> usize
fn length_at<O: AsRef<ExId>>(&self, obj: O, heads: &[ChangeHash]) -> usize
heads
Read moresource§fn object_type<O: AsRef<ExId>>(&self, obj: O) -> Result<ObjType, AutomergeError>
fn object_type<O: AsRef<ExId>>(&self, obj: O) -> Result<ObjType, AutomergeError>
source§fn text<O: AsRef<ExId>>(&self, obj: O) -> Result<String, AutomergeError>
fn text<O: AsRef<ExId>>(&self, obj: O) -> Result<String, AutomergeError>
source§fn text_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash]
) -> Result<String, AutomergeError>
fn text_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash] ) -> Result<String, AutomergeError>
heads
, see
Self::text
source§fn get_cursor<O: AsRef<ExId>>(
&self,
obj: O,
position: usize,
at: Option<&[ChangeHash]>
) -> Result<Cursor, AutomergeError>
fn get_cursor<O: AsRef<ExId>>( &self, obj: O, position: usize, at: Option<&[ChangeHash]> ) -> Result<Cursor, AutomergeError>
usize
position in a Sequence (either Self::List
or Self::Text
). Read moresource§fn get_cursor_position<O: AsRef<ExId>>(
&self,
obj: O,
address: &Cursor,
at: Option<&[ChangeHash]>
) -> Result<usize, AutomergeError>
fn get_cursor_position<O: AsRef<ExId>>( &self, obj: O, address: &Cursor, at: Option<&[ChangeHash]> ) -> Result<usize, AutomergeError>
usize
. Read moresource§fn marks<O: AsRef<ExId>>(&self, obj: O) -> Result<Vec<Mark<'_>>, AutomergeError>
fn marks<O: AsRef<ExId>>(&self, obj: O) -> Result<Vec<Mark<'_>>, AutomergeError>
source§fn marks_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash]
) -> Result<Vec<Mark<'_>>, AutomergeError>
fn marks_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash] ) -> Result<Vec<Mark<'_>>, AutomergeError>
fn get_marks<O: AsRef<ExId>>( &self, obj: O, index: usize, heads: Option<&[ChangeHash]> ) -> Result<MarkSet, AutomergeError>
source§fn get<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
source§fn get_at<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash]
) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
fn get_at<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, heads: &[ChangeHash] ) -> Result<Option<(Value<'_>, ExId)>, AutomergeError>
heads
, see [Self::get]
source§fn get_all<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
source§fn get_all_at<O: AsRef<ExId>, P: Into<Prop>>(
&self,
obj: O,
prop: P,
heads: &[ChangeHash]
) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
fn get_all_at<O: AsRef<ExId>, P: Into<Prop>>( &self, obj: O, prop: P, heads: &[ChangeHash] ) -> Result<Vec<(Value<'_>, ExId)>, AutomergeError>
heads
Read moresource§fn parents<O: AsRef<ExId>>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
fn parents<O: AsRef<ExId>>(&self, obj: O) -> Result<Parents<'_>, AutomergeError>
source§fn parents_at<O: AsRef<ExId>>(
&self,
obj: O,
heads: &[ChangeHash]
) -> Result<Parents<'_>, AutomergeError>
fn parents_at<O: AsRef<ExId>>( &self, obj: O, heads: &[ChangeHash] ) -> Result<Parents<'_>, AutomergeError>
source§fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
fn get_missing_deps(&self, heads: &[ChangeHash]) -> Vec<ChangeHash>
heads
.source§fn get_change_by_hash(&self, hash: &ChangeHash) -> Option<&Change>
fn get_change_by_hash(&self, hash: &ChangeHash) -> Option<&Change>
source§impl<'a> Transactable for Transaction<'a>
impl<'a> Transactable for Transaction<'a>
source§fn pending_ops(&self) -> usize
fn pending_ops(&self) -> usize
Get the number of pending operations in this transaction.
source§fn put<O: AsRef<ExId>, P: Into<Prop>, V: Into<ScalarValue>>(
&mut self,
obj: O,
prop: P,
value: V
) -> Result<(), AutomergeError>
fn put<O: AsRef<ExId>, P: Into<Prop>, V: Into<ScalarValue>>( &mut self, obj: O, prop: P, value: V ) -> Result<(), AutomergeError>
Set the value of property P
to value V
in object obj
.
Errors
This will return an error if
- The object does not exist
- The key is the wrong type for the object
- The key does not exist in the object
source§fn splice<O: AsRef<ExId>, V: IntoIterator<Item = ScalarValue>>(
&mut self,
obj: O,
pos: usize,
del: isize,
vals: V
) -> Result<(), AutomergeError>
fn splice<O: AsRef<ExId>, V: IntoIterator<Item = ScalarValue>>( &mut self, obj: O, pos: usize, del: isize, vals: V ) -> Result<(), AutomergeError>
Splice new elements into the given sequence. Returns a vector of the OpIds used to insert the new elements
source§fn put_object<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P,
value: ObjType
) -> Result<ExId, AutomergeError>
fn put_object<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P, value: ObjType ) -> Result<ExId, AutomergeError>
source§fn insert<O: AsRef<ExId>, V: Into<ScalarValue>>(
&mut self,
obj: O,
index: usize,
value: V
) -> Result<(), AutomergeError>
fn insert<O: AsRef<ExId>, V: Into<ScalarValue>>( &mut self, obj: O, index: usize, value: V ) -> Result<(), AutomergeError>
source§fn insert_object<O: AsRef<ExId>>(
&mut self,
obj: O,
index: usize,
value: ObjType
) -> Result<ExId, AutomergeError>
fn insert_object<O: AsRef<ExId>>( &mut self, obj: O, index: usize, value: ObjType ) -> Result<ExId, AutomergeError>
source§fn increment<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P,
value: i64
) -> Result<(), AutomergeError>
fn increment<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P, value: i64 ) -> Result<(), AutomergeError>
value
.source§fn delete<O: AsRef<ExId>, P: Into<Prop>>(
&mut self,
obj: O,
prop: P
) -> Result<(), AutomergeError>
fn delete<O: AsRef<ExId>, P: Into<Prop>>( &mut self, obj: O, prop: P ) -> Result<(), AutomergeError>
source§fn splice_text<O: AsRef<ExId>>(
&mut self,
obj: O,
pos: usize,
del: isize,
text: &str
) -> Result<(), AutomergeError>
fn splice_text<O: AsRef<ExId>>( &mut self, obj: O, pos: usize, del: isize, text: &str ) -> Result<(), AutomergeError>
Self::splice
but for text.