diff --git a/internal/jet/literal_expression.go b/internal/jet/literal_expression.go index 98dd300..fba2644 100644 --- a/internal/jet/literal_expression.go +++ b/internal/jet/literal_expression.go @@ -282,9 +282,9 @@ func (n *rawExpression) serialize(statement StatementType, out *SqlBuilder, opti return nil } -// RAW can be used for any unsupported functions, operators or expressions. -// For example: RAW("current_database()") -func RAW(raw string) Expression { +// Raw can be used for any unsupported functions, operators or expressions. +// For example: Raw("current_database()") +func Raw(raw string) Expression { rawExp := &rawExpression{raw: raw} rawExp.expressionInterfaceImpl.parent = rawExp diff --git a/internal/jet/literal_expression_test.go b/internal/jet/literal_expression_test.go index d6c5fc1..0b671d5 100644 --- a/internal/jet/literal_expression_test.go +++ b/internal/jet/literal_expression_test.go @@ -6,7 +6,7 @@ import ( ) func TestRawExpression(t *testing.T) { - assertClauseSerialize(t, RAW("current_database()"), "current_database()") + assertClauseSerialize(t, Raw("current_database()"), "current_database()") var timeT = time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) diff --git a/mysql/expressions.go b/mysql/expressions.go index c5bf182..d91ccaf 100644 --- a/mysql/expressions.go +++ b/mysql/expressions.go @@ -29,4 +29,4 @@ var DateExp = jet.DateExp var DateTimeExp = jet.TimestampExp var TimestampExp = jet.TimestampExp -var RAW = jet.RAW +var Raw = jet.Raw diff --git a/postgres/expressions.go b/postgres/expressions.go index 46deb88..df6916e 100644 --- a/postgres/expressions.go +++ b/postgres/expressions.go @@ -31,6 +31,6 @@ var DateExp = jet.DateExp var TimestampExp = jet.TimestampExp var TimestampzExp = jet.TimestampzExp -var RAW = jet.RAW +var Raw = jet.Raw var NewEnumValue = jet.NewEnumValue diff --git a/tests/mysql/alltypes_test.go b/tests/mysql/alltypes_test.go index 07660d4..37acab7 100644 --- a/tests/mysql/alltypes_test.go +++ b/tests/mysql/alltypes_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/model" . "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table" "github.com/go-jet/jet/tests/testdata/common" + "github.com/google/uuid" "time" . "github.com/go-jet/jet/mysql" @@ -29,6 +30,32 @@ func TestAllTypes(t *testing.T) { testutils.AssertJSON(t, dest, allTypesJson) } +func TestUUID(t *testing.T) { + + query := AllTypes. + SELECT( + Raw("uuid()").AS("uuid"), + String("dc8daae3-b83b-11e9-8eb4-98ded00c39c6").AS("str_uuid"), + Raw("unhex(replace('dc8daae3-b83b-11e9-8eb4-98ded00c39c6','-',''))").AS("bin_uuid"), + ).LIMIT(1) + + //fmt.Println(query.DebugSql()) + + var dest struct { + UUID uuid.UUID + StrUUID *uuid.UUID + BinUUID uuid.UUID + } + + err := query.Query(db, &dest) + + assert.NilError(t, err) + assert.Assert(t, dest.StrUUID != nil) + assert.Assert(t, dest.UUID.String() != uuid.UUID{}.String()) + assert.Assert(t, dest.StrUUID.String() != uuid.UUID{}.String()) + assert.Equal(t, dest.StrUUID.String(), dest.BinUUID.String()) +} + func TestExpressionOperators(t *testing.T) { query := AllTypes.SELECT( AllTypes.Integer.IS_NULL().AS("result.is_null"), @@ -38,7 +65,7 @@ func TestExpressionOperators(t *testing.T) { AllTypes.SmallIntPtr.NOT_IN(Int(11), Int(22), NULL).AS("result.not_in"), AllTypes.SmallIntPtr.NOT_IN(AllTypes.SELECT(AllTypes.Integer)).AS("result.not_in_select"), - RAW("DATABASE()"), + Raw("DATABASE()"), ).LIMIT(2) //fmt.Println(query.Sql()) diff --git a/tests/postgres/alltypes_test.go b/tests/postgres/alltypes_test.go index 1f8eb69..fb8b2a2 100644 --- a/tests/postgres/alltypes_test.go +++ b/tests/postgres/alltypes_test.go @@ -152,7 +152,7 @@ func TestExpressionCast(t *testing.T) { GREATEST(AllTypes.Numeric, AllTypes.NumericPtr), LEAST(AllTypes.Numeric, AllTypes.NumericPtr), - RAW("current_database()"), + Raw("current_database()"), ) //fmt.Println(query.DebugSql())