reifydb_engine/procedure/system/
set_config.rs1use reifydb_core::{internal_error, value::column::columns::Columns};
5use reifydb_transaction::transaction::Transaction;
6use reifydb_type::{Result, params::Params, value::Value};
7
8use super::super::{Procedure, context::ProcedureContext};
9
10pub struct SetConfigProcedure;
14
15impl SetConfigProcedure {
16 pub fn new() -> Self {
17 Self
18 }
19}
20
21impl Procedure for SetConfigProcedure {
22 fn call(&self, ctx: &ProcedureContext, tx: &mut Transaction<'_>) -> Result<Columns> {
23 let (key, value) = match ctx.params {
24 Params::Positional(args) if args.len() == 2 => (args[0].clone(), args[1].clone()),
25 _ => {
26 return Err(internal_error!(
27 "system::config::set requires exactly 2 positional arguments"
28 ));
29 }
30 };
31
32 let key_str = match &key {
33 Value::Utf8(s) => s.as_str().to_string(),
34 _ => {
35 return Err(internal_error!("system::config::set: first argument (key) must be Utf8"));
36 }
37 };
38
39 let value_clone = value.clone();
40
41 match tx {
42 Transaction::Admin(admin) => ctx.catalog.set_config(admin, &key_str, value)?,
43 _ => {
44 return Err(internal_error!("system::config::set must run in a write transaction"));
45 }
46 }
47
48 Ok(Columns::single_row([("key", Value::Utf8(key_str)), ("value", value_clone)]))
49 }
50}