MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_eval

Function try_eval

nodedb-query/src/functions/conditional.rs:8–40  ·  view source on GitHub ↗
(name: &str, args: &[Value])

Source from the content-addressed store, hash-verified

6use nodedb_types::Value;
7
8pub(super) fn try_eval(name: &str, args: &[Value]) -> Option<Value> {
9 let v = match name {
10 "coalesce" => {
11 for arg in args {
12 if !arg.is_null() {
13 return Some(arg.clone());
14 }
15 }
16 Value::Null
17 }
18 "nullif" => {
19 if args.len() >= 2 && args[0] == args[1] {
20 Value::Null
21 } else {
22 args.first().cloned().unwrap_or(Value::Null)
23 }
24 }
25 "greatest" => args
26 .iter()
27 .filter(|v| !v.is_null())
28 .max_by(|a, b| compare_values(a, b))
29 .cloned()
30 .unwrap_or(Value::Null),
31 "least" => args
32 .iter()
33 .filter(|v| !v.is_null())
34 .min_by(|a, b| compare_values(a, b))
35 .cloned()
36 .unwrap_or(Value::Null),
37 _ => return None,
38 };
39 Some(v)
40}

Callers

nothing calls this directly

Calls 6

firstMethod · 0.80
compare_valuesFunction · 0.50
is_nullMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected