2
0

Add database/sql support to pgtype

This commit is contained in:
Jack Christensen
2017-03-18 21:11:43 -05:00
parent 5572c002dc
commit bec9bd261b
55 changed files with 1459 additions and 201 deletions
+30
View File
@@ -299,3 +299,33 @@ func (src *<%= pgtype_array_type %>) EncodeText(ci *ConnInfo, w io.Writer) (bool
return false, err
}
<% end %>
// Scan implements the database/sql Scanner interface.
func (dst *<%= pgtype_array_type %>) Scan(src interface{}) error {
if src == nil {
return dst.DecodeText(nil, nil)
}
switch src := src.(type) {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *<%= pgtype_array_type %>) Value() (driver.Value, error) {
buf := &bytes.Buffer{}
null, err := src.EncodeText(nil, buf)
if err != nil {
return nil, err
}
if null {
return nil, nil
}
return buf.String(), nil
}