This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-01
Channels
- # announcements (14)
- # beginners (6)
- # biff (6)
- # calva (3)
- # cider (7)
- # clojure (79)
- # clojure-europe (5)
- # clojure-norway (9)
- # cursive (9)
- # data-science (20)
- # datomic (3)
- # fulcro (9)
- # graalvm (15)
- # integrant (2)
- # introduce-yourself (2)
- # jobs (1)
- # lsp (7)
- # malli (5)
- # off-topic (130)
- # parinfer (11)
- # pedestal (11)
- # portal (1)
- # practicalli (4)
- # releases (3)
- # remote-jobs (1)
- # ring (8)
- # ring-swagger (30)
- # shadow-cljs (9)
- # sql (10)
- # tools-deps (8)
Is there a way to express this in a query:
How to find all labels for which ::value is > 100 OR ::key is a member of a set we provide. if we don't provide any keys, just use the > 100
predicate only.
[I know this minimal example I could just use e.g. d/datoms
but in the "real" example I'm attempting there's more joining going on where putting it all in one query would be convenient.]
(d/transact conn1
{:tx-data
[{:db/ident ::key
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/one}
{:db/ident ::value
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident ::label
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]})
(d/transact conn1
{:tx-data
[{::key :a
::label "a"
::value 101}
{::key :b
::label "b"
::value 50}
{::key :c
::label "c"
::value 50}
]})
(d/q
'[:find ?label
:in $ [?provided ...]
:where
[?e ::label ?label]
(or-join [?e ?provided]
(and [?e ::value ?value]
[(> ?value 100)])
[?e ::key ?provided])
]
(d/db conn1)
[:b])
;; Works if we provide some keys
;;=> [["a"] ["b"]]
(d/q
'[:find ?label
:in $ [?provided ...]
:where
[?e ::label ?label]
(or-join [?e ?provided]
(and [?e ::value ?value]
[(> ?value 100)])
[?e ::key ?provided])
]
(d/db conn1)
[])
;; But returns nothing if we provide no keys
;; []