Fork me on GitHub
#datascript
<
2016-11-28
>
leov20:11:46

ok why do they say you cannot write true row-style component upsert functions in datomic due to some limitation?

leov20:11:55

for simplest use-case I made this function

leov20:11:59

(defn upsert-rows-component [db component-key new-component]
  "Given {:app.id 2, ...} and [{:app.config.key .., :app.config.value .., :app.config.app-id ..}, ..]
   in database, removes all old entities under given :app.config.app-id and asserts new rows"
  {:pre? (= 1 (count (distinct (map component-key new-component))))}
  (concat
    (->> (first new-component)
         component-key
         (d/q '[:find [?e ...]
                :in $ ?component-key ?v
                :where [?e ?component-key ?v]] db component-key)
         (map (fn [e] [:db.fn/retractEntity e])))
    new-component))

leov20:11:30

is it due to some temp-id generation.. 😕

leov20:11:46

also persisting datascript seems to be dead simple, however next question is due - are there any transit-specific data compressors, smart enough as to tokenize map keys?.. (went googling)