Last active
January 6, 2016 16:46
-
-
Save dball/78cdd440863c6b62fec0 to your computer and use it in GitHub Desktop.
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
TypeResolver | |
(resolve-types [_])) | |
(extend-protocol TypeResolver | |
clojure.lang.Keyword | |
(resolve-types [type] | |
(when-let [spec (spark.spec-tacular/get-spec type)] | |
(resolve-types spec))) | |
clojure.lang.Var | |
(resolve-types [var] | |
(let [meta (meta var) | |
type (or (:spec-tacular/spec meta) | |
(:spec-tacular/union meta))] | |
(when type | |
(resolve-types type)))) | |
spark.spec_tacular.spec.Spec | |
(resolve-types [spec] | |
#{(:name spec)}) | |
spark.spec_tacular.spec.UnionSpec | |
(resolve-types [spec] | |
(reduce into #{} (map resolve-types (:elements spec))))) | |
(defn load-datoms | |
[db type] | |
(let [types (resolve-types type)] | |
(when (seq types) | |
(->> (d/q '[:find ?datom | |
:in $ [?types ...] ?attr | |
:where [?datom ?attr ?types]] | |
db types spark.spec-tacular.datomic/spark-type-attr) | |
(reduce concat) | |
(mapv (comp d/touch (partial d/entity db))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment