Skip to content

Commit

Permalink
transforms should handle [:in <field> <set>] (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul authored Jan 4, 2023
1 parent a539c38 commit 6241460
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/toucan2/tools/transformed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
(sequential? v)
(into [(first v)]
(map (fn xform* [v]
(if (sequential? v)
(if (or (sequential? v)
(set? v))
(mapv xform* v)
(xform v))))
(rest v))
Expand Down
23 changes: 11 additions & 12 deletions test/toucan2/tools/transformed_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,17 @@
{:id 2, :name "Ho's Tavern", :category :bar}]
(select/select ::venues.category-keyword :category :bar {:select [:id :name :category]
:order-by [[:id :asc]]})))
(testing "Toucan-style [f & args] condition"
(is (= [{:id 1, :name "Tempest", :category :bar}
{:id 2, :name "Ho's Tavern", :category :bar}]
(select/select ::venues.category-keyword :category [:= :bar]
{:select [:id :name :category]
:order-by [[:id :asc]]})
(select/select ::venues.category-keyword :category [:in [:bar]]
{:select [:id :name :category]
:order-by [[:id :asc]]})
(select/select ::venues.category-keyword :category [:in [:bar :saloon]]
{:select [:id :name :category]
:order-by [[:id :asc]]})))))
(testing "Toucan-style [f & args] condition\n"
(are [condition] (= [{:id 1, :name "Tempest", :category :bar}
{:id 2, :name "Ho's Tavern", :category :bar}]
(select/select ::venues.category-keyword :category condition
{:select [:id :name :category]
:order-by [[:id :asc]]}))
[:= :bar]
[:in [:bar]]
[:in [:bar :saloon]]
[:in #{:bar :saloon}]
[:in (list :bar :saloon)])))
(testing "as the PK"
(testing "(single value)"
(is (= [{:id "1", :name "Tempest", :category :bar}]
Expand Down

0 comments on commit 6241460

Please sign in to comment.