Expand pgtype.Value interface
- Include and rename ConvertFrom to Set - Add Get - Include AssignTo
This commit is contained in:
+13
-2
@@ -12,7 +12,7 @@ type Bytea struct {
|
||||
Status Status
|
||||
}
|
||||
|
||||
func (dst *Bytea) ConvertFrom(src interface{}) error {
|
||||
func (dst *Bytea) Set(src interface{}) error {
|
||||
switch value := src.(type) {
|
||||
case Bytea:
|
||||
*dst = value
|
||||
@@ -24,7 +24,7 @@ func (dst *Bytea) ConvertFrom(src interface{}) error {
|
||||
}
|
||||
default:
|
||||
if originalSrc, ok := underlyingBytesType(src); ok {
|
||||
return dst.ConvertFrom(originalSrc)
|
||||
return dst.Set(originalSrc)
|
||||
}
|
||||
return fmt.Errorf("cannot convert %v to Bytea", value)
|
||||
}
|
||||
@@ -32,6 +32,17 @@ func (dst *Bytea) ConvertFrom(src interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dst *Bytea) Get() interface{} {
|
||||
switch dst.Status {
|
||||
case Present:
|
||||
return dst.Bytes
|
||||
case Null:
|
||||
return nil
|
||||
default:
|
||||
return dst.Status
|
||||
}
|
||||
}
|
||||
|
||||
func (src *Bytea) AssignTo(dst interface{}) error {
|
||||
switch v := dst.(type) {
|
||||
case *[]byte:
|
||||
|
||||
Reference in New Issue
Block a user