Skip to content

Commit

Permalink
Support ilike (#19)
Browse files Browse the repository at this point in the history
* Add support for ilike too

* Update README and unit tests
  • Loading branch information
rockwelln authored and mattbennett committed Jun 25, 2018
1 parent 6347ca0 commit f938806
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ This is the list of operators that can be used:
- ``>=``, ``ge``
- ``<=``, ``le``
- ``like``
- ``ilike``
- ``in``
- ``not_in``
Expand Down
1 change: 1 addition & 0 deletions sqlalchemy_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Operator(object):
'<=': lambda f, a: f <= a,
'le': lambda f, a: f <= a,
'like': lambda f, a: f.like(a),
'ilike': lambda f, a: f.ilike(a),
'in': lambda f, a: f.in_(a),
'not_in': lambda f, a: ~f.in_(a),
}
Expand Down
15 changes: 15 additions & 0 deletions test/interface/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,21 @@ def test_one_filter_applied_to_a_single_model(self, session):
assert result[1].id == 3


class TestApplyILikeFilter:

@pytest.mark.usefixtures('multiple_bars_inserted')
def test_one_filter_applied_to_a_single_model(self, session):
query = session.query(Bar)
filters = [{'field': 'name', 'op': 'ilike', 'value': '%ME_1'}]

filtered_query = apply_filters(query, filters)
result = filtered_query.all()

assert len(result) == 2
assert result[0].id == 1
assert result[1].id == 3


class TestApplyInFilter:

@pytest.mark.usefixtures('multiple_bars_inserted')
Expand Down

0 comments on commit f938806

Please sign in to comment.