Skip to content
Browse files

add generated data (e.g. uuids)

  • Loading branch information...
clayton committed Oct 7, 2017
1 parent e1108c4 commit ee652be2cc8bfc9deaf51ffc80e37ad509746872
@@ -50,9 +50,20 @@
(conj accumulator [(first (last accumulator)) item next-sym]
[next-sym component-id-attr component-id-attr-val])))

(defn namespace-attrs
[attr-paths-lookup id-attr]
(for [[k v] attr-paths-lookup :when (and (= (namespace k) (namespace id-attr))
(not= k id-attr))] k))

(defn generate-attr-tx-data
[dt-value-type-lookup attr]
(when-let [value-type (get dt-value-type-lookup attr)]
(= value-type :db.type/uuid) [:db/add -1 attr (dt/squuid)])))

;; query for the id of the parent entity
(defn cache-row
[ds-conn attr-paths-lookup component-attr-id-attr-map row]
[ds-conn dt-value-type-lookup attr-paths-lookup component-attr-id-attr-map row]
(let [;;_ (info "attr-paths-lookup: " attr-paths-lookup)
insertion-order (sort-by namespace (filter #(contains? attr-paths-lookup %) (keys row)))
;;_ (info "insertion-order: " insertion-order)
@@ -65,7 +76,10 @@
;;_ (info "root-result: " root-result)
_ (when (nil? root-result)
(ds/transact ds-conn [[:db/add -1 (first insertion-order) (get row (first insertion-order))]]))]
(let [other-root-attrs (namespace-attrs attr-paths-lookup (first insertion-order))
generated-tx-data (vec (remove nil? (map (partial generate-attr-tx-data dt-value-type-lookup) (remove #(contains? row %) other-root-attrs))))]
(ds/transact ds-conn (concat [[:db/add -1 (first insertion-order) (get row (first insertion-order))]]
(doseq [field (rest insertion-order)]
;;(dorun (map (partial cache-field conn attr-paths-lookup component-attr-id-attr-map row) insertion-order))
(let [field-attr-paths (get attr-paths-lookup field)
@@ -95,8 +109,9 @@
[:db/add -1 component-id-attr component-id-attr-val]
[:db/add -1 field (get row field)]]))
;;_ (info "tx-data: " tx-data)
(ds/transact ds-conn tx-data))
other-attrs (namespace-attrs attr-paths-lookup component-id-attr)
generated-tx-data (vec (remove nil? (map (partial generate-attr-tx-data dt-value-type-lookup) (remove #(contains? row %) other-attrs))))]
(ds/transact ds-conn (concat tx-data generated-tx-data)))
(not= (get result field) (get row field))
(ds/transact ds-conn [[:db/add (:db/id result) field (get row field)]])))))
@@ -14,5 +14,5 @@
ds-conn (ds/conn-from-db (ds/init-db datoms schema))
attr-paths (peer-push/push->path [] [] push-pattern)
attr-paths-lookup (into {} (map #(vector (last %) (vec (butlast %))) attr-paths))
_ (dorun (map (partial peer-push/cache-row ds-conn attr-paths-lookup component-attr-id-attr-map) rows))]
_ (dorun (map (partial peer-push/cache-row ds-conn dt-value-type-lookup attr-paths-lookup component-attr-id-attr-map) rows))]
(peer-push/datascript->datomic-tx-data ds-conn dt-partition dt-value-type-lookup))))

0 comments on commit ee652be

Please sign in to comment.
You can’t perform that action at this time.