2
0

Add MarshalJSON to a few types

This commit is contained in:
Jack Christensen
2017-04-13 21:54:04 -05:00
parent adb54d06ce
commit fe7d9d3462
6 changed files with 58 additions and 0 deletions
+14
View File
@@ -2,6 +2,7 @@ package pgtype
import (
"database/sql/driver"
"encoding/json"
"fmt"
"io"
)
@@ -134,3 +135,16 @@ func (src Text) Value() (driver.Value, error) {
return nil, errUndefined
}
}
func (src Text) MarshalJSON() ([]byte, error) {
switch src.Status {
case Present:
return json.Marshal(src.String)
case Null:
return []byte("null"), nil
case Undefined:
return []byte("undefined"), nil
}
return nil, errBadStatus
}