Skip to content

Commit

Permalink
fix: schema not fully support
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Mar 29, 2024
1 parent 7db748a commit aa2f963
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1285,14 +1285,16 @@
(let [err-msg (str "Schema with attribute " v-ident " does not exist")
err-map {:error :retract/schema :attribute v-ident}]
(throw (ex-info err-msg err-map)))
(update-in db [:schema] #(dissoc % v-ident)))
(let [e-ident (:v (first (-seek-datoms db :eavt e :db/ident nil nil)))]
(if (schema e-ident)
(update-in db [:schema e-ident] #(dissoc % a-ident))
(let [err-msg (str "Schema with db/ident " e-ident " does not exist")
err-map {:error :retract/schema :entity-id e :attribute a :value e}]
(throw #?(:clj (ex-info err-msg err-map)
:cljs (ex-info err-msg err-map)))))))))
(-> db
(assoc-in [:schema e] (dissoc (schema v-ident) a-ident))
(update-in [:schema] #(dissoc % v-ident))))
(if-let [schema-entry (schema e)]
(if (schema schema-entry)
(update-in db [:schema schema-entry] #(dissoc % a-ident))
(update-in db [:schema e] #(dissoc % a-ident v-ident)))
(let [err-msg (str "Schema with entity id " e " does not exist")
err-map {:error :retract/schema :entity-id e :attribute a :value e}]
(throw (ex-info err-msg err-map)))))))

(defn get-schema [db]
(or (:schema db) {}))
Expand All @@ -1305,9 +1307,14 @@
a-ident a
v-ident v]
(if (= a-ident :db/ident)
(assoc-in db [:schema v-ident a-ident] v-ident)
(let [e-ident (:v (first (-seek-datoms db :eavt e :db/ident nil nil)))]
(assoc-in db [:schema e-ident a-ident] v-ident)))))
(-> db
(assoc-in [:schema v-ident] (merge (or (schema e) {}) (hash-map a-ident v-ident)))
(assoc-in [:schema e] v-ident))
(if-let [schema-entry (schema e)]
(if (schema schema-entry)
(assoc-in db [:schema schema-entry a-ident] v-ident)
(assoc-in db [:schema e a-ident] v-ident))
(assoc-in db [:schema e] (hash-map a-ident v-ident))))))

(defn update-rschema [db]
(assoc db :rschema (rschema (merge implicit-schema (get-schema db)))))
Expand Down

0 comments on commit aa2f963

Please sign in to comment.