Skip to content

Instantly share code, notes, and snippets.

Last active May 6, 2016
What would you like to do?
One solution to integrating Schema and Datomic
(in-ns test
[schema.macros :as macros]
[schema.utils :as sutils]))
;; Wrapper type needed because Entity values do not implement
;; IPersistentMap interface
(defrecord EntitySchema
(walker [this]
(let [map-checker (s/subschema-walker schema)]
(fn [e]
(or (when-not (sd/entity? e)
(macros/validation-error this e
(list 'instance? datomic.Entity (sutils/value-name e))))
(map-checker (into {} (seq e)))))))
(explain [this]
(list 'entity 'datomic.Entity (explain (:schema this)))))
(defn entity-schema?
(= (type schema) EntitySchema))
(defn model-base-schema
"Generates a schema for Datomic entity with model tag 'type'"
{:pre [(keyword? type)]}
(EntitySchema. {:model/id s/Uuid
:model/type (s/both s/Keyword (s/eq type))}))

This comment has been minimized.

Copy link

@jcf jcf commented Sep 14, 2015

As sd/entity? is not defined you can use (instance? datomic.Entity e) in its place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment