Skip to content

Commit 583b22a

Browse files
committed
New ?column__date=yyyy-mm-dd filter
1 parent 1c6649b commit 583b22a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

datasette/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Filters:
100100
where j.value = :{p}
101101
)""", '{c} contains "{v}"')
102102
] if detect_json1() else []) + [
103+
TemplatedFilter('date', 'date', 'date({c}) = :{p}', '"{c}" is on date {v}'),
103104
TemplatedFilter('isnull', 'is null', '"{c}" is null', '{c} is null', no_argument=True),
104105
TemplatedFilter('notnull', 'is not null', '"{c}" is not null', '{c} is not null', no_argument=True),
105106
TemplatedFilter('isblank', 'is blank', '("{c}" is null or "{c}" = "")', '{c} is blank', no_argument=True),

docs/json_api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ You can filter the data returned by the table based on column values using a que
233233

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

236+
``?column__date=value``
237+
Column is a datestamp occurring on the specified YYYY-MM-DD date, e.g. ``2018-01-02``.
238+
236239
``?column__isnull=1``
237240
Matches rows where the column is null.
238241

tests/test_filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
['foo in (:p0, :p1, :p2)'],
6161
["1", "2", "3"]
6262
),
63+
# date
64+
(
65+
{
66+
"foo__date": "1988-01-01",
67+
},
68+
["date(foo) = :p0"],
69+
["1988-01-01"]
70+
),
6371
# JSON array variants of __in (useful for unexpected characters)
6472
(
6573
{

0 commit comments

Comments
 (0)