Merge branch 'develop' of https://github.com/go-jet/jet into develop
This commit is contained in:
commit
bdbbc4d58d
3 changed files with 28 additions and 1 deletions
|
|
@ -261,10 +261,22 @@ func UNIX_TIMESTAMP(str StringExpression) TimestampExpression {
|
|||
return jet.NewTimestampFunc("UNIX_TIMESTAMP", str)
|
||||
}
|
||||
|
||||
//----------- Comparison operators ---------------//
|
||||
// --------------- Conditional Expressions Functions -------------//
|
||||
|
||||
// EXISTS checks for existence of the rows in subQuery
|
||||
var EXISTS = jet.EXISTS
|
||||
|
||||
// CASE create CASE operator with optional list of expressions
|
||||
var CASE = jet.CASE
|
||||
|
||||
// COALESCE function returns the first of its arguments that is not null.
|
||||
var COALESCE = jet.COALESCE
|
||||
|
||||
// NULLIF function returns a null value if value1 equals value2; otherwise it returns value1.
|
||||
var NULLIF = jet.NULLIF
|
||||
|
||||
// GREATEST selects the largest value from a list of expressions, or null if any of the expressions is null.
|
||||
var GREATEST = jet.GREATEST
|
||||
|
||||
// LEAST selects the smallest value from a list of expressions, or null if any of the expressions is null.
|
||||
var LEAST = jet.LEAST
|
||||
|
|
|
|||
|
|
@ -65,6 +65,16 @@ func String(value string) StringExpression {
|
|||
return CAST(jet.String(value)).AS_TEXT()
|
||||
}
|
||||
|
||||
// Json creates new json literal expression
|
||||
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
|
||||
// value can be any uuid type with a String method
|
||||
var UUID = jet.UUID
|
||||
|
|
|
|||
|
|
@ -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