Passed
Pull Request — master (#2447)
by Tolga
03:26
created

postgres.*XID8.Set   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package postgres
2
3
import (
4
	"database/sql/driver"
5
6
	"github.com/jackc/pgtype"
7
)
8
9
// XID8 represents a PostgreSQL xid8 (64-bit transaction ID) type
10
type XID8 pguint64
11
12
// pgSnapshot represents a PostgreSQL snapshot type
13
type pgSnapshot struct {
14
	pgtype.Value
15
}
16
17
// SnapshotCodec handles encoding/decoding of PostgreSQL snapshot values
18
type SnapshotCodec struct{}
19
20
// Uint64Codec handles encoding/decoding of PostgreSQL xid8 values
21
type Uint64Codec struct{}
22
23
// Set sets the XID8 value from various input types
24
func (x *XID8) Set(src interface{}) error {
25
	return (*pguint64)(x).Set(src)
26
}
27
28
// Get returns the underlying value
29
func (x XID8) Get() interface{} {
30
	return (pguint64)(x).Get()
31
}
32
33
// AssignTo assigns the value to the destination
34
func (x *XID8) AssignTo(dst interface{}) error {
35
	return (*pguint64)(x).AssignTo(dst)
36
}
37
38
// DecodeText decodes text format
39
func (x *XID8) DecodeText(ci *pgtype.ConnInfo, src []byte) error {
40
	return (*pguint64)(x).DecodeText(ci, src)
41
}
42
43
// DecodeBinary decodes binary format
44
func (x *XID8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error {
45
	return (*pguint64)(x).DecodeBinary(ci, src)
46
}
47
48
// EncodeText encodes to text format
49
func (x XID8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
50
	return (pguint64)(x).EncodeText(ci, buf)
51
}
52
53
// EncodeBinary encodes to binary format
54
func (x XID8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
55
	return (pguint64)(x).EncodeBinary(ci, buf)
56
}
57
58
// Scan implements the database/sql Scanner interface
59
func (x *XID8) Scan(src interface{}) error {
60
	return (*pguint64)(x).Scan(src)
61
}
62
63
// Value implements the database/sql/driver Valuer interface
64
func (x XID8) Value() (driver.Value, error) {
65
	return (pguint64)(x).Value()
66
}
67
68
// FormatCode returns the format code for snapshot values
69
func (c SnapshotCodec) FormatCode() int16 {
70
	return pgtype.BinaryFormatCode
71
}
72
73
// FormatCode returns the format code for xid8 values
74
func (c Uint64Codec) FormatCode() int16 {
75
	return pgtype.BinaryFormatCode
76
}
77