reifydb_core/interface/transaction/
mod.rs1mod cdc;
5mod change;
6pub mod interceptor;
7mod multi;
8mod single;
9mod transaction;
10
11use std::{
12 fmt::{Display, Formatter},
13 ops::Deref,
14};
15
16pub use cdc::{CdcQueryTransaction, CdcTransaction};
17pub use change::*;
18pub use multi::*;
19use reifydb_type::{Error, Uuid7, return_internal_error};
20pub use single::*;
21pub use transaction::{CommandTransaction, QueryTransaction};
22
23#[repr(transparent)]
26#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
27pub struct TransactionId(pub(crate) Uuid7);
28
29impl Default for TransactionId {
30 fn default() -> Self {
31 Self::generate()
32 }
33}
34
35impl Deref for TransactionId {
36 type Target = Uuid7;
37
38 fn deref(&self) -> &Self::Target {
39 &self.0
40 }
41}
42
43impl TransactionId {
44 pub fn generate() -> Self {
45 Self(Uuid7::generate())
46 }
47}
48
49impl TryFrom<&[u8]> for TransactionId {
50 type Error = Error;
51
52 fn try_from(bytes: &[u8]) -> std::result::Result<Self, Self::Error> {
53 if bytes.len() != 16 {
54 return_internal_error!("Invalid transaction ID length: expected 16 bytes, got {}", bytes.len());
55 }
56 let mut uuid_bytes = [0u8; 16];
57 uuid_bytes.copy_from_slice(bytes);
58 let uuid = uuid::Uuid::from_bytes(uuid_bytes);
59 Ok(Self(Uuid7::from(uuid)))
60 }
61}
62
63impl Display for TransactionId {
64 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
65 write!(f, "{}", self.0)
66 }
67}