Merge pull request #2203 from martinyonatann/chore/check-array-and-remove-imposible-condition

check array just using `len` and remove `imposible condition`
pull/2208/head
Jack Christensen 2024-12-24 11:10:45 -06:00 committed by GitHub
commit f7c3d190ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 9 deletions

View File

@ -161,7 +161,7 @@ type derivedTypeInfo struct {
// The result of this call can be passed into RegisterTypes to complete the process. // The result of this call can be passed into RegisterTypes to complete the process.
func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Type, error) { func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Type, error) {
m := c.TypeMap() m := c.TypeMap()
if typeNames == nil || len(typeNames) == 0 { if len(typeNames) == 0 {
return nil, fmt.Errorf("No type names were supplied.") return nil, fmt.Errorf("No type names were supplied.")
} }
@ -232,7 +232,8 @@ func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Typ
default: default:
return nil, fmt.Errorf("Unknown typtype %q was found while registering %q", ti.Typtype, ti.TypeName) return nil, fmt.Errorf("Unknown typtype %q was found while registering %q", ti.Typtype, ti.TypeName)
} }
if type_ != nil {
// the type_ is imposible to be null
m.RegisterType(type_) m.RegisterType(type_)
if ti.NspName != "" { if ti.NspName != "" {
nspType := &pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec} nspType := &pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec}
@ -241,7 +242,6 @@ func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Typ
} }
result = append(result, type_) result = append(result, type_)
} }
}
return result, nil return result, nil
} }