Skip to content

Commit

Permalink
Add snake_case support to RowToStructByName
Browse files Browse the repository at this point in the history
  • Loading branch information
hello-users9 committed Dec 22, 2023
1 parent 9ab9e3c commit 686213c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ const structTagKey = "db"
func fieldPosByName(fldDescs []pgconn.FieldDescription, field string) (i int) {
i = -1
for i, desc := range fldDescs {

// Support snake and spinal case.
desc.Name = strings.ReplaceAll(desc.Name, "_", "")
desc.Name = strings.ReplaceAll(desc.Name, "-", "")

if strings.EqualFold(desc.Name, field) {
return i
}
Expand Down

0 comments on commit 686213c

Please sign in to comment.