Skip to content
Permalink
e1108c472a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
38 lines (32 sloc) 1.79 KB
(ns de.mpg.shh.util-datomic-peer.schema
(:require [datomic.api :as dt])
(:import [java.util.regex Pattern]))
(defn entity-attr->datascript-kv
[accumulator item]
(merge-with merge accumulator {(first item) {(second item) (last item)}}))
(defn entity-schema->value-type
[entity-schema]
(let [filtered-entity-schema (filter #(and (= (second %) :db/valueType)
(not (contains? #{:db.type/string :db.type/ref} (last %)))) entity-schema)]
(into {} (map (fn [[k v]] [k (:db/valueType v)]) (reduce entity-attr->datascript-kv {} filtered-entity-schema)))))
(defn entity-schema->datascript
[entity-schema]
(let [filtered-entity-schema (remove #(or (contains? #{:db/doc :db/ident} (second %))
(and (= (second %) :db/valueType)
(not= (last %) :db.type/ref))
(= (last %) :db.cardinality/one)) entity-schema)]
(reduce entity-attr->datascript-kv {} filtered-entity-schema)))
(defn domain-schema
[db dom-pat]
(let [_ (when-not (instance? Pattern dom-pat) (throw (ex-info "domain-schema requires an re-pattern" {:cause (str "You supplied '" (type dom-pat) "'")})))
domain-schema (dt/q '[:find ?attr ?iattr ?i
:in $ ?dom-pat
:where [(datomic.api/ident $ ?x) ?i]
[(datomic.api/ident $ ?xattr) ?iattr]
[?e ?xattr ?x]
[?e :db/ident ?attr]
[(datomic.Util/namespace ?attr) ?ns]
[(re-find ?dom-pat ?ns)]]
db
dom-pat)]
domain-schema))