2
0

Rename Uint32 field to include bit size

i.e. Uint renamed to Uint32. This matches the pattern set by the
database/sql types.
This commit is contained in:
Jack Christensen
2022-03-05 09:23:25 -06:00
parent 84a3d91322
commit 2885b039d5
2 changed files with 10 additions and 10 deletions
+7 -7
View File
@@ -20,7 +20,7 @@ type Uint32Valuer interface {
// Uint32 is the core type that is used to represent PostgreSQL types such as OID, CID, and XID. // Uint32 is the core type that is used to represent PostgreSQL types such as OID, CID, and XID.
type Uint32 struct { type Uint32 struct {
Uint uint32 Uint32 uint32
Valid bool Valid bool
} }
@@ -62,7 +62,7 @@ func (dst *Uint32) Scan(src interface{}) error {
return fmt.Errorf("%d is greater than maximum value for Uint32", n) return fmt.Errorf("%d is greater than maximum value for Uint32", n)
} }
*dst = Uint32{Uint: uint32(n), Valid: true} *dst = Uint32{Uint32: uint32(n), Valid: true}
return nil return nil
} }
@@ -72,7 +72,7 @@ func (src Uint32) Value() (driver.Value, error) {
if !src.Valid { if !src.Valid {
return nil, nil return nil, nil
} }
return int64(src.Uint), nil return int64(src.Uint32), nil
} }
type Uint32Codec struct{} type Uint32Codec struct{}
@@ -127,7 +127,7 @@ func (encodePlanUint32CodecBinaryUint32Valuer) Encode(value interface{}, buf []b
return nil, nil return nil, nil
} }
return pgio.AppendUint32(buf, v.Uint), nil return pgio.AppendUint32(buf, v.Uint32), nil
} }
type encodePlanUint32CodecBinaryInt64Valuer struct{} type encodePlanUint32CodecBinaryInt64Valuer struct{}
@@ -171,7 +171,7 @@ func (encodePlanUint32CodecTextUint32Valuer) Encode(value interface{}, buf []byt
return nil, nil return nil, nil
} }
return append(buf, strconv.FormatUint(uint64(v.Uint), 10)...), nil return append(buf, strconv.FormatUint(uint64(v.Uint32), 10)...), nil
} }
type encodePlanUint32CodecTextInt64Valuer struct{} type encodePlanUint32CodecTextInt64Valuer struct{}
@@ -279,7 +279,7 @@ func (scanPlanBinaryUint32ToUint32Scanner) Scan(src []byte, dst interface{}) err
n := binary.BigEndian.Uint32(src) n := binary.BigEndian.Uint32(src)
return s.ScanUint32(Uint32{Uint: n, Valid: true}) return s.ScanUint32(Uint32{Uint32: n, Valid: true})
} }
type scanPlanTextAnyToUint32Scanner struct{} type scanPlanTextAnyToUint32Scanner struct{}
@@ -299,5 +299,5 @@ func (scanPlanTextAnyToUint32Scanner) Scan(src []byte, dst interface{}) error {
return err return err
} }
return s.ScanUint32(Uint32{Uint: uint32(n), Valid: true}) return s.ScanUint32(Uint32{Uint32: uint32(n), Valid: true})
} }
+2 -2
View File
@@ -10,9 +10,9 @@ import (
func TestUint32Codec(t *testing.T) { func TestUint32Codec(t *testing.T) {
testutil.RunTranscodeTests(t, "oid", []testutil.TranscodeTestCase{ testutil.RunTranscodeTests(t, "oid", []testutil.TranscodeTestCase{
{ {
pgtype.Uint32{Uint: pgtype.TextOID, Valid: true}, pgtype.Uint32{Uint32: pgtype.TextOID, Valid: true},
new(pgtype.Uint32), new(pgtype.Uint32),
isExpectedEq(pgtype.Uint32{Uint: pgtype.TextOID, Valid: true}), isExpectedEq(pgtype.Uint32{Uint32: pgtype.TextOID, Valid: true}),
}, },
{pgtype.Uint32{}, new(pgtype.Uint32), isExpectedEq(pgtype.Uint32{})}, {pgtype.Uint32{}, new(pgtype.Uint32), isExpectedEq(pgtype.Uint32{})},
{nil, new(pgtype.Uint32), isExpectedEq(pgtype.Uint32{})}, {nil, new(pgtype.Uint32), isExpectedEq(pgtype.Uint32{})},