1017e2fffb
Closes SUR-53 When creating a new context for subqueries or statement clauses, we used to have to clone any variables/values, and freeze the context, so that it could be used across threads and async boundaries. Now with the new executor pattern for parallel queries, we can pass references instead, improving performance by removing unnecessary cloning of values.
17 lines
423 B
Rust
17 lines
423 B
Rust
use crate::ctx::Context;
|
|
use crate::err::Error;
|
|
use crate::sql::value::Value;
|
|
|
|
pub fn count(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
|
|
match args.len() {
|
|
1 => match args.remove(0) {
|
|
Value::Array(v) => Ok(v.iter().filter(|v| v.is_truthy()).count().into()),
|
|
v => match v.is_truthy() {
|
|
true => Ok(1.into()),
|
|
false => Ok(0.into()),
|
|
},
|
|
},
|
|
0 => Ok(1.into()),
|
|
_ => unreachable!(),
|
|
}
|
|
}
|