mirror of https://github.com/jackc/pgx.git
parent
ccb207cba5
commit
25558de3bd
17
int2.go
17
int2.go
|
@ -3,6 +3,7 @@ package pgtype
|
||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -302,3 +303,19 @@ func (src Int2) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
return nil, errBadStatus
|
return nil, errBadStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dst *Int2) UnmarshalJSON(b []byte) error {
|
||||||
|
var n *int16
|
||||||
|
err := json.Unmarshal(b, &n)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == nil {
|
||||||
|
*dst = Int2{Status: Null}
|
||||||
|
} else {
|
||||||
|
*dst = Int2{Int: *n, Status: Present}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue