sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Can you specify name to be case insensitive

Open sjmark opened this issue 3 years ago • 2 comments

190 lines of a reflectx/reflect.go

func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error { t = Deref(t) mustBe(t, reflect.Struct) tm := m.TypeMap(t) for i, name := range names { fi, ok := tm.Names[name] if !ok { if err := fn(i, nil); err != nil { return err } } else { if err := fn(i, fi.Index); err != nil { return err } } } return nil }

sjmark avatar Mar 23 '23 09:03 sjmark

#859 sure, To make the TraversalsByNameFunc function in your code case-insensitive, you can modify the fi, ok := tm.Names[name] line to convert the name to lowercase using the strings.ToLower()

you can modify the fi, ok := tm.Names[name] line to convert the name to lowercase using the strings.ToLower() function

tm.Names[strings.ToLower(name)]

This way, the function will find struct fields regardless of the case of their names.

farid-alfernass avatar May 04 '23 03:05 farid-alfernass

这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

sjmark avatar May 04 '23 03:05 sjmark