pub struct ClawTransaction<'c> { /* private fields */ }Expand description
A wrapper around a SQLite transaction with deferred cache operations.
Obtain a ClawTransaction via ClawTransaction::begin or
ClawEngine::transaction. Call ClawTransaction::commit to
persist changes or allow the value to be dropped to trigger an implicit
rollback.
Cache mutations that should be applied after a successful commit can be
registered with ClawTransaction::stage and retrieved afterwards with
ClawTransaction::pending_cache_ops.
§Example
let mut tx = engine.transaction().await?;
let r = MemoryRecord::new("hello", MemoryType::Semantic, vec![], None);
tx.insert_memory(&r).await?;
tx.commit().await?;Implementations§
Source§impl<'c> ClawTransaction<'c>
impl<'c> ClawTransaction<'c>
Sourcepub async fn begin(engine: &'c ClawEngine) -> ClawResult<ClawTransaction<'c>>
pub async fn begin(engine: &'c ClawEngine) -> ClawResult<ClawTransaction<'c>>
Begin a new transaction against the engine’s connection pool.
§Errors
Returns ClawError::Transaction if the underlying pool cannot start
a new transaction.
Sourcepub fn stage(&mut self, op: CacheOp)
pub fn stage(&mut self, op: CacheOp)
Stage a CacheOp to be applied to an in-memory cache after a
successful commit.
Staged operations are available via ClawTransaction::pending_cache_ops.
Sourcepub fn pending_cache_ops(&self) -> &[CacheOp]
pub fn pending_cache_ops(&self) -> &[CacheOp]
Return a slice of the cache operations staged so far.
Sourcepub async fn commit(self) -> ClawResult<()>
pub async fn commit(self) -> ClawResult<()>
Commit the transaction, making all changes permanent.
All operations staged via ClawTransaction::insert_memory are
written to the database — including their FTS5 and tag-index rows —
inside the open transaction before the final commit, guaranteeing
atomicity.
§Errors
Returns ClawError::Transaction if the commit fails.
Sourcepub async fn rollback(self) -> ClawResult<()>
pub async fn rollback(self) -> ClawResult<()>
Explicitly roll back the transaction, discarding all changes.
All operations in the staging buffer are discarded without any database
writes. Any writes made directly via ClawTransaction::inner_mut
are rolled back by the underlying SQLite transaction.
§Errors
Returns ClawError::Transaction if the rollback fails.
Sourcepub fn inner_mut(&mut self) -> &mut Transaction<'c, Sqlite>
pub fn inner_mut(&mut self) -> &mut Transaction<'c, Sqlite>
Return a mutable reference to the inner SQLx transaction for use with raw SQLx queries.
Sourcepub async fn insert_memory(&mut self, record: &MemoryRecord) -> ClawResult<Uuid>
pub async fn insert_memory(&mut self, record: &MemoryRecord) -> ClawResult<Uuid>
Insert a crate::store::memory::MemoryRecord within this transaction.
Both the memories table and the memories_fts FTS5 index are updated
atomically as part of the same transaction.
§Errors
Returns a ClawError if the SQL execution fails or serialization fails.
§Example
let mut tx = engine.transaction().await?;
let r = MemoryRecord::new("transactional", MemoryType::Episodic, vec![], None);
let id = tx.insert_memory(&r).await?;
tx.commit().await?;Trait Implementations§
Auto Trait Implementations§
impl<'c> Freeze for ClawTransaction<'c>
impl<'c> !RefUnwindSafe for ClawTransaction<'c>
impl<'c> Send for ClawTransaction<'c>
impl<'c> Sync for ClawTransaction<'c>
impl<'c> Unpin for ClawTransaction<'c>
impl<'c> UnsafeUnpin for ClawTransaction<'c>
impl<'c> !UnwindSafe for ClawTransaction<'c>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more