Skip to content

Commit

Permalink
chore(opts): Removing case-insensative ignore field, cases now need t…
Browse files Browse the repository at this point in the history
…o match (#100)

Removing case insensative ignore field, cases now need to match
  • Loading branch information
Jacobbrewer1 authored Jan 23, 2025
1 parent 53e78e8 commit 82648e3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ func (s *SQLPatch) checkSkipTag(field reflect.StructField) bool {
}

func (s *SQLPatch) ignoredFieldsCheck(field reflect.StructField) bool {
return s.checkIgnoredFields(strings.ToLower(field.Name)) || s.checkIgnoreFunc(field)
return s.checkIgnoredFields(field.Name) || s.checkIgnoreFunc(field)
}

func (s *SQLPatch) checkIgnoreFunc(field reflect.StructField) bool {
return s.ignoreFieldsFunc != nil && s.ignoreFieldsFunc(field)
}

func (s *SQLPatch) checkIgnoredFields(field string) bool {
return len(s.ignoreFields) > 0 && slices.Contains(s.ignoreFields, strings.ToLower(field))
return len(s.ignoreFields) > 0 && slices.Contains(s.ignoreFields, field)
}
6 changes: 3 additions & 3 deletions loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func (s *loadDiffSuite) TestLoadDiff_Success_Include_Nil_false() {

func (s *loadDiffSuite) TestLoadDiff_Success_IgnoreFields() {
l := s.patch
l.ignoreFields = []string{"name"}
l.ignoreFields = []string{"Name"}

type testStruct struct {
Name string
Expand Down Expand Up @@ -728,7 +728,7 @@ func (s *loadDiffSuite) TestLoadDiff_Success_IgnoreFieldsFuncAndIgnoreFields() {
func (s *loadDiffSuite) TestLoadDiff_Success_Blank_Except_Id() {
l := s.patch
l.includeZeroValues = true
l.ignoreFields = []string{"id"}
l.ignoreFields = []string{"ID"}

type testStruct struct {
ID int
Expand Down Expand Up @@ -758,7 +758,7 @@ func (s *loadDiffSuite) TestLoadDiff_Success_Blank_Except_Id() {
func (s *loadDiffSuite) TestLoadDiff_Success_Skip_Priority_Check() {
l := s.patch
l.includeZeroValues = true
l.ignoreFields = []string{"id"}
l.ignoreFields = []string{"ID"}

type testStruct struct {
ID int
Expand Down
5 changes: 0 additions & 5 deletions patch_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package patcher

import (
"database/sql"
"strings"
)

const (
Expand Down Expand Up @@ -75,10 +74,6 @@ func WithIncludeNilValues() PatchOpt {
// case-sensitive.
func WithIgnoredFields(fields ...string) PatchOpt {
return func(s *SQLPatch) {
for i := range fields {
fields[i] = strings.ToLower(fields[i])
}

s.ignoreFields = fields
}
}
Expand Down
2 changes: 1 addition & 1 deletion sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func NewDiffSQLPatch[T any](old, newT *T, opts ...PatchOpt) (*SQLPatch, error) {
if patch.ignoreFields == nil {
patch.ignoreFields = make([]string, 0)
}
patch.ignoreFields = append(patch.ignoreFields, strings.ToLower(oldElem.Type().Field(i).Name))
patch.ignoreFields = append(patch.ignoreFields, oldElem.Type().Field(i).Name)
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success_IgnoredFields() {
Description: nil,
}

patch := NewSQLPatch(obj, WithIncludeNilValues(), WithIncludeZeroValues(), WithIgnoredFields("id", "description"))
patch := NewSQLPatch(obj, WithIncludeNilValues(), WithIncludeZeroValues(), WithIgnoredFields("Id", "Description"))

s.Equal([]string{"name = ?"}, patch.fields)
s.Equal([]any{""}, patch.args)
Expand Down

0 comments on commit 82648e3

Please sign in to comment.