Fork me on GitHub
#datascript
<
2020-08-27
>
oly09:08:45

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 ?

oly09:08:45

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 ?

pithyless09:08:27

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

oly09:08:18

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

oly09:08:05

but I am having a read through and thanks for the detailed responses hopefully it will help direct me in the right direction

oly09:08:25

@pithyless just realised it was your youtube video I watched which got me interested in datalog great work 🙂

metal 3
Casey09:08:18

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?

pithyless10:08:21

Keynote and lots of coffee. 😂

Casey08:08:55

major props, it was a great talk and a great use of code on slides.

oly09:08:18

yeah its very slick for a live talk very few have that sort of quality.

oly10:08:45

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 ?

oly10:08:21

guessing i can do the pull in the query actually, but same question applies

oly10:08:04

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 csv

✔️ 3
oly11:08:56

is something like in possible in datalog where query ?

[?condition-eid :condition/slug ["good" "bad"]]

oly11:08:54

(or [?condition-eid :condition/slug "good"] 
    [?condition-eid :condition/slug "bad"])
that seems to work