Skip to main content

reifydb_routine/routine/
context.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_catalog::catalog::Catalog;
5use reifydb_core::util::ioc::IocContainer;
6use reifydb_runtime::context::RuntimeContext;
7use reifydb_transaction::transaction::Transaction;
8use reifydb_type::{fragment::Fragment, params::Params, value::identity::IdentityId};
9
10use super::{Context, sealed};
11
12/// Execution context for a function.
13///
14/// A function impl writes `impl Routine<FunctionContext> for Foo`. The trait's
15/// `execute` signature has no way to receive `&mut Transaction`, so a function
16/// is guaranteed at the type level to be unable to mutate transactional state.
17///
18/// Functions don't get `catalog`/`ioc`  - they're pure operations on column
19/// data. If a future "function" needs catalog access, it should be a
20/// procedure instead.
21pub struct FunctionContext<'a> {
22	pub fragment: Fragment,
23	pub identity: IdentityId,
24	pub row_count: usize,
25	pub runtime_context: &'a RuntimeContext,
26}
27
28impl sealed::Sealed for FunctionContext<'_> {}
29impl Context for FunctionContext<'_> {}
30
31/// Execution context for a procedure.
32///
33/// A procedure impl writes `impl Routine<ProcedureContext> for Foo`. The
34/// transaction is reachable via `ctx.tx`. Procedures get the catalog and the
35/// IOC container in addition to the shared facets, plus access to user-supplied
36/// parameters as the legacy `Params` view.
37pub struct ProcedureContext<'a, 'tx> {
38	pub fragment: Fragment,
39	pub identity: IdentityId,
40	pub row_count: usize,
41	pub runtime_context: &'a RuntimeContext,
42	pub tx: &'a mut Transaction<'tx>,
43	pub params: &'a Params,
44	pub catalog: &'a Catalog,
45	pub ioc: &'a IocContainer,
46}
47
48impl sealed::Sealed for ProcedureContext<'_, '_> {}
49impl Context for ProcedureContext<'_, '_> {}