reifydb_routine/procedure/identity/
inject.rs1use std::sync::LazyLock;
5
6use reifydb_core::value::column::{ColumnWithName, buffer::ColumnBuffer, columns::Columns};
7use reifydb_type::{
8 fragment::Fragment,
9 params::Params,
10 value::{Value, r#type::Type},
11};
12
13use crate::routine::{Routine, RoutineInfo, context::ProcedureContext, error::RoutineError};
14
15static INFO: LazyLock<RoutineInfo> = LazyLock::new(|| RoutineInfo::new("identity::inject"));
16
17pub struct IdentityInject;
18
19impl Default for IdentityInject {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24
25impl IdentityInject {
26 pub fn new() -> Self {
27 Self
28 }
29}
30
31impl<'a, 'tx> Routine<ProcedureContext<'a, 'tx>> for IdentityInject {
32 fn info(&self) -> &RoutineInfo {
33 &INFO
34 }
35
36 fn return_type(&self, _input_types: &[Type]) -> Type {
37 Type::IdentityId
38 }
39
40 fn execute(&self, ctx: &mut ProcedureContext<'a, 'tx>, _args: &Columns) -> Result<Columns, RoutineError> {
41 let identity_id = match ctx.params {
42 Params::Positional(args) if args.len() == 1 => match &args[0] {
43 Value::IdentityId(id) => *id,
44 other => {
45 return Err(RoutineError::ProcedureInvalidArgumentType {
46 procedure: Fragment::internal("identity::inject"),
47 argument_index: 0,
48 expected: vec![Type::IdentityId],
49 actual: other.get_type(),
50 });
51 }
52 },
53 Params::Positional(args) => {
54 return Err(RoutineError::ProcedureArityMismatch {
55 procedure: Fragment::internal("identity::inject"),
56 expected: 1,
57 actual: args.len(),
58 });
59 }
60 _ => {
61 return Err(RoutineError::ProcedureArityMismatch {
62 procedure: Fragment::internal("identity::inject"),
63 expected: 1,
64 actual: 0,
65 });
66 }
67 };
68
69 let col = ColumnWithName::new("identity_id", ColumnBuffer::identity_id(vec![identity_id]));
70 Ok(Columns::new(vec![col]))
71 }
72}