2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-01-13 17:37:46 +00:00
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
|
2022-05-14 12:35:08 +00:00
|
|
|
pub fn count(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
|
2022-01-13 17:37:46 +00:00
|
|
|
match args.len() {
|
|
|
|
1 => match args.remove(0) {
|
2022-05-04 16:14:40 +00:00
|
|
|
Value::Array(v) => Ok(v.iter().filter(|v| v.is_truthy()).count().into()),
|
2022-01-13 17:37:46 +00:00
|
|
|
v => match v.is_truthy() {
|
|
|
|
true => Ok(1.into()),
|
|
|
|
false => Ok(0.into()),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
0 => Ok(1.into()),
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|