Allow Bytea literal constructor to accept byte array.
Bytea literal constructor now accepts string or []byte a a parameter.
This commit is contained in:
parent
f30cbb9e89
commit
9385f462df
3 changed files with 66 additions and 4 deletions
|
|
@ -1,8 +1,9 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
"time"
|
||||
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
)
|
||||
|
||||
// Bool creates new bool literal expression
|
||||
|
|
@ -48,9 +49,14 @@ var String = jet.String
|
|||
// value can be any uuid type with a String method
|
||||
var UUID = jet.UUID
|
||||
|
||||
// Bytea craates new bytea literal expression
|
||||
var Bytea = func(value string) StringExpression {
|
||||
return CAST(jet.String(value)).AS_BYTEA()
|
||||
// Bytea creates new bytea literal expression
|
||||
var Bytea = func(value interface{}) StringExpression {
|
||||
switch value.(type) {
|
||||
case string, []byte:
|
||||
default:
|
||||
panic("Bytea parameter value has to be of the type string or []byte")
|
||||
}
|
||||
return CAST(jet.Literal(value)).AS_BYTEA()
|
||||
}
|
||||
|
||||
// Date creates new date literal expression
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ func TestString(t *testing.T) {
|
|||
assertSerialize(t, String("Some text"), `$1`, "Some text")
|
||||
}
|
||||
|
||||
func TestBytea(t *testing.T) {
|
||||
assertSerialize(t, Bytea("Some text"), `$1::bytea`, "Some text")
|
||||
assertSerialize(t, Bytea([]byte("Some byte array")), `$1::bytea`, []byte("Some byte array"))
|
||||
}
|
||||
|
||||
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