-
Notifications
You must be signed in to change notification settings - Fork 5
/
export.cljc
28 lines (24 loc) · 1.12 KB
/
export.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns datoms-differ.export
(:require [datoms-differ.core :refer [get-datoms find-attrs]]
[medley.core :refer [filter-keys map-vals]]))
(defn export [schema datoms]
(str "#datascript/DB "
(pr-str {:schema (dissoc schema :datoms-differ.core/db-id-partition)
:datoms (vec datoms)})))
(defn prep-for-datascript
"Filter away any keys from the schema contents that does not start with the :db/ namespace"
[schema]
(map-vals #(filter-keys (fn [k] (= (namespace k) "db")) %) schema))
(defn export-db [db]
(export (prep-for-datascript (:schema db)) (get-datoms db)))
(defn prune-diffs [schema tx-data]
(let [{:keys [many?]} (find-attrs schema)
overwriting-additions (set (keep (fn [[op eid attr]]
(when (and (= :db/add op)
(not (many? attr)))
[eid attr]))
tx-data))]
(remove (fn [[op eid attr]]
(and (= :db/retract op)
(overwriting-additions [eid attr])))
tx-data)))