diff --git a/README.rst b/README.rst index 6a4930d..204f721 100644 --- a/README.rst +++ b/README.rst @@ -252,6 +252,7 @@ This is the list of operators that can be used: - ``>=``, ``ge`` - ``<=``, ``le`` - ``like`` +- ``ilike`` - ``in`` - ``not_in`` diff --git a/sqlalchemy_filters/filters.py b/sqlalchemy_filters/filters.py index 0cf557b..ecc56e7 100644 --- a/sqlalchemy_filters/filters.py +++ b/sqlalchemy_filters/filters.py @@ -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), } diff --git a/test/interface/test_filters.py b/test/interface/test_filters.py index 2ef1941..3c8cf75 100644 --- a/test/interface/test_filters.py +++ b/test/interface/test_filters.py @@ -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')