reifydb_core/interface/transaction/
single.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use async_trait::async_trait;
5
6use crate::{
7	EncodedKey,
8	interface::{SingleVersionValues, WithEventBus},
9	value::encoded::EncodedValues,
10};
11
12#[async_trait]
13pub trait SingleVersionTransaction: WithEventBus + Send + Sync + Clone + 'static {
14	type Query<'a>: SingleVersionQueryTransaction + Send;
15	type Command<'a>: SingleVersionCommandTransaction + Send;
16
17	async fn begin_query<'a, I>(&self, keys: I) -> crate::Result<Self::Query<'_>>
18	where
19		I: IntoIterator<Item = &'a EncodedKey> + Send;
20
21	async fn begin_command<'a, I>(&self, keys: I) -> crate::Result<Self::Command<'_>>
22	where
23		I: IntoIterator<Item = &'a EncodedKey> + Send;
24}
25
26/// Single-version query transaction trait.
27/// Uses tokio::sync locks which are Send-safe with owned guards.
28#[async_trait]
29pub trait SingleVersionQueryTransaction: Send {
30	async fn get(&mut self, key: &EncodedKey) -> crate::Result<Option<SingleVersionValues>>;
31
32	async fn contains_key(&mut self, key: &EncodedKey) -> crate::Result<bool>;
33}
34
35/// Single-version command transaction trait.
36/// Uses tokio::sync locks which are Send-safe with owned guards.
37#[async_trait]
38pub trait SingleVersionCommandTransaction: SingleVersionQueryTransaction + Send {
39	fn set(&mut self, key: &EncodedKey, row: EncodedValues) -> crate::Result<()>;
40
41	async fn remove(&mut self, key: &EncodedKey) -> crate::Result<()>;
42
43	async fn commit(&mut self) -> crate::Result<()>;
44
45	async fn rollback(&mut self) -> crate::Result<()>;
46}