From f3e0920817963e31d4d81ad398d2aa1dcb24f771 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 7 Sep 2024 14:32:12 +0200 Subject: [PATCH] feat: Implement `daterange` range function --- crates/gitql-std/src/range/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/gitql-std/src/range/mod.rs b/crates/gitql-std/src/range/mod.rs index cf2daca..61a4acd 100644 --- a/crates/gitql-std/src/range/mod.rs +++ b/crates/gitql-std/src/range/mod.rs @@ -8,6 +8,7 @@ use std::collections::HashMap; #[inline(always)] pub fn register_std_range_functions(map: &mut HashMap<&'static str, Function>) { map.insert("int4range", int4range); + map.insert("daterange", daterange); } #[inline(always)] @@ -19,6 +20,13 @@ pub fn register_std_range_function_signatures(map: &mut HashMap<&'static str, Si return_type: DataType::Range(Box::new(DataType::Integer)), }, ); + map.insert( + "daterange", + Signature { + parameters: vec![DataType::Date, DataType::Date], + return_type: DataType::Range(Box::new(DataType::Date)), + }, + ); } pub fn int4range(inputs: &[Value]) -> Value { @@ -28,3 +36,11 @@ pub fn int4range(inputs: &[Value]) -> Value { Box::new(inputs[1].clone()), ) } + +pub fn daterange(inputs: &[Value]) -> Value { + Value::Range( + DataType::Date, + Box::new(inputs[0].clone()), + Box::new(inputs[1].clone()), + ) +}