diff --git a/datasette/filters.py b/datasette/filters.py index abaafc5b..483f031f 100644 --- a/datasette/filters.py +++ b/datasette/filters.py @@ -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), diff --git a/docs/json_api.rst b/docs/json_api.rst index 67700224..ef1b4548 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -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. diff --git a/tests/test_filters.py b/tests/test_filters.py index a5d6e3d0..7b19c4e9 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -60,6 +60,14 @@ import pytest ['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) ( {