datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
unbalanced 2020-02-10T02:51:29.020600Z

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

unbalanced 2020-02-10T02:57:15.021900Z

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

unbalanced 2020-02-10T02:57:41.022400Z

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

richiardiandrea 2020-02-10T02:57:58.023300Z

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

unbalanced 2020-02-10T02:58:23.023900Z

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

unbalanced 2020-02-10T02:58:44.024800Z

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

richiardiandrea 2020-02-10T02:58:50.025100Z

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

richiardiandrea 2020-02-10T02:59:11.025900Z

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

unbalanced 2020-02-10T02:59:24.026300Z

value duplication?

richiardiandrea 2020-02-10T02:59:47.027400Z

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

unbalanced 2020-02-10T02:59:48.027600Z

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

richiardiandrea 2020-02-10T03:00:00.028Z

Yep they are exactly the same indeed

richiardiandrea 2020-02-10T03:00:15.028800Z

Just belonging to multiple :product/name

unbalanced 2020-02-10T03:00:28.029300Z

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

unbalanced 2020-02-10T03:01:01.030700Z

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

richiardiandrea 2020-02-10T03:01:17.031500Z

(lol I give up Slack is horrible 😆)

😂 1
unbalanced 2020-02-10T03:02:05.032900Z

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

richiardiandrea 2020-02-10T03:02:16.033100Z

Oh I see

unbalanced 2020-02-10T03:03:13.034800Z

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

unbalanced 2020-02-10T03:04:02.036300Z

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

unbalanced 2020-02-10T03:04:29.036900Z

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

richiardiandrea 2020-02-10T03:04:47.037600Z

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

unbalanced 2020-02-10T03:05:09.038200Z

same as before

unbalanced 2020-02-10T03:05:25.039100Z

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

unbalanced 2020-02-10T03:05:30.039500Z

tuple is just for uniqueness

unbalanced 2020-02-10T03:06:06.041200Z

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

richiardiandrea 2020-02-10T03:06:07.041300Z

Ok gotcha

richiardiandrea 2020-02-10T03:06:21.041500Z

Right that works

unbalanced 2020-02-10T03:07:19.043100Z

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

richiardiandrea 2020-02-10T03:07:28.043400Z

Ahaah

unbalanced 2020-02-10T03:07:52.044300Z

Appreciate your input, btw.

richiardiandrea 2020-02-10T03:07:56.044600Z

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

👍 1
richiardiandrea 2020-02-10T03:08:34.045500Z

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

richiardiandrea 2020-02-10T03:09:15.046800Z

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

😅 1
unbalanced 2020-02-10T03:15:35.047200Z

We'll get there!

🙏 1
lambdam 2020-02-10T17:50:32.050100Z

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

lambdam 2020-02-11T12:43:09.050500Z

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

jbrown 2020-02-10T21:26:26.050300Z

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