Add SQL array::group()
function
This commit is contained in:
parent
513f213a4a
commit
b53103c9c7
3 changed files with 10 additions and 0 deletions
|
@ -51,6 +51,13 @@ pub fn flatten((arg,): (Value,)) -> Result<Value, Error> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn group((arg,): (Value,)) -> Result<Value, Error> {
|
||||
Ok(match arg {
|
||||
Value::Array(v) => v.uniq().flatten().into(),
|
||||
_ => Value::None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn insert((array, value, index): (Value, Value, Option<Value>)) -> Result<Value, Error> {
|
||||
match (array, index) {
|
||||
(Value::Array(mut v), Some(Value::Number(i))) => {
|
||||
|
|
|
@ -66,6 +66,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
|
|||
"array::difference" => array::difference,
|
||||
"array::distinct" => array::distinct,
|
||||
"array::flatten" => array::flatten,
|
||||
"array::group" => array::group,
|
||||
"array::insert" => array::insert,
|
||||
"array::intersect" => array::intersect,
|
||||
"array::len" => array::len,
|
||||
|
|
|
@ -79,6 +79,7 @@ impl Function {
|
|||
match self {
|
||||
Self::Normal(f, _) if f == "array::concat" => true,
|
||||
Self::Normal(f, _) if f == "array::distinct" => true,
|
||||
Self::Normal(f, _) if f == "array::group" => true,
|
||||
Self::Normal(f, _) if f == "array::union" => true,
|
||||
Self::Normal(f, _) if f == "count" => true,
|
||||
Self::Normal(f, _) if f == "math::bottom" => true,
|
||||
|
@ -241,6 +242,7 @@ fn function_array(i: &str) -> IResult<&str, &str> {
|
|||
tag("array::difference"),
|
||||
tag("array::distinct"),
|
||||
tag("array::flatten"),
|
||||
tag("array::group"),
|
||||
tag("array::insert"),
|
||||
tag("array::intersect"),
|
||||
tag("array::len"),
|
||||
|
|
Loading…
Reference in a new issue