2
0

Expand pgtype.Value interface

- Include and rename ConvertFrom to Set
- Add Get
- Include AssignTo
This commit is contained in:
Jack Christensen
2017-03-11 19:53:02 -06:00
parent 542eac08c6
commit 57494a6a0f
74 changed files with 568 additions and 185 deletions
+13 -2
View File
@@ -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: