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