Skip to content

Commit

Permalink
use normalized equality or strict equality check in rows.go fieldPosB…
Browse files Browse the repository at this point in the history
…yName
  • Loading branch information
nolandseigler committed Jul 12, 2024
1 parent b25d092 commit 71a8e53
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,21 +816,21 @@ func computeNamedStructFields(

const structTagKey = "db"

func fieldPosByName(fldDescs []pgconn.FieldDescription, field string, replace bool) (i int) {
func fieldPosByName(fldDescs []pgconn.FieldDescription, field string, normalize bool) (i int) {
i = -1
if replace {

if normalize {
field = strings.ReplaceAll(field, "_", "")
}
for i, desc := range fldDescs {

// Snake case support.
descName := desc.Name
if replace {
descName = strings.ReplaceAll(desc.Name, "_", "")
}

if strings.EqualFold(descName, field) {
return i
if normalize {
if strings.EqualFold(strings.ReplaceAll(desc.Name, "_", ""), field) {
return i
}
} else {
if desc.Name == field {
return i
}
}
}
return
Expand Down

0 comments on commit 71a8e53

Please sign in to comment.