From 33ec120437b23edbc05a798491ca523c92beaad1 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 22 Feb 2024 17:23:14 +0530 Subject: [PATCH] replaced the UUIDToBin functions with a singular UUID_TO_BIN --- mysql/functions.go | 6 ++++++ mysql/functions_test.go | 11 +++++++++++ mysql/literal.go | 12 ------------ mysql/literal_test.go | 10 ---------- 4 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 mysql/functions_test.go diff --git a/mysql/functions.go b/mysql/functions.go index 4eba942..ca31d18 100644 --- a/mysql/functions.go +++ b/mysql/functions.go @@ -222,6 +222,12 @@ var SUBSTR = jet.SUBSTR // REGEXP_LIKE Returns 1 if the string expr matches the regular expression specified by the pattern pat, 0 otherwise. var REGEXP_LIKE = jet.REGEXP_LIKE +// UUID_TO_BIN is a helper function that calls "uuid_to_bin" function on the passed value. +func UUID_TO_BIN(str StringExpression) StringExpression { + fn := Func("uuid_to_bin", str) + return StringExp(fn) +} + //----------------- Date/Time Functions and Operators ------------// // EXTRACT function retrieves subfields such as year or hour from date/time values diff --git a/mysql/functions_test.go b/mysql/functions_test.go new file mode 100644 index 0000000..197b515 --- /dev/null +++ b/mysql/functions_test.go @@ -0,0 +1,11 @@ +package mysql + +import ( + "testing" + + "github.com/google/uuid" +) + +func TestUUIDToBin(t *testing.T) { + assertSerialize(t, UUID_TO_BIN(String(uuid.Nil.String())), `uuid_to_bin(?)`, uuid.Nil.String()) +} diff --git a/mysql/literal.go b/mysql/literal.go index 3c7c07a..ca720c8 100644 --- a/mysql/literal.go +++ b/mysql/literal.go @@ -1,7 +1,6 @@ package mysql import ( - "fmt" "time" "github.com/go-jet/jet/v2/internal/jet" @@ -57,17 +56,6 @@ var String = jet.String // value can be any uuid type with a String method var UUID = jet.UUID -// UUIDToBin takes ay object with a String method and calls StringUUIDToBin. -func UUIDToBin(str fmt.Stringer) StringExpression { - return StringUUIDToBin(str.String()) -} - -// StringUUIDToBin is a helper function that calls "uuid_to_bin" function on the passed value. -func StringUUIDToBin(str string) StringExpression { - fn := Func("uuid_to_bin", String(str)) - return StringExp(fn) -} - // Date creates new date literal func Date(year int, month time.Month, day int) DateExpression { return CAST(jet.Date(year, month, day)).AS_DATE() diff --git a/mysql/literal_test.go b/mysql/literal_test.go index d5831b6..fb96641 100644 --- a/mysql/literal_test.go +++ b/mysql/literal_test.go @@ -4,8 +4,6 @@ import ( "math" "testing" "time" - - "github.com/google/uuid" ) func TestBool(t *testing.T) { @@ -83,11 +81,3 @@ func TestTimestamp(t *testing.T) { assertSerialize(t, Timestamp(2010, time.March, 30, 10, 15, 30), `TIMESTAMP(?)`, "2010-03-30 10:15:30") assertSerialize(t, TimestampT(time.Now()), `TIMESTAMP(?)`) } - -func TestUUIDToBin(t *testing.T) { - assertSerialize(t, UUIDToBin(uuid.Nil), `uuid_to_bin(?)`, uuid.Nil.String()) -} - -func TestStringUUIDToBin(t *testing.T) { - assertSerialize(t, StringUUIDToBin(uuid.Nil.String()), `uuid_to_bin(?)`, uuid.Nil.String()) -}