Fork me on GitHub

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: 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 - 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.