From 10f01f365fc125029c1cd08f523b8d3aa58e315a Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 5 Sep 2022 00:56:23 +0100 Subject: [PATCH] Add session::sd() SQL function for retrieving session auth data --- lib/src/fnc/mod.rs | 1 + lib/src/fnc/session.rs | 5 +++++ lib/src/sql/function.rs | 1 + lib/src/sql/paths.rs | 2 ++ 4 files changed, 9 insertions(+) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index 79972645..24b0f412 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -133,6 +133,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result args::check(ctx, name, args, Args::None, session::ns), "session::origin" => args::check(ctx, name, args, Args::None, session::origin), "session::sc" => args::check(ctx, name, args, Args::None, session::sc), + "session::sd" => args::check(ctx, name, args, Args::None, session::sd), // "string::concat" => args::check(ctx, name, args, Args::Any, string::concat), "string::endsWith" => args::check(ctx, name, args, Args::Two, string::ends_with), diff --git a/lib/src/fnc/session.rs b/lib/src/fnc/session.rs index 8343b295..e00da6db 100644 --- a/lib/src/fnc/session.rs +++ b/lib/src/fnc/session.rs @@ -6,6 +6,7 @@ use crate::sql::paths::IP; use crate::sql::paths::NS; use crate::sql::paths::OR; use crate::sql::paths::SC; +use crate::sql::paths::SD; use crate::sql::value::Value; pub fn db(ctx: &Context, _: Vec) -> Result { @@ -31,3 +32,7 @@ pub fn origin(ctx: &Context, _: Vec) -> Result { pub fn sc(ctx: &Context, _: Vec) -> Result { ctx.value("session").unwrap_or(&Value::None).pick(SC.as_ref()).ok() } + +pub fn sd(ctx: &Context, _: Vec) -> Result { + ctx.value("session").unwrap_or(&Value::None).pick(SD.as_ref()).ok() +} diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 1fa593cf..54f45502 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -393,6 +393,7 @@ fn function_session(i: &str) -> IResult<&str, &str> { tag("session::ns"), tag("session::origin"), tag("session::sc"), + tag("session::sd"), ))(i) } diff --git a/lib/src/sql/paths.rs b/lib/src/sql/paths.rs index 0d833425..cc12cb32 100644 --- a/lib/src/sql/paths.rs +++ b/lib/src/sql/paths.rs @@ -11,6 +11,8 @@ pub static DB: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("db")]); pub static SC: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("sc")]); +pub static SD: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("sd")]); + pub static OR: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("or")]); pub static IN: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("in")]);