MySQL UUID test.
RAW rename to Raw.
This commit is contained in:
parent
3089bffa1c
commit
d235385c2a
6 changed files with 35 additions and 8 deletions
|
|
@ -282,9 +282,9 @@ func (n *rawExpression) serialize(statement StatementType, out *SqlBuilder, opti
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RAW can be used for any unsupported functions, operators or expressions.
|
// Raw can be used for any unsupported functions, operators or expressions.
|
||||||
// For example: RAW("current_database()")
|
// For example: Raw("current_database()")
|
||||||
func RAW(raw string) Expression {
|
func Raw(raw string) Expression {
|
||||||
rawExp := &rawExpression{raw: raw}
|
rawExp := &rawExpression{raw: raw}
|
||||||
rawExp.expressionInterfaceImpl.parent = rawExp
|
rawExp.expressionInterfaceImpl.parent = rawExp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRawExpression(t *testing.T) {
|
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)
|
var timeT = time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,4 @@ var DateExp = jet.DateExp
|
||||||
var DateTimeExp = jet.TimestampExp
|
var DateTimeExp = jet.TimestampExp
|
||||||
var TimestampExp = jet.TimestampExp
|
var TimestampExp = jet.TimestampExp
|
||||||
|
|
||||||
var RAW = jet.RAW
|
var Raw = jet.Raw
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ var DateExp = jet.DateExp
|
||||||
var TimestampExp = jet.TimestampExp
|
var TimestampExp = jet.TimestampExp
|
||||||
var TimestampzExp = jet.TimestampzExp
|
var TimestampzExp = jet.TimestampzExp
|
||||||
|
|
||||||
var RAW = jet.RAW
|
var Raw = jet.Raw
|
||||||
|
|
||||||
var NewEnumValue = jet.NewEnumValue
|
var NewEnumValue = jet.NewEnumValue
|
||||||
|
|
|
||||||
|
|
@ -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/model"
|
||||||
. "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table"
|
. "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table"
|
||||||
"github.com/go-jet/jet/tests/testdata/common"
|
"github.com/go-jet/jet/tests/testdata/common"
|
||||||
|
"github.com/google/uuid"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/go-jet/jet/mysql"
|
. "github.com/go-jet/jet/mysql"
|
||||||
|
|
@ -29,6 +30,32 @@ func TestAllTypes(t *testing.T) {
|
||||||
testutils.AssertJSON(t, dest, allTypesJson)
|
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) {
|
func TestExpressionOperators(t *testing.T) {
|
||||||
query := AllTypes.SELECT(
|
query := AllTypes.SELECT(
|
||||||
AllTypes.Integer.IS_NULL().AS("result.is_null"),
|
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(Int(11), Int(22), NULL).AS("result.not_in"),
|
||||||
AllTypes.SmallIntPtr.NOT_IN(AllTypes.SELECT(AllTypes.Integer)).AS("result.not_in_select"),
|
AllTypes.SmallIntPtr.NOT_IN(AllTypes.SELECT(AllTypes.Integer)).AS("result.not_in_select"),
|
||||||
|
|
||||||
RAW("DATABASE()"),
|
Raw("DATABASE()"),
|
||||||
).LIMIT(2)
|
).LIMIT(2)
|
||||||
|
|
||||||
//fmt.Println(query.Sql())
|
//fmt.Println(query.Sql())
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ func TestExpressionCast(t *testing.T) {
|
||||||
GREATEST(AllTypes.Numeric, AllTypes.NumericPtr),
|
GREATEST(AllTypes.Numeric, AllTypes.NumericPtr),
|
||||||
LEAST(AllTypes.Numeric, AllTypes.NumericPtr),
|
LEAST(AllTypes.Numeric, AllTypes.NumericPtr),
|
||||||
|
|
||||||
RAW("current_database()"),
|
Raw("current_database()"),
|
||||||
)
|
)
|
||||||
|
|
||||||
//fmt.Println(query.DebugSql())
|
//fmt.Println(query.DebugSql())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue