Fork me on GitHub
#datomic
<
2022-08-31
>
Drew Verlee17:08:00

Is there a function which will turn the tx-data map and nested map forms into the list forms? e.g

;; have
  [{:db/id 316659348816869
    :internal-team/id #uuid "5caf6e45-f54d-4c0e-9658-33f63c069569"}]

;; want 
  [[:db/add 316659348816869 :internal-team/id #uuid "5caf6e45-f54d-4c0e-9658-33f63c069569"]]
I want this so it's easier to change the db/id's if there is another simple way to do that i would be keen to hear it 🙂

Drew Verlee17:08:00

the result of (:tx-data (d/with)) will do this but i can't use that bc it throws.

ghadi17:08:40

What do you mean by “change the db/id’s”?

Drew Verlee18:08:22

The ids are too long for datascript, so I'll need to replace them with shorter ones.

Drew Verlee21:08:09

At the moment i'm changing directions and just looking to handle both the map and list form of that transaction can take. here is the map form handling code:

(defn server-tx->client-tx!
  ([server-tx]
   (server-tx->client-tx! server-tx (atom {:client-eid-idx         0
                                           :client-eid             0
                                           :server-eid->client-eid {}})))
  ([server-tx client-indexing-state]
   (letfn  [(server-eid->client-eid!
              [server-eid]
              (:client-eid
               (swap! client-indexing-state
                      (fn [{:keys [client-eid server-eid->client-eid]}]
                        (let [id (server-eid->client-eid server-eid (dec client-eid))]
                          {:client-eid-idx         client-eid
                           :client-eid             id
                           :server-eid->client-eid (assoc server-eid->client-eid server-eid id)})))))]
     (->> server-tx
          (postwalk
            #(if (and (map? %) (:db/id %))
               (update % :db/id server-eid->client-eid!)
               %))))))

(tests

  "base case"
  (server-tx->client-tx! []) := []

  "turns ids into negative numbers which datascript sees as temp"
  (server-tx->client-tx! [{:db/id 1}]) := [{:db/id -1}]

  "correctly syncs across reused ids in a transaction"
  (server-tx->client-tx! [{:db/id 1} {:db/id 1}]) := [{:db/id -1} {:db/id -1}]
  (server-tx->client-tx! [{:db/id 1} {:db/id 2}]) := [{:db/id -1} {:db/id -2}]

  "it works on nested hashmaps"
  (server-tx->client-tx! [{:a [{:db/id 1}]}]) := [{:a [{:db/id -1}]}]
  (server-tx->client-tx! [{:a [{:db/id 1}] :b [{:db/id 1}]}]) := [{:a [{:db/id -1}] :b [{:db/id -1}]}]

  "note its not just turning the given id negative its decrementing from 0"
  (server-tx->client-tx! [{:db/id 100}]) := [{:db/id -1}]

  nil)

Drew Verlee21:08:41

ill probably have to move the atom out of that function and into our re-frame db so we can reference it when doing future tx... or maybe it could return it along with the transactions. ugh.

hadils20:08:52

Hi! I am trying to remove all dependencies to Datomic Cloud in my repository. I have removed all traces of the libraries in my deps.edn however, when I try to remove:

:mvn/repos {"datomic-cloud" {:url ""}}
I get the following error message:
The following errors were found during project resolve: /Users/hadilsabbagh/yardwerkz/deps.edn: Could not find artifact com.datomic:ion:jar:0.9.28 in central ()
I cannot find com.datomic/ion 0.9.28 referred to anywhere in my deps.edn or in the repository. Any suggestions would be greatly appreciated!

hanDerPeder21:08:48

I'd check if it's listed in -Stree. clj reads multiple deps.edn files

hanDerPeder21:08:34

My first thought was it probably has something to do with the cache, but reading https://clojure.org/reference/deps_and_cli i think it would be invalidated when you changed deps.edn.

hanDerPeder21:08:05

Also, probably more appropriate to ask this in #tools-deps.

hadils21:08:33

Thank you! Found it in clj -Stree

Daniel Jomphe21:08:09

Our Datomic Cloud Ion system needs to track events to send (typical) user-level notifications. Notifications have different churn characteristics than most of the DB model datoms. We don’t expect to need to query them more than one year in the past. We fear that our main DB might grow too fast. We thought of creating a separate DB per year of notifications (e.g. notif-2021, notif-2022) but since https://forum.datomic.com/t/joining-across-databases-in-datomic-cloud/1632, this wouldn’t be practical wouldn't it? What are good fit or bad fit solution examples with Datomic Cloud Ions?