Skip to content

Commit

Permalink
Added 'not like' table filter, refs #750
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 2, 2020
1 parent 4df1b4d commit b3aa5f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datasette/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class Filters:
"lte", "\u2264", '"{c}" <= :{p}', "{c} \u2264 {v}", numeric=True
),
TemplatedFilter("like", "like", '"{c}" like :{p}', '{c} like "{v}"'),
TemplatedFilter(
"notlike", "not like", '"{c}" not like :{p}', '{c} not like "{v}"'
),
TemplatedFilter("glob", "glob", '"{c}" glob :{p}', '{c} glob "{v}"'),
InFilter(),
NotInFilter(),
Expand Down
3 changes: 3 additions & 0 deletions docs/json_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ You can filter the data returned by the table based on column values using a que
``?column__like=value``
Match rows with a LIKE clause, case insensitive and with ``%`` as the wildcard character.

``?column__notlike=value``
Match rows that do not match the provided LIKE clause.

``?column__glob=value``
Similar to LIKE but uses Unix wildcard syntax and is case sensitive.

Expand Down
2 changes: 2 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
['"foo" like :p0', '"foo" like :p1'],
["2%2", "3%3"],
),
# notlike:
((("foo__notlike", "2%2"),), ['"foo" not like :p0'], ["2%2"],),
(
(("foo__isnull", "1"), ("baz__isnull", "1"), ("bar__gt", "10")),
['"bar" > :p0', '"baz" is null', '"foo" is null'],
Expand Down

0 comments on commit b3aa5f4

Please sign in to comment.