Fork me on GitHub
#datascript
<
2016-06-08
>
fasiha06:06:54

Just inserted ~2k DataScript EAVT tuples into RethinkDB via http://Horizon.io, looking forward to straightforward persistence and changefeeds!

Niki07:06:10

@fasiha: are you using DS and Rethink together? what’s the integration story?

Niki07:06:21

just all datoms in a single table?

fasiha11:06:34

@tonsky: exactly: something really simple. I was looking at Firebase to just (1) persist EAVT datoms, (2) coordinate dissemination of novelty to connected clients (though I had that working in Sente, wasn't hard), and (3) handle Twitter/Github/etc. auth. Trying Horizon (even tho Firebase has a ClojureScript wrapper), I've previously used RethinkDB, before EAVT. My front-end app grabs all datoms from Horizon/Rethink and dumps them in its DataScript instance. I haven't thought through how I'm going to write rollback: transacting on the client makes tx-data vectors, but there's no DataScript/Datomic on the backend to incorporate them, so hmmm. Maybe not such a good idea, replacing my Clojure/DataScript backend 😛

Niki12:06:24

what type do you use for V column?

Niki12:06:33

do you serialize cljs values to a string?

Niki12:06:20

re: writing, can’t you just insert datoms generated on a client into the same table?

fasiha14:06:12

@tonsky: hmm, I see what you mean. Yes, I use clj->js:

; so our namespaced keywords attributes stored with namespace
(extend-type Keyword
  IEncodeJS
  (-clj->js
    [kw]
    (subs (str kw) 1)))

(defn datom-to-obj [v]
  (apply hash-map (interleave ["e" "a" "v" "t"] (take 4 v))))

(let [datoms (clj->js (map datom-to-obj (map #(take 4 %) full-datascript-db)))] ; send to RethinkDB...)

fasiha14:06:34

So I'll have to extend any rich cljs types (sets, keywords, etc.) I use as values with IEncodeClojure to retrieve them properly…

fasiha14:06:15

Re: writing—I was thinking about retractions, the 5th element of tx-data vector (does 5th element that have a name?). I'll just have to partition tx-datas into additions and retraction, then translate that appropriately to Rethink/Horizon

fasiha14:06:18

I was also thinking, what happens if RethinkDB rejects a transaction? Maybe because of permissions. Then I'll have to roll back the change made to the client's DataScript db

Niki14:06:33

rejections are hard

Niki14:06:40

fifth element is called :added

fasiha15:06:41

EAVTA, I like it 😄

fasiha15:06:16

I will try to hang on to older copies of the db and update conn only in a success handler

fasiha15:06:33

If I had Datascript/Datomic on backend, I could eschew optimistic updates—clients could just send speculative tx-logs (I can get speculative transactions via with-db right?) over WebSocket and update their local dbs when the server broadcasts an accepted change. But with Horizon/Rethink, everything has to be optimistic 😂