From 1c5977961f596dae5aaa18c8b2d7a10e9f42a543 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 24 Oct 2017 18:53:01 -0700 Subject: [PATCH] Added glob and like lookups - refs #23 --- app.py | 2 ++ test_helpers.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/app.py b/app.py index 8806fa8f..3018ab74 100644 --- a/app.py +++ b/app.py @@ -329,6 +329,8 @@ def build_where_clause(args): 'gte': '"{}" >= ?', 'lt': '"{}" < ?', 'lte': '"{}" <= ?', + 'glob': '"{}" glob ?', + 'like': '"{}" like ?', }[lookup] value = values[0] value_convert = { diff --git a/test_helpers.py b/test_helpers.py index 4f00ef55..8a4e006f 100644 --- a/test_helpers.py +++ b/test_helpers.py @@ -100,6 +100,14 @@ def test_custom_json_encoder(obj, expected): '"bar" > ? and "bax" <= ? and "baz" >= ? and "foo" < ?', ['2', '4', '3', '1'] ), + ( + { + 'foo__like': ['2%2'], + 'zax__glob': ['3*'], + }, + '"foo" like ? and "zax" glob ?', + ['2%2', '3*'] + ), ]) def test_build_where(args, expected_where, expected_params): actual_where, actual_params = app.build_where_clause(args)