datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
oly 2020-08-27T09:19:45.019400Z

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 ?

oly 2020-08-27T09:20:45.021Z

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 ?

pithyless 2020-08-27T09:28:27.027100Z

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

oly 2020-08-27T09:29:18.028100Z

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

oly 2020-08-27T09:30:05.029Z

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

oly 2020-08-27T09:45:25.030300Z

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

🤘 1
Casey 2020-08-27T09:47:18.030800Z

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?

Casey 2020-08-28T08:20:55.038900Z

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

oly 2020-08-27T09:48:18.031600Z

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

pithyless 2020-08-27T10:00:21.032100Z

Keynote and lots of coffee. 😂

oly 2020-08-27T10:40:45.035300Z

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 ?

oly 2020-08-27T10:41:21.035800Z

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

oly 2020-08-27T10:47:04.036900Z

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

✔️ 1
oly 2020-08-27T11:09:56.037500Z

is something like in possible in datalog where query ?

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

oly 2020-08-27T11:18:54.038400Z

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