datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
richiardiandrea 2020-02-09T01:58:20.012600Z

Hi there, I have a question...I have data in this shape:

({:product/code "42"
  :sku/code "1"
  :product/names [{:product/name "Camera"
                   :language/iso-639-1 "en"}
                  {:product/name "Appareil"
                   :language/iso-639-1 "fr"}]
  :product/type "Camcorders & Digital Cameras"}
 ...)
and schema
(def schema {:product/code {:db/unique :db.unique/identity}
             :product/names {:db/valueType   :db.type/ref
                             :db/cardinality :db.cardinality/many
                             :db/isComponent true}
             :language/iso-639-1 {:db/valueType   :db.type/ref
                                  :db/isComponent true}})
Is it expected that I see these datoms?
[1 :product/code "42" 536870913 true]
[1 :product/names 2 536870913 true]
[1 :product/names 4 536870913 true]
[1 :product/type "Camcorders & Digital Cameras" 536870913 true]
[1 :sku/code "1" 536870913 true]
[2 :language/iso-639-1 3 536870913 true]
[2 :product/name "Camera" 536870913 true]
[4 :language/iso-639-1 5 536870913 true]
[4 :product/name "Appareil" 536870913 true]
If yes, why is it not showing me the language in:
(datascript/pull db ["*"] 3)
=> #:db{:id 3}

richiardiandrea 2020-02-09T01:59:13.013400Z

In the above the entity 3 should have attribute "en" but I never see it in the list of datoms

richiardiandrea 2020-02-09T01:59:28.013700Z

(`5` is "fr")

richiardiandrea 2020-02-09T02:18:10.014800Z

I am basically trying to have one datom per :language/iso-639-1 and refer to those from the product/name

richiardiandrea 2020-02-09T04:36:07.015500Z

Oh I see, if it's a ref I cannot really go back to the values - kind of makes sense

richiardiandrea 2020-02-09T04:38:08.015900Z

I wonder how I can model that now though

richiardiandrea 2020-02-09T05:07:07.016600Z

(as a note, I am letting datascript create the entities, no :db/add on my side)

richiardiandrea 2020-02-09T05:27:01.017200Z

uhm...I see I receive back some

(:tempids txs)
{"en" 3, "fr" 5, :db/current-tx 536870913}
still not clear ... digging digging

richiardiandrea 2020-02-09T21:30:51.018700Z

for my problem above, I am still trying to understand how to model, it feels like I need a composite key [:product/name :language] - is it something you usually do in datascript/datomic?

richiardiandrea 2020-02-09T21:34:32.018900Z

oh just discovered https://docs.datomic.com/on-prem/schema.html#composite-tuples

richiardiandrea 2020-02-09T21:37:14.019200Z

and https://github.com/tonsky/datascript/issues/323