Created
November 21, 2019 17:17
-
-
Save DaveWM/66bced07550aaf295a3f40dbf263f171 to your computer and use it in GitHub Desktop.
Datomic - update cardinality many attr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns datomic-update-cardinality-many | |
(:require [datomic.api :as d])) | |
(defn update-attr-txs [db entity-id attr values] | |
(let [current-vals (-> (d/q '[:find [?p ...] | |
:where [?id :intention/parents ?p] | |
:in $ ?id] | |
db | |
entity-id) | |
(set)) | |
[added removed] (clojure.data/diff (set values) current-vals)] | |
(concat (->> added | |
(map #(-> [:db/add entity-id attr %]))) | |
(->> removed | |
(map #(-> [:db/retract entity-id attr %])))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment