@richiardiandrea to answer your specific question,
(d/pull @conn '[*] 2)
will give you the language. You can try for yourself:
(def db (d/empty-db {: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}}))
(def conn (d/conn-from-db db))
(d/transact
conn
(mapv (fn [tuple] (into [:db/add] tuple))
[[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]]))
(d/pull @conn '[*] 2)
;;=> {:db/id 2, :language/iso-639-1 {:db/id 3}, :product/name "Camera"}
it will also show up in these circumstances:
(d/q '[:find ?e (pull ?e [*]) :where [?e :product/code]] @conn)
;; => ([1 {:db/id 1, :product/code "42", :product/names [{:db/id 2, :language/iso-639-1 {:db/id 3}, :product/name "Camera"} {:db/id 4, :language/iso-639-1 {:db/id 5}, :product/name "Appareil"}], :product/type "Camcorders & Digital Cameras", :sku/code "1"}])
and
(d/pull @conn '[*] [:product/code "42"])
;;=> {:db/id 1, :product/code "42", :product/names [{:db/id 2, :language/iso-639-1 {:db/id 3}, :product/name "Camera"} {:db/id 4, :language/iso-639-1 {:db/id 5}, :product/name "Appareil"}], :product/type "Camcorders & Digital Cameras", :sku/code "1"}
and
(d/pull @conn '[*] 1)
;;=> {:db/id 1, :product/code "42", :product/names [{:db/id 2, :language/iso-639-1 {:db/id 3}, :product/name "Camera"} {:db/id 4, :language/iso-639-1 {:db/id 5}, :product/name "Appareil"}], :product/type "Camcorders & Digital Cameras", :sku/code "1"}
Yep it shows as ref for sure, I was kind of trying to get it as value
ah that's cause it's set as a ref in the schema
:language/iso-639-1 {:db/valueType :db.type/ref
:db/isComponent true}
But I figured that it cannot really work that way so now I have probably... yeah... that's why
I was trying to save value duplication in the DB but maybe there is no need for that
value duplication?
Yes well all the names now have the same "en" and "fr"
like multiple instances of the same thing (but slightly different?)
Yep they are exactly the same indeed
Just belonging to multiple :product/name
gotcha. Yeah composite tuples would be helpful here for sure to add another dimension of uniqueness
if they don't actually have to be updated, you can kind of get away with using vectors or hash values
(lol I give up Slack is horrible 😆)
{:thing/id (hash ["blah" (random-uuid)])
:thing/name "blah"}
Oh I see
{:thing/id ["blah" (random-uuid)]
:thing/name "blah"}
could also workin other words, you can use vectors aka tuples for uniqueness now -- the only thing is datascript won't update them for you until the composite tuple work is finished
so if you know they're fixed values you can still use it
Yep I wonder though what a query by language would look like then ....but I can fiddle 😉
same as before
you just kind of ignore the tuple anyway and query by attributes
tuple is just for uniqueness
(d/q '[:find (pull ?e [*]) :where [?e :thing/name "blah"] [?e :thing/otherattr "foo"]] @conn)
Ok gotcha
Right that works
Huzzah! Glad we found a work around cause this is a complex PR 😅 can't say how long it will take
Ahaah
Appreciate your input, btw.
Yes and in any case I can live with duplicate attributes..so no worries and thanks for your help!
I am in POC mode but it is useful to see if things can be optimized at some point in the future
Thanks for your work on the PR btw, I will have something to show when the question will be asked 😉
We'll get there!
Hello, Is someone aware of basic breaking changes between 17.1 and above versions? I have basic queries that do not return results after upgrading to latest version (I tried several times during the past months with different versions and the same result). I don't see anything that would explain that behaviour in the changelog : https://github.com/tonsky/datascript/blob/master/CHANGELOG.md Thanks
Interesting. Thanks. I'll look in that direction.
I think I had a problem upgrading because older versions allowed {:db/id 0} entities, but the newer version threw an error querying against a db with {:db/id 0} in it