Doc tweaks and renames

non-blocking
Jack Christensen 2020-05-10 12:45:12 -05:00
parent a71c179ce3
commit cc4d1eafe0
2 changed files with 12 additions and 14 deletions

View File

@ -16,14 +16,14 @@ type enumType struct {
value string
status Status
pgTypeName string // PostgreSQL type name
typeName string // PostgreSQL type name
members []string // enum members
membersMap map[string]string // map to quickly lookup member and reuse string instead of allocating
}
// NewEnumType initializes a new EnumType. It retains a read-only reference to members. members must not be changed.
func NewEnumType(pgTypeName string, members []string) EnumType {
et := &enumType{pgTypeName: pgTypeName, members: members}
func NewEnumType(typeName string, members []string) EnumType {
et := &enumType{typeName: typeName, members: members}
et.membersMap = make(map[string]string, len(members))
for _, m := range members {
et.membersMap[m] = m
@ -36,14 +36,14 @@ func (et *enumType) CloneTypeValue() Value {
value: et.value,
status: et.status,
pgTypeName: et.pgTypeName,
typeName: et.typeName,
members: et.members,
membersMap: et.membersMap,
}
}
func (et *enumType) PgTypeName() string {
return et.pgTypeName
func (et *enumType) TypeName() string {
return et.typeName
}
func (et *enumType) Members() []string {
@ -87,7 +87,7 @@ func (dst *enumType) Set(src interface{}) error {
if originalSrc, ok := underlyingStringType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to enum %s", value, dst.pgTypeName)
return errors.Errorf("cannot convert %v to enum %s", value, dst.typeName)
}
return nil

View File

@ -128,10 +128,8 @@ type Value interface {
AssignTo(dst interface{}) error
}
// TypeValue represents values where instances represent a type. In the normal pgtype model a Go type maps to a
// PostgreSQL type and an instance of a Go type maps to a PostgreSQL value of that type. Implementors of TypeValue
// are different in that an instance represents a PostgreSQL type. This can be useful for representing types such
// as enums, composites, and arrays.
// TypeValue represents values where instances can represent different PostgreSQL types. This can be useful for
// representing types such as enums, composites, and arrays.
//
// In general, instances of TypeValue should not be used to directly represent a value. It should only be used as an
// encoder and decoder internal to ConnInfo.
@ -140,8 +138,8 @@ type TypeValue interface {
// in an EnumType.
CloneTypeValue() Value
// PgTypeName returns the PostgreSQL name of this type.
PgTypeName() string
// TypeName returns the PostgreSQL name of this type.
TypeName() string
}
type BinaryDecoder interface {
@ -433,7 +431,7 @@ func (ci *ConnInfo) DataTypeForValue(v interface{}) (*DataType, bool) {
}
if tv, ok := v.(TypeValue); ok {
dt, ok := ci.nameToDataType[tv.PgTypeName()]
dt, ok := ci.nameToDataType[tv.TypeName()]
return dt, ok
}