Skip to content

Commit

Permalink
feat: Implement TO_HEX Text Function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Nov 18, 2024
1 parent df86365 commit df38b70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/gitql-std/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn register_std_text_functions(map: &mut HashMap<&'static str, Function>) {
map.insert("strcmp", text_strcmp);
map.insert("quotename", text_quotename);
map.insert("str", text_str);
map.insert("to_hex", text_to_hex);
}

#[inline(always)]
Expand Down Expand Up @@ -276,6 +277,13 @@ pub fn register_std_text_function_signatures(map: &mut HashMap<&'static str, Sig
return_type: Box::new(TextType),
},
);
map.insert(
"text_to_hex",
Signature {
parameters: vec![Box::new(IntType)],
return_type: Box::new(TextType),
},
);
}

pub fn text_bin(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
Expand Down Expand Up @@ -658,3 +666,9 @@ pub fn text_str(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
value: number_string.clone(),
})
}

pub fn text_to_hex(inputs: &[Box<dyn Value>]) -> Box<dyn Value> {
let number = inputs[0].as_int().unwrap();
let value = format!("0x{}", number);
Box::new(TextValue { value })
}
1 change: 1 addition & 0 deletions docs/functions/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
| STRCMP | Text , Text | Integer | Return 0 If string1 = string2, -1 if string1 < string2, this function returns -1, and 1 if string1 > string2 |
| QUOTENAME | Text , Text | Text | Returns the string (first argument) with specified delimiters (second argument), defaulting to [] |
| STR | Text, Integer?, Integer? | Text | Returns a number as a string with optionals length and decimals. |
| TO_HEX | Integer | Text | Returns a number as a string with hex decimal format. |

0 comments on commit df38b70

Please sign in to comment.