Fork me on GitHub
#datascript
<
2020-02-10
>
unbalanced02:02:29

@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"}

unbalanced02:02:15

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"}

unbalanced02:02:41

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"}

richiardiandrea02:02:58

Yep it shows as ref for sure, I was kind of trying to get it as value

unbalanced02:02:23

ah that's cause it's set as a ref in the schema

unbalanced02:02:44

:language/iso-639-1 {:db/valueType   :db.type/ref
                                            :db/isComponent true}

richiardiandrea02:02:50

But I figured that it cannot really work that way so now I have probably... yeah... that's why

richiardiandrea02:02:11

I was trying to save value duplication in the DB but maybe there is no need for that

unbalanced02:02:24

value duplication?

richiardiandrea02:02:47

Yes well all the names now have the same "en" and "fr"

unbalanced02:02:48

like multiple instances of the same thing (but slightly different?)

richiardiandrea03:02:00

Yep they are exactly the same indeed

richiardiandrea03:02:15

Just belonging to multiple :product/name

unbalanced03:02:28

gotcha. Yeah composite tuples would be helpful here for sure to add another dimension of uniqueness

unbalanced03:02:01

if they don't actually have to be updated, you can kind of get away with using vectors or hash values

richiardiandrea03:02:17

(lol I give up Slack is horrible 😆)

😂 4
unbalanced03:02:05

{:thing/id   (hash ["blah" (random-uuid)])
 :thing/name "blah"}

unbalanced03:02:13

{:thing/id   ["blah" (random-uuid)]
 :thing/name "blah"}
could also work

unbalanced03:02:02

in 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

unbalanced03:02:29

so if you know they're fixed values you can still use it

richiardiandrea03:02:47

Yep I wonder though what a query by language would look like then ....but I can fiddle 😉

unbalanced03:02:09

same as before

unbalanced03:02:25

you just kind of ignore the tuple anyway and query by attributes

unbalanced03:02:30

tuple is just for uniqueness

unbalanced03:02:06

(d/q '[:find (pull ?e [*]) :where [?e :thing/name "blah"] [?e :thing/otherattr "foo"]] @conn)

richiardiandrea03:02:21

Right that works

unbalanced03:02:19

Huzzah! Glad we found a work around cause this is a complex PR 😅 can't say how long it will take

unbalanced03:02:52

Appreciate your input, btw.

richiardiandrea03:02:56

Yes and in any case I can live with duplicate attributes..so no worries and thanks for your help!

👍 4
richiardiandrea03:02:34

I am in POC mode but it is useful to see if things can be optimized at some point in the future

richiardiandrea03:02:15

Thanks for your work on the PR btw, I will have something to show when the question will be asked 😉

😅 4
unbalanced03:02:35

We'll get there!

🙏 4
lambdam17:02:32

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

jbrown21:02:26

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

lambdam12:02:09

Interesting. Thanks. I'll look in that direction.