Better json func, and tests
This commit is contained in:
parent
0425e8895c
commit
11b0a6858a
2 changed files with 12 additions and 2 deletions
|
|
@ -66,8 +66,13 @@ func String(value string) StringExpression {
|
|||
}
|
||||
|
||||
// Json creates new json literal expression
|
||||
func Json(value string) StringExpression {
|
||||
return StringExp(CAST(jet.String(value)).AS("json"))
|
||||
func Json(value interface{}) StringExpression {
|
||||
switch value.(type) {
|
||||
case string, []byte:
|
||||
default:
|
||||
panic("Bytea parameter value has to be of the type string or []byte")
|
||||
}
|
||||
return StringExp(CAST(jet.Literal(value)).AS("json"))
|
||||
}
|
||||
|
||||
// UUID is a helper function to create string literal expression from uuid object
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ func TestBytea(t *testing.T) {
|
|||
assertSerialize(t, Bytea([]byte("Some byte array")), `$1::bytea`, []byte("Some byte array"))
|
||||
}
|
||||
|
||||
func TestJson(t *testing.T) {
|
||||
assertSerialize(t, Json("{\"key\": \"value\"}"), `$1::json`, "{\"key\": \"value\"}")
|
||||
assertSerialize(t, Json([]byte("{\"key\": \"value\"}")), `$1::json`, []byte("{\"key\": \"value\"}"))
|
||||
}
|
||||
|
||||
func TestDate(t *testing.T) {
|
||||
assertSerialize(t, Date(2014, time.January, 2), `$1::date`, "2014-01-02")
|
||||
assertSerialize(t, DateT(time.Now()), `$1::date`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue