Add meta::id() and meta::tb() functions
This commit is contained in:
parent
94dc566d3f
commit
70970862f4
3 changed files with 27 additions and 0 deletions
17
lib/src/fnc/meta.rs
Normal file
17
lib/src/fnc/meta.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use crate::ctx::Context;
|
||||
use crate::err::Error;
|
||||
use crate::sql::value::Value;
|
||||
|
||||
pub fn id(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||
Ok(match args.remove(0) {
|
||||
Value::Thing(v) => v.id.into(),
|
||||
_ => Value::None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn tb(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||
Ok(match args.remove(0) {
|
||||
Value::Thing(v) => v.tb.into(),
|
||||
_ => Value::None,
|
||||
})
|
||||
}
|
|
@ -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<Value>) -> Result<Va
|
|||
"math::trimean" => 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),
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue