...
1 package pgtype
2
3 import (
4 "database/sql/driver"
5 "fmt"
6 )
7
8
9
10 type BPChar Text
11
12
13 func (dst *BPChar) Set(src interface{}) error {
14 return (*Text)(dst).Set(src)
15 }
16
17
18 func (dst BPChar) Get() interface{} {
19 return (Text)(dst).Get()
20 }
21
22
23 func (src *BPChar) AssignTo(dst interface{}) error {
24 switch src.Status {
25 case Present:
26 switch v := dst.(type) {
27 case *rune:
28 runes := []rune(src.String)
29 if len(runes) == 1 {
30 *v = runes[0]
31 return nil
32 }
33 case *string:
34 *v = src.String
35 return nil
36 case *[]byte:
37 *v = make([]byte, len(src.String))
38 copy(*v, src.String)
39 return nil
40 default:
41 if nextDst, retry := GetAssignToDstType(dst); retry {
42 return src.AssignTo(nextDst)
43 }
44 return fmt.Errorf("unable to assign to %T", dst)
45 }
46 case Null:
47 return NullAssignTo(dst)
48 }
49
50 return fmt.Errorf("cannot decode %#v into %T", src, dst)
51 }
52
53 func (BPChar) PreferredResultFormat() int16 {
54 return TextFormatCode
55 }
56
57 func (dst *BPChar) DecodeText(ci *ConnInfo, src []byte) error {
58 return (*Text)(dst).DecodeText(ci, src)
59 }
60
61 func (dst *BPChar) DecodeBinary(ci *ConnInfo, src []byte) error {
62 return (*Text)(dst).DecodeBinary(ci, src)
63 }
64
65 func (BPChar) PreferredParamFormat() int16 {
66 return TextFormatCode
67 }
68
69 func (src BPChar) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
70 return (Text)(src).EncodeText(ci, buf)
71 }
72
73 func (src BPChar) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
74 return (Text)(src).EncodeBinary(ci, buf)
75 }
76
77
78 func (dst *BPChar) Scan(src interface{}) error {
79 return (*Text)(dst).Scan(src)
80 }
81
82
83 func (src BPChar) Value() (driver.Value, error) {
84 return (Text)(src).Value()
85 }
86
87 func (src BPChar) MarshalJSON() ([]byte, error) {
88 return (Text)(src).MarshalJSON()
89 }
90
91 func (dst *BPChar) UnmarshalJSON(b []byte) error {
92 return (*Text)(dst).UnmarshalJSON(b)
93 }
94
View as plain text