mysql: added a helper to compare UUID strings with uuid_to_bin
This commit is contained in:
parent
493d3a4a25
commit
09fe45b09c
2 changed files with 24 additions and 1 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-jet/jet/v2/internal/jet"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-jet/jet/v2/internal/jet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Keywords
|
// Keywords
|
||||||
|
|
@ -55,6 +57,17 @@ var String = jet.String
|
||||||
// value can be any uuid type with a String method
|
// value can be any uuid type with a String method
|
||||||
var UUID = jet.UUID
|
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
|
// Date creates new date literal
|
||||||
func Date(year int, month time.Month, day int) DateExpression {
|
func Date(year int, month time.Month, day int) DateExpression {
|
||||||
return CAST(jet.Date(year, month, day)).AS_DATE()
|
return CAST(jet.Date(year, month, day)).AS_DATE()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBool(t *testing.T) {
|
func TestBool(t *testing.T) {
|
||||||
|
|
@ -81,3 +83,11 @@ func TestTimestamp(t *testing.T) {
|
||||||
assertSerialize(t, Timestamp(2010, time.March, 30, 10, 15, 30), `TIMESTAMP(?)`, "2010-03-30 10:15:30")
|
assertSerialize(t, Timestamp(2010, time.March, 30, 10, 15, 30), `TIMESTAMP(?)`, "2010-03-30 10:15:30")
|
||||||
assertSerialize(t, TimestampT(time.Now()), `TIMESTAMP(?)`)
|
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())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue