From 686213c438654455cda6c84cad0d3a758eef5898 Mon Sep 17 00:00:00 2001 From: Tikhon Fedulov Date: Fri, 22 Dec 2023 23:04:44 +0300 Subject: [PATCH] Add snake_case support to RowToStructByName --- rows.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rows.go b/rows.go index 73efffa0a..2bb95d1f1 100644 --- a/rows.go +++ b/rows.go @@ -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 }