Got another question with d/q if you query a product which has many prices related to an entity can you get a list with in a list response or would I be doing 2 queries to achieve this ?
so would I query for the products retrieve the entity ids to then query for the related prices or is there a way to do this in a single query ?
@oliver.marks - I think your last two questions are essentially the same; I usually approach them like this: use q
to query, use pull
to pull.
1. Find the subset of eids that match my expectation via q
(or even multiple q
)
2. Then forget about querying and use pull
(either as (pull ..)
inside q, or via d/pull
or d/pull-many
) to fetch everything I'm actually interested.
3. Then, use clojure for data munging if my pull result does not line up with my expected output.
yeah I just went and looked at the previous message after noticing it had replies, I wonder if you can change that so it does not thread
but I am having a read through and thanks for the detailed responses hopefully it will help direct me in the right direction
@pithyless just realised it was your youtube video I watched which got me interested in datalog great work 🙂
Yea, it's a great video. The visualizations/slides were very well done. Must have been tons of work doing the highlighting. What did you use to create it?
major props, it was a great talk and a great use of code on slides.
yeah its very slick for a live talk very few have that sort of quality.
Keynote and lots of coffee. 😂
making some headway
(->> (d/q
'[:find ?e
:where
[?e :product/id ?product-id]
[?e :product/name ?product-name]]
(d/db conn))
(map (fn [eid]
(d/pull
(d/db conn)
'[* :price/_product]
(first eid)))))
This seems to return all the prices under the :price/_product key can i extend that to be the price eid and amount or will i need to map again to pull the extra details ?guessing i can do the pull in the query actually, but same question applies
okay think i am getting there the discovery of _product has helped.
(d/q
'[:find (pull ?e [* {:price/_product [:price/amount]}])
:where
[?e :product/id ?product-id]]
(d/db conn))
that is nearing what I want I believe i need to just flatten out the result now so i can make a csvis something like in possible in datalog where query ?
[?condition-eid :condition/slug ["good" "bad"]]
(or [?condition-eid :condition/slug "good"]
[?condition-eid :condition/slug "bad"])
that seems to work