Skip to content

Commit

Permalink
Fixed find-datom on empty DB (closes #477)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jul 22, 2024
1 parent 4eabbb8 commit 13a5c31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# WIP

- Fixed `find-datom` on empty DB #477 thx @RCmerci

# 1.7.2 - Jul 4, 2024

- Regression: transacting many ref value as a set of inline maps #476
Expand Down
2 changes: 1 addition & 1 deletion src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@
cmp #?(:clj (.comparator ^clojure.lang.Sorted set) :cljs (.-comparator set))
from (components->pattern db index c0 c1 c2 c3 e0 tx0)
to (components->pattern db index c0 c1 c2 c3 emax txmax)
datom (when-let [set* (seq set)] (first (set/seek set* from)))]
datom (some-> set seq (set/seek from) first)]
(when (and (some? datom) (<= 0 (cmp to datom)))
datom)))

Expand Down
6 changes: 5 additions & 1 deletion test/datascript/test/index.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@
(is (= [2 :name "Ivan"] (dvec (d/find-datom db :eavt 2 :name))))

(is (= nil (dvec (d/find-datom db :eavt 1 :name "Ivan"))))
(is (= nil (dvec (d/find-datom db :eavt 4))))))
(is (= nil (dvec (d/find-datom db :eavt 4))))

;; issue-477
(is (= nil (d/find-datom (d/empty-db) :eavt)))
(is (= nil (d/find-datom (d/empty-db {:age {:db/index true}}) :eavt)))))

(deftest test-seek-datoms
(let [dvec #(vector (:e %) (:a %) (:v %))
Expand Down

0 comments on commit 13a5c31

Please sign in to comment.