mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
SQL view-friendly arraycontains/arraynotcontains implementation, refs #448
This commit is contained in:
parent
502c02fa6d
commit
07044bd130
2 changed files with 9 additions and 12 deletions
|
|
@ -149,19 +149,13 @@ class Filters:
|
|||
TemplatedFilter(
|
||||
"arraycontains",
|
||||
"array contains",
|
||||
"""rowid in (
|
||||
select {t}.rowid from {t}, json_each([{t}].[{c}]) j
|
||||
where j.value = :{p}
|
||||
)""",
|
||||
""":{p} in (select value from json_each([{t}].[{c}]))""",
|
||||
'{c} contains "{v}"',
|
||||
),
|
||||
TemplatedFilter(
|
||||
"arraynotcontains",
|
||||
"array does not contain",
|
||||
"""rowid not in (
|
||||
select {t}.rowid from {t}, json_each([{t}].[{c}]) j
|
||||
where j.value = :{p}
|
||||
)""",
|
||||
""":{p} not in (select value from json_each([{t}].[{c}]))""",
|
||||
'{c} does not contain "{v}"',
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -56,12 +56,15 @@ import pytest
|
|||
# Not in, and JSON array not in
|
||||
((("foo__notin", "1,2,3"),), ["foo not in (:p0, :p1, :p2)"], ["1", "2", "3"]),
|
||||
((("foo__notin", "[1,2,3]"),), ["foo not in (:p0, :p1, :p2)"], [1, 2, 3]),
|
||||
# JSON arraycontains
|
||||
# JSON arraycontains, arraynotcontains
|
||||
(
|
||||
(("Availability+Info__arraycontains", "yes"),),
|
||||
[
|
||||
"rowid in (\n select table.rowid from table, json_each([table].[Availability+Info]) j\n where j.value = :p0\n )"
|
||||
],
|
||||
[":p0 in (select value from json_each([table].[Availability+Info]))"],
|
||||
["yes"],
|
||||
),
|
||||
(
|
||||
(("Availability+Info__arraynotcontains", "yes"),),
|
||||
[":p0 not in (select value from json_each([table].[Availability+Info]))"],
|
||||
["yes"],
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue