Skip to content

Commit 6e7ad11

Browse files
committed
added pgtypeutils uint implementation
1 parent 3e08c65 commit 6e7ad11

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

pkg/db/dbutils/pgtypeutils/int2.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ func DecodeInt2(value pgtype.Int2) *int16 {
1919
}
2020
return &value.Int16
2121
}
22+
23+
func EncodeUInt2(value *uint16) pgtype.Int2 {
24+
var v int16
25+
if value != nil {
26+
v = int16(*value)
27+
}
28+
return pgtype.Int2{
29+
Int16: v,
30+
Valid: value != nil,
31+
}
32+
}
33+
34+
func DecodeUInt2(value pgtype.Int2) *uint16 {
35+
if !value.Valid {
36+
return nil
37+
}
38+
v := uint16(value.Int16)
39+
return &v
40+
}

pkg/db/dbutils/pgtypeutils/int4.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ func DecodeInt4(value pgtype.Int4) *int32 {
1919
}
2020
return &value.Int32
2121
}
22+
23+
func EncodeUInt4(value *uint32) pgtype.Int4 {
24+
var v int32
25+
if value != nil {
26+
v = int32(*value)
27+
}
28+
return pgtype.Int4{
29+
Int32: v,
30+
Valid: value != nil,
31+
}
32+
}
33+
34+
func DecodeUInt4(value pgtype.Int4) *uint32 {
35+
if !value.Valid {
36+
return nil
37+
}
38+
v := uint32(value.Int32)
39+
return &v
40+
}

pkg/db/dbutils/pgtypeutils/int8.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ func DecodeInt8(value pgtype.Int8) *int64 {
1919
}
2020
return &value.Int64
2121
}
22+
23+
func EncodeUInt8(value *uint64) pgtype.Int8 {
24+
var v int64
25+
if value != nil {
26+
v = int64(*value)
27+
}
28+
return pgtype.Int8{
29+
Int64: v,
30+
Valid: value != nil,
31+
}
32+
}
33+
34+
func DecodeUInt8(value pgtype.Int8) *uint64 {
35+
if !value.Valid {
36+
return nil
37+
}
38+
v := uint64(value.Int64)
39+
return &v
40+
}

0 commit comments

Comments
 (0)