Skip to content

Commit

Permalink
New ?column__date=yyyy-mm-dd filter
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 15, 2019
1 parent 1c6649b commit 583b22a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions datasette/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Filters:
where j.value = :{p}
)""", '{c} contains "{v}"')
] if detect_json1() else []) + [
TemplatedFilter('date', 'date', 'date({c}) = :{p}', '"{c}" is on date {v}'),
TemplatedFilter('isnull', 'is null', '"{c}" is null', '{c} is null', no_argument=True),
TemplatedFilter('notnull', 'is not null', '"{c}" is not null', '{c} is not null', no_argument=True),
TemplatedFilter('isblank', 'is blank', '("{c}" is null or "{c}" = "")', '{c} is blank', no_argument=True),
Expand Down
3 changes: 3 additions & 0 deletions docs/json_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ You can filter the data returned by the table based on column values using a que

This is only available if the ``json1`` SQLite extension is enabled.

``?column__date=value``
Column is a datestamp occurring on the specified YYYY-MM-DD date, e.g. ``2018-01-02``.

``?column__isnull=1``
Matches rows where the column is null.

Expand Down
8 changes: 8 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
['foo in (:p0, :p1, :p2)'],
["1", "2", "3"]
),
# date
(
{
"foo__date": "1988-01-01",
},
["date(foo) = :p0"],
["1988-01-01"]
),
# JSON array variants of __in (useful for unexpected characters)
(
{
Expand Down

0 comments on commit 583b22a

Please sign in to comment.