This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-01
Channels
- # aleph (2)
- # announcements (3)
- # architecture (9)
- # babashka (56)
- # beginners (18)
- # calva (7)
- # cider (18)
- # cljfx (3)
- # cljs-dev (23)
- # clojure-europe (11)
- # clojure-hungary (1)
- # clojure-nl (2)
- # clojure-norway (24)
- # clojure-sweden (2)
- # clojurescript (37)
- # code-reviews (47)
- # datalog (3)
- # datomic (8)
- # emacs (11)
- # events (2)
- # graalvm (7)
- # gratitude (1)
- # hyperfiddle (12)
- # java (1)
- # jvm (46)
- # kaocha (3)
- # life (16)
- # lsp (3)
- # malli (4)
- # matcher-combinators (1)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # releases (1)
- # sci (15)
- # shadow-cljs (21)
- # slack-help (21)
- # tools-deps (17)
#datalog
<
2023-09-01Hi. Is there a way to query for an entity that has a specific set of references (through a cardinality-many db.type/ref), but no other references? For example, using the following schema:
[#:db{:ident :combination/name
:valueType :db.type/string}
#:db{:ident :combination/widget
:valueType :db.type/ref
:cardinality :db.cardinality/many}
#:db{:ident :combination/some-important-data-to-know-about-this-combo-of-widgets
:valueType :db.type/string}
#:db{:ident :widget/sku
:valueType :db.type/string}]
I want to find the “combination” that refers to widgets 1000 and 2000. So maybe a query like this:
(d/q
'[:find (pull ?e [:db/id :combination/some-important-data-to-know-about-this-combo-of-widgets])
:where
[?e :combination/widget 1000]
[?e :combination/widget 2000]]
db)
But the number of referenced widgets in a combination could also be 1 or 3 or 4 or any number. So,
here I would want to find ONLY the combo with 1000 and 2000, but NOT a combo referred to 1000, 2000 and 3000.Unless someone has a better answer, you’d have to compute your own specialized index for this by tailing the transaction report queue
👌 2
I‘m not at my computer, so I can’t test. But could you count the number of widgets and see if you have exactly two? [?e :widget ?widgets] [(contains? #{1000 2000} ?widgets)] [(count ?widgets) ?no-of-widgets] [(= ?no-of-widgets 2)]