Skip to content

Instantly share code, notes, and snippets.

@dball
Last active January 6, 2016 16:46
Show Gist options
  • Save dball/78cdd440863c6b62fec0 to your computer and use it in GitHub Desktop.
Save dball/78cdd440863c6b62fec0 to your computer and use it in GitHub Desktop.
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