2
0

Fixes #11 -- support initializing Array types from a slice of the value

This commit is contained in:
Alex Gaynor
2019-11-08 14:59:19 -05:00
parent f711de3591
commit 0079108e29
22 changed files with 327 additions and 80 deletions
+14 -2
View File
@@ -40,6 +40,18 @@ func (dst *EnumArray) Set(src interface{}) error {
}
}
case []GenericText:
if value == nil {
*dst = EnumArray{Status: Null}
} else if len(value) == 0 {
*dst = EnumArray{Status: Present}
} else {
*dst = EnumArray{
Elements: value,
Dimensions: []ArrayDimension{{Length: int32(len(value)), LowerBound: 1}},
Status: Present,
}
}
default:
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
@@ -124,7 +136,7 @@ func (dst *EnumArray) DecodeText(ci *ConnInfo, src []byte) error {
return nil
}
func (src EnumArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src *EnumArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
switch src.Status {
case Null:
return nil, nil
@@ -200,7 +212,7 @@ func (dst *EnumArray) Scan(src interface{}) error {
}
// Value implements the database/sql/driver Valuer interface.
func (src EnumArray) Value() (driver.Value, error) {
func (src *EnumArray) Value() (driver.Value, error) {
buf, err := src.EncodeText(nil, nil)
if err != nil {
return nil, err