This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-01
Channels
- # adventofcode (66)
- # announcements (12)
- # aws (8)
- # babashka (28)
- # beginners (160)
- # cider (28)
- # clara (22)
- # clj-kondo (5)
- # cljdoc (40)
- # clojure (129)
- # clojure-australia (2)
- # clojure-europe (24)
- # clojure-gamedev (19)
- # clojure-nl (5)
- # clojure-norway (15)
- # clojure-sanfrancisco (25)
- # clojure-seattle (2)
- # clojure-spec (13)
- # clojure-uk (29)
- # clojurescript (14)
- # cryogen (5)
- # cursive (7)
- # data-science (1)
- # datascript (5)
- # datomic (8)
- # deps-new (5)
- # emacs (19)
- # events (8)
- # fulcro (32)
- # graalvm (7)
- # helix (9)
- # kaocha (3)
- # lambdaisland (1)
- # london-clojurians (4)
- # malli (5)
- # meander (32)
- # off-topic (143)
- # pathom (4)
- # portal (32)
- # re-frame (7)
- # reagent (33)
- # reitit (2)
- # shadow-cljs (5)
- # spacemacs (4)
- # tools-deps (30)
- # vim (1)
Humm, I have another question that comes then. When I take a subset of information from Datomic, I can have relations between entities that cannot be represented with tree style imbricated data structures (JSON style), like in this kind of relations: https://lambdam.com/images/2020-08-er-diagram.svg Would a solution be to walk through the whole data and replace the db ids by lookup refs, like so:
:book/categories [17592186048456 17592186048457 17592186048458]
;; to
:book/categories [[:entity/id #uuid "6743167e-e1b1-4cd6-9d37-7e7b8db5dd53"] [:entity/id #uuid "052d8b26-e175-43b0-be23-d660deb5376b"] [:entity/id #uuid "42cf0a5c-f3c1-4216-8d12-365b7aede4ce"]]
I didn't try it yet but I don't know if it is a well known case that has a well known solution.Well, this works:
(def ds-schema
{:entity/id {;; :db/valueType :db.type/uuid
:db/unique :db.unique/identity}
:user/friends {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}})
(def conn* (ds/create-conn ds-schema))
(def uid1 (java.util.UUID/randomUUID))
(def uid2 (java.util.UUID/randomUUID))
(ds/transact! conn*
[{:entity/id uid1
:user/name "Foo"}
{:entity/id uid2
:user/name "Bar"
:user/friends [[:entity/id uid1]]}])
(ds/pull @conn*
'[* {:user/friends [*]}]
[:entity/id uid2])
But that means stripping always all :db/id
fields when data goes back and forth between front and back :thinking_face: ?!
If you're trying to do a 1:1 sync from Datomic to DataScript, you may want to check out https://github.com/metasoarous/datsync - and either use it directly, or at least study how it solves these problems.
Thanks @pithyless, That is an overcomplicated lib for my needs. The Datomic and the Datascript are on the same server. I didn't choose a classical webapp architecture for my current project. I'll take a look at the id translation part of the code of Datsync. I saw this project few years ago but forgot about it. Thanks again.