Skip to content

Commit

Permalink
fix(like): fix LIKE behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffrey Bauduin <[email protected]>
  • Loading branch information
geoffreybauduin committed Sep 29, 2020
1 parent 8693fc5 commit c547178
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions filterapply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,19 @@ func TestFilterApplier_ApplyRaw_EscapedFields(t *testing.T) {
assert.Len(t, models, 1)
assert.Equal(t, models[0].(*testdata.TwoI).ID, category.ID)
}

func TestFilterApply_Like(t *testing.T) {
killDb, err := testdata.SetupTestDatabase("test")
defer killDb()
assert.Nil(t, err)
dbp, err := yaorm.NewDBProvider(context.TODO(), "test")
assert.Nil(t, err)
category := &testdata.TwoI{Name: "category"}
saveModel(t, dbp, category)
category2 := &testdata.TwoI{Name: "category2"}
saveModel(t, dbp, category2)

models, err := yaorm.GenericSelectAll(dbp, testdata.NewTwoIFilter().Name(yaormfilter.Like("category%")))
assert.Nil(t, err)
assert.Len(t, models, 2)
}
2 changes: 1 addition & 1 deletion yaormfilter/valuefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *valuefilterimpl) notEquals(e interface{}) *valuefilterimpl {

func (f *valuefilterimpl) like(e interface{}) *valuefilterimpl {
return f.raw(func(field string) interface{} {
return fmt.Sprintf("%s LIKE %s", field, e)
return squirrel.Expr(fmt.Sprintf("%s LIKE ?", field), e)
})
}

Expand Down

0 comments on commit c547178

Please sign in to comment.