datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Andrew 2020-08-19T14:44:14.144500Z

I guess you need [(< 0 ?p)] to express a predicate, right now datascript thinks it's a rule expression. https://docs.datomic.com/on-prem/query.html#expression-clauses

oly 2020-08-19T15:57:13.147300Z

wondering if some one can help I am playing with datascript and the a bit confused on :db/ref if i query some thing that has a ref I get it returned as #:db{:id 1} can that not auro resolve back the attributes ?

oly 2020-08-19T15:57:30.147600Z

(def schema {:type/id     {:db/unique :db.unique/identity}
             :product/id {:db/unique :db.unique/identity}
             :product/type {:db/valueType :db.type/ref}})

(def conn (d/create-conn schema))

(d/transact!
 conn
 [{:type/id 1 :type/name "type 1"}
  {:type/id 2 :type/name "type 2"}
  {:product/id 1 :product/name "p1" :product/type [:type/id 1]}
  {:product/id 2 :product/name "p2" :product/type [:type/id 2]}])

(d/q '[:find  (pull ?e [*])
       :where
       [?e :product/id]] @conn)

oly 2020-08-19T15:58:02.148100Z

That's my simple example which returns

0. [ { :db/id 4, :product/id 1, :product/name "p1", :product/type { :db/id 1 } } ]

oly 2020-08-19T15:58:54.149100Z

I am wondering if I can make it return :type/name in the row and other type related attributes instead of :product/type {:db/id 1}

oly 2020-08-19T15:59:32.149800Z

feel free to point me at docs, could be I have just been missing or mis understanding how it works

lilactown 2020-08-19T16:09:00.151500Z

@oliver.marks I believe * only gets all of the attributes one level deep. you could try playing around with something like:

(d/q '[:find (pull ?e [* {:product/type [*]}])
       :where
       [?e :product/id]] @conn)

lilactown 2020-08-19T16:09:08.151700Z

(I haven’t tried that)

lilactown 2020-08-19T16:09:15.151900Z

(I’m also not very good at datalog)

oly 2020-08-19T16:39:32.152800Z

@lilactown spot on that's works perfectly 🙂