Skip to main content

reifydb_runtime/context/
transaction.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use std::sync::Arc;
5
6use reifydb_value::value::identity::IdentityId;
7
8use crate::context::RuntimeContext;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct IdentityContext {
12	pub session: IdentityId,
13	pub current: IdentityId,
14}
15
16#[derive(Debug)]
17pub struct TransactionContext {
18	pub identity: IdentityContext,
19	pub runtime: RuntimeContext,
20}
21
22impl TransactionContext {
23	pub fn new(identity: IdentityId, runtime: RuntimeContext) -> Self {
24		Self {
25			identity: IdentityContext {
26				session: identity,
27				current: identity,
28			},
29			runtime,
30		}
31	}
32
33	pub fn system(runtime: RuntimeContext) -> Self {
34		Self::new(IdentityId::system(), runtime)
35	}
36
37	pub fn with_current(self: &Arc<Self>, id: IdentityId) -> Arc<Self> {
38		Arc::new(Self {
39			identity: IdentityContext {
40				session: self.identity.session,
41				current: id,
42			},
43			runtime: self.runtime.clone(),
44		})
45	}
46}