Skip to content

Commit 13a5c31

Browse files
committed
Fixed find-datom on empty DB (closes #477)
1 parent 4eabbb8 commit 13a5c31

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# WIP
2+
3+
- Fixed `find-datom` on empty DB #477 thx @RCmerci
4+
15
# 1.7.2 - Jul 4, 2024
26

37
- Regression: transacting many ref value as a set of inline maps #476

src/datascript/db.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@
11491149
cmp #?(:clj (.comparator ^clojure.lang.Sorted set) :cljs (.-comparator set))
11501150
from (components->pattern db index c0 c1 c2 c3 e0 tx0)
11511151
to (components->pattern db index c0 c1 c2 c3 emax txmax)
1152-
datom (when-let [set* (seq set)] (first (set/seek set* from)))]
1152+
datom (some-> set seq (set/seek from) first)]
11531153
(when (and (some? datom) (<= 0 (cmp to datom)))
11541154
datom)))
11551155

test/datascript/test/index.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@
102102
(is (= [2 :name "Ivan"] (dvec (d/find-datom db :eavt 2 :name))))
103103

104104
(is (= nil (dvec (d/find-datom db :eavt 1 :name "Ivan"))))
105-
(is (= nil (dvec (d/find-datom db :eavt 4))))))
105+
(is (= nil (dvec (d/find-datom db :eavt 4))))
106+
107+
;; issue-477
108+
(is (= nil (d/find-datom (d/empty-db) :eavt)))
109+
(is (= nil (d/find-datom (d/empty-db {:age {:db/index true}}) :eavt)))))
106110

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

0 commit comments

Comments
 (0)