Skip to content

Commit

Permalink
replaced the UUIDToBin functions with a singular UUID_TO_BIN
Browse files Browse the repository at this point in the history
  • Loading branch information
realbucksavage committed Feb 22, 2024
1 parent 09fe45b commit 33ec120
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
6 changes: 6 additions & 0 deletions mysql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions mysql/functions_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
12 changes: 0 additions & 12 deletions mysql/literal.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mysql

import (
"fmt"
"time"

"github.com/go-jet/jet/v2/internal/jet"
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 0 additions & 10 deletions mysql/literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"math"
"testing"
"time"

"github.com/google/uuid"
)

func TestBool(t *testing.T) {
Expand Down Expand Up @@ -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())
}

0 comments on commit 33ec120

Please sign in to comment.