diff --git a/lib/src/fnc/meta.rs b/lib/src/fnc/meta.rs new file mode 100644 index 00000000..59089175 --- /dev/null +++ b/lib/src/fnc/meta.rs @@ -0,0 +1,17 @@ +use crate::ctx::Context; +use crate::err::Error; +use crate::sql::value::Value; + +pub fn id(_: &Context, mut args: Vec) -> Result { + Ok(match args.remove(0) { + Value::Thing(v) => v.id.into(), + _ => Value::None, + }) +} + +pub fn tb(_: &Context, mut args: Vec) -> Result { + Ok(match args.remove(0) { + Value::Thing(v) => v.tb.into(), + _ => Value::None, + }) +} diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index 1075eeaa..a875a16f 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -13,6 +13,7 @@ pub mod geo; pub mod http; pub mod is; pub mod math; +pub mod meta; pub mod operate; pub mod parse; pub mod rand; @@ -108,6 +109,10 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result args::check(ctx, name, args, Args::One, math::trimean), "math::variance" => args::check(ctx, name, args, Args::One, math::variance), // + "meta::id" => args::check(ctx, name, args, Args::One, meta::id), + "meta::table" => args::check(ctx, name, args, Args::One, meta::tb), + "meta::tb" => args::check(ctx, name, args, Args::One, meta::tb), + // "parse::email::host" => args::check(ctx, name, args, Args::One, parse::email::host), "parse::email::user" => args::check(ctx, name, args, Args::One, parse::email::user), "parse::url::domain" => args::check(ctx, name, args, Args::One, parse::url::domain), diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 8779ef8a..30925b2a 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -243,6 +243,7 @@ fn function_names(i: &str) -> IResult<&str, &str> { function_http, function_is, function_math, + function_meta, function_parse, function_rand, function_session, @@ -358,6 +359,10 @@ fn function_math(i: &str) -> IResult<&str, &str> { ))(i) } +fn function_meta(i: &str) -> IResult<&str, &str> { + alt((tag("meta::id"), tag("meta::table"), tag("meta::tb")))(i) +} + fn function_parse(i: &str) -> IResult<&str, &str> { alt(( tag("parse::email::host"),