featherdb_query/expr/functions/
mod.rs1mod datetime;
4mod math;
5mod string;
6
7use featherdb_core::{Error, Result, Value};
8
9pub fn eval_function(name: &str, args: &[Value]) -> Result<Value> {
11 if let Some(result) = string::eval_string_function(name, args) {
13 return result;
14 }
15
16 if let Some(result) = datetime::eval_datetime_function(name, args) {
18 return result;
19 }
20
21 if let Some(result) = math::eval_math_function(name, args) {
23 return result;
24 }
25
26 Err(Error::Unsupported {
28 feature: format!("Function: {}", name),
29 })
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn test_eval_function_string() {
38 assert_eq!(
39 eval_function("UPPER", &[Value::Text("hello".into())]).unwrap(),
40 Value::Text("HELLO".into())
41 );
42 }
43
44 #[test]
45 fn test_eval_function_datetime() {
46 assert_eq!(
47 eval_function("YEAR", &[Value::Text("2024-01-15".into())]).unwrap(),
48 Value::Integer(2024)
49 );
50 }
51
52 #[test]
53 fn test_eval_function_math() {
54 assert_eq!(
55 eval_function("ABS", &[Value::Integer(-5)]).unwrap(),
56 Value::Integer(5)
57 );
58 }
59
60 #[test]
61 fn test_eval_function_unknown() {
62 assert!(eval_function("UNKNOWN_FUNC", &[]).is_err());
63 }
64}