Add session::sd() SQL function for retrieving session auth data

This commit is contained in:
Tobie Morgan Hitchcock 2022-09-05 00:56:23 +01:00
parent 491806aa75
commit 10f01f365f
4 changed files with 9 additions and 0 deletions

View file

@ -133,6 +133,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
"session::ns" => 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),

View file

@ -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<Value>) -> Result<Value, Error> {
@ -31,3 +32,7 @@ pub fn origin(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
pub fn sc(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
ctx.value("session").unwrap_or(&Value::None).pick(SC.as_ref()).ok()
}
pub fn sd(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
ctx.value("session").unwrap_or(&Value::None).pick(SD.as_ref()).ok()
}

View file

@ -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)
}

View file

@ -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")]);