From 5d271454ac984030b2b779be8fee9be474c41475 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Tue, 2 Aug 2016 17:35:05 -0700 Subject: [PATCH] Don't replace keyword idents if the underlying field is itself :db.type/keyword. This is necessary to assert new :db/ident datoms. --- src/datomish/db.cljc | 14 +++++++------- src/datomish/schema.cljc | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/datomish/db.cljc b/src/datomish/db.cljc index 03e20d85..83e1cfbd 100644 --- a/src/datomish/db.cljc +++ b/src/datomish/db.cljc @@ -335,13 +335,13 @@ true (recur (util/conj-in report [:entities] entity) entities)))))) -(defn maybe-ident->entid [db [op & entity :as orig]] - ;; TODO: use something faster than `into` here. - (-> - (into [op] (for [field entity] - (get (idents db) field field))) ;; TODO: schema, not db. - ;; (with-meta (get (meta orig) :source {:source orig})) - )) +(defn maybe-ident->entid [db [op e a v tx :as orig]] + (let [e (get (idents db) e e) ;; TODO: use ident, entid here. + a (get (idents db) a a) + v (if (ds/kw? (schema db) a) ;; TODO: decide if this is best. We could also check for ref and numeric types. + v + (get (idents db) v v))] + [op e a v tx])) (defrecord Transaction [db tempids entities]) diff --git a/src/datomish/schema.cljc b/src/datomish/schema.cljc index 2af56c0c..0a039f2f 100644 --- a/src/datomish/schema.cljc +++ b/src/datomish/schema.cljc @@ -24,6 +24,10 @@ :cljs [^boolean ref?]) [schema attr] (is-attr? schema attr :db.type/ref)) +(defn #?@(:clj [^Boolean kw?] + :cljs [^boolean kw?]) [schema attr] + (is-attr? schema attr :db.type/keyword)) + (defn #?@(:clj [^Boolean component?] :cljs [^boolean component?]) [schema attr] (is-attr? schema attr :db/isComponent)) @@ -59,7 +63,8 @@ (= v :db.cardinality/many) [:db.cardinality/many] (= v :db.unique/identity) [:db/unique :db.unique/identity :db/index] (= v :db.unique/value) [:db/unique :db.unique/value :db/index] - (= [k v] [:db/index true]) [:db/index])) + (= [k v] [:db/index true]) [:db/index] + (= k :db/valueType) [v])) (defn- multimap [e m] (reduce