datalog

mlimotte 2023-09-01T16:46:39.808879Z

Hi. 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.

2023-09-03T03:05:06.443199Z

Unless someone has a better answer, you’d have to compute your own specialized index for this by tailing the transaction report queue

👌 1
Björn Ebbinghaus 2023-10-23T20:32:43.469319Z

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)]