...
1 package pgtype
2
3 import (
4 "database/sql/driver"
5 "fmt"
6 )
7
8 type JSONB JSON
9
10 func (dst *JSONB) Set(src interface{}) error {
11 return (*JSON)(dst).Set(src)
12 }
13
14 func (dst JSONB) Get() interface{} {
15 return (JSON)(dst).Get()
16 }
17
18 func (src *JSONB) AssignTo(dst interface{}) error {
19 return (*JSON)(src).AssignTo(dst)
20 }
21
22 func (JSONB) PreferredResultFormat() int16 {
23 return TextFormatCode
24 }
25
26 func (dst *JSONB) DecodeText(ci *ConnInfo, src []byte) error {
27 return (*JSON)(dst).DecodeText(ci, src)
28 }
29
30 func (dst *JSONB) DecodeBinary(ci *ConnInfo, src []byte) error {
31 if src == nil {
32 *dst = JSONB{Status: Null}
33 return nil
34 }
35
36 if len(src) == 0 {
37 return fmt.Errorf("jsonb too short")
38 }
39
40 if src[0] != 1 {
41 return fmt.Errorf("unknown jsonb version number %d", src[0])
42 }
43
44 *dst = JSONB{Bytes: src[1:], Status: Present}
45 return nil
46
47 }
48
49 func (JSONB) PreferredParamFormat() int16 {
50 return TextFormatCode
51 }
52
53 func (src JSONB) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
54 return (JSON)(src).EncodeText(ci, buf)
55 }
56
57 func (src JSONB) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
58 switch src.Status {
59 case Null:
60 return nil, nil
61 case Undefined:
62 return nil, errUndefined
63 }
64
65 buf = append(buf, 1)
66 return append(buf, src.Bytes...), nil
67 }
68
69
70 func (dst *JSONB) Scan(src interface{}) error {
71 return (*JSON)(dst).Scan(src)
72 }
73
74
75 func (src JSONB) Value() (driver.Value, error) {
76 return (JSON)(src).Value()
77 }
78
79 func (src JSONB) MarshalJSON() ([]byte, error) {
80 return (JSON)(src).MarshalJSON()
81 }
82
83 func (dst *JSONB) UnmarshalJSON(b []byte) error {
84 return (*JSON)(dst).UnmarshalJSON(b)
85 }
86
View as plain text