From 0c860610862f63d3643afdb19557ff3ce9540331 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sun, 3 Jul 2022 19:22:12 +0100 Subject: [PATCH] Accept Thing as argument to type::thing SQL function --- lib/src/fnc/mod.rs | 2 +- lib/src/fnc/type.rs | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index f55e7367..c1fdfb5a 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -158,7 +158,7 @@ pub async fn run(ctx: &Context<'_>, name: &str, args: Vec) -> Result args::check(ctx, name, args, Args::One, r#type::regex), "type::string" => args::check(ctx, name, args, Args::One, r#type::string), "type::table" => args::check(ctx, name, args, Args::One, r#type::table), - "type::thing" => args::check(ctx, name, args, Args::Two, r#type::thing), + "type::thing" => args::check(ctx, name, args, Args::OneTwo, r#type::thing), // _ => unreachable!(), } diff --git a/lib/src/fnc/type.rs b/lib/src/fnc/type.rs index e1795853..f3e279ed 100644 --- a/lib/src/fnc/type.rs +++ b/lib/src/fnc/type.rs @@ -97,15 +97,24 @@ pub fn table(_: &Context, mut args: Vec) -> Result { } pub fn thing(_: &Context, mut args: Vec) -> Result { - let tb = args.remove(0); - match args.remove(0) { - Value::Thing(id) => Ok(Value::Thing(Thing { - tb: tb.as_string(), - id: id.id, - })), - id => Ok(Value::Thing(Thing { - tb: tb.as_string(), - id: id.as_string().into(), - })), + match args.len() { + 2 => { + let tb = args.remove(0); + match args.remove(0) { + Value::Thing(id) => Ok(Value::Thing(Thing { + tb: tb.as_string(), + id: id.id, + })), + id => Ok(Value::Thing(Thing { + tb: tb.as_string(), + id: id.as_string().into(), + })), + } + } + 1 => match args.remove(0) { + Value::Thing(v) => Ok(v.into()), + _ => Ok(Value::None), + }, + _ => unreachable!(), } }