2021-03-31 12:10:13 +00:00
|
|
|
use crate::dbs::Runtime;
|
2021-03-29 15:43:37 +00:00
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::literal::Literal;
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn run(ctx: &Runtime, name: &String, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
match name.as_str() {
|
|
|
|
"bool" => bool(ctx, val),
|
|
|
|
"int" => int(ctx, val),
|
|
|
|
"float" => float(ctx, val),
|
|
|
|
"string" => string(ctx, val),
|
|
|
|
"number" => number(ctx, val),
|
|
|
|
"decimal" => number(ctx, val),
|
|
|
|
"datetime" => datetime(ctx, val),
|
|
|
|
"duration" => duration(ctx, val),
|
|
|
|
_ => Ok(val),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn bool(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
match val.as_bool() {
|
|
|
|
true => Ok(Literal::True),
|
|
|
|
false => Ok(Literal::False),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn int(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Int(val.as_int()))
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn float(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Float(val.as_float()))
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn string(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Strand(val.as_strand()))
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn number(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Number(val.as_number()))
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn datetime(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Datetime(val.as_datetime()))
|
|
|
|
}
|
|
|
|
|
2021-03-31 12:10:13 +00:00
|
|
|
pub fn duration(ctx: &Runtime, val: Literal) -> Result<Literal, Error> {
|
2021-03-29 15:43:37 +00:00
|
|
|
Ok(Literal::Duration(val.as_duration()))
|
|
|
|
}
|