Add MarshalJSON to a few types
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user