Skip to content

Commit 8c7168b

Browse files
committed
Merge remote-tracking branch 'tonsky/master'
2 parents 18a9b14 + cec8603 commit 8c7168b

File tree

10 files changed

+109
-61
lines changed

10 files changed

+109
-61
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.7.3 - Jul 22, 2024
2+
3+
- Fixed `find-datom` on empty DB #477 thx @RCmerci
4+
5+
# 1.7.2 - Jul 4, 2024
6+
7+
- Regression: transacting many ref value as a set of inline maps #476
8+
19
# 1.7.1 - Jun 20, 2024
210

311
- Regression: :db.fn/call returning entity without :db/id #474 #475 via @DerGuteMoritz

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ The intention with DataScript is to be a basic building block in client-side app
1919

2020
```clj
2121
;; lein
22-
[datascript "1.7.1"]
22+
[datascript "1.7.3"]
2323
```
2424
```clj
2525
;; deps.edn
26-
datascript/datascript {:mvn/version "1.7.1"}
26+
datascript/datascript {:mvn/version "1.7.3"}
2727
```
2828

2929
Important! If you are using shadow-cljs, add
@@ -183,7 +183,7 @@ For more examples, see [our acceptance test suite](test/datascript/test/).
183183
DataScript can be used from any JS engine without additional dependencies:
184184

185185
```html
186-
<script src="https://github.com/tonsky/datascript/releases/download/1.7.1/datascript-1.7.1.min.js"></script>
186+
<script src="https://github.com/tonsky/datascript/releases/download/1.7.3/datascript-1.7.3.min.js"></script>
187187
```
188188

189189
or as a CommonJS module ([npm page](https://www.npmjs.org/package/datascript)):

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(def version "1.7.1")
1+
(def version "1.7.3")
22

33
(defproject datascript (str version (System/getenv "DATASCRIPT_CLASSIFIER"))
44
:description "An implementation of Datomic in-memory database and Datalog query engine in ClojureScript"

release-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datascript",
3-
"version": "1.7.1",
3+
"version": "1.7.3",
44
"description": "Immutable in-memory triplestore with Datalog queries",
55
"homepage": "https://github.com/tonsky/datascript",
66
"author": "Nikita Prokopov (https://github.com/tonsky)",

release-js/wrapper.prefix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Datascript v1.7.1
2+
* Datascript v1.7.3
33
*
44
* Copyright 2014-2021 Nikita Prokopov
55
*

script/release.clj

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737

3838
(defn update-version []
3939
(println "\n\n[ Updating version number ]\n")
40-
(let [old-v (current-version)]
41-
(update-file "CHANGELOG.md" #(str/replace % "# WIP" (str "# " new-v)))
40+
(let [old-v (current-version)
41+
today (.format
42+
(java.time.format.DateTimeFormatter/ofPattern "MMM d, yyyy")
43+
(java.time.LocalDate/now))]
44+
(update-file "CHANGELOG.md" #(str/replace % "# WIP" (str "# " new-v " - " today)))
4245
(update-file "project.clj" #(str/replace % old-v new-v))
4346
(update-file "README.md" #(str/replace % old-v new-v))
4447
(update-file "release-js/package.json" #(str/replace %
@@ -55,11 +58,11 @@
5558
(defn make-commit []
5659
(println "\n\n[ Making a commit ]\n")
5760
(sh "git" "add"
58-
"CHANGELOG.md"
59-
"project.clj"
60-
"README.md"
61-
"release-js/package.json"
62-
"release-js/wrapper.prefix")
61+
"CHANGELOG.md"
62+
"project.clj"
63+
"README.md"
64+
"release-js/package.json"
65+
"release-js/wrapper.prefix")
6366

6467
(sh "git" "commit" "-m" commit-message)
6568
(sh "git" "tag" new-v)
@@ -71,9 +74,9 @@
7174

7275
(defn- str->json [s]
7376
(-> s
74-
(str/replace "\\" "\\\\")
75-
(str/replace "\"" "\\\"")
76-
(str/replace "\n" "\\n")))
77+
(str/replace "\\" "\\\\")
78+
(str/replace "\"" "\\\"")
79+
(str/replace "\n" "\\n")))
7780

7881
(defn- map->json [m]
7982
(str "{ "
@@ -86,27 +89,31 @@
8689

8790
(defn github-release []
8891
(sh "cp" "release-js/datascript.js" (str "release-js/datascript-" new-v ".min.js"))
89-
(let [changelog (->> (slurp "CHANGELOG.md")
90-
str/split-lines
91-
(drop-while #(not= (str "# " new-v) %))
92-
next
93-
(take-while #(not (re-matches #"# .+" %)))
94-
(remove str/blank?)
95-
(str/join "\n"))
96-
request { "tag_name" new-v
97-
"name" new-v
92+
(let [re (as-> new-v %
93+
(str/replace % "." "\\.")
94+
(str "# " % " .*")
95+
(re-pattern %))
96+
changelog (->> (slurp "CHANGELOG.md")
97+
str/split-lines
98+
(drop-while #(not (re-matches re %)))
99+
next
100+
(take-while #(not (re-matches #"# .+" %)))
101+
(remove str/blank?)
102+
(str/join "\n"))
103+
request {"tag_name" new-v
104+
"name" new-v
98105
"target_commitish" "master"
99-
"body" changelog}
100-
response (sh "curl" "-u" GITHUB_BASIC
101-
"-X" "POST"
102-
"--data" (map->json request)
103-
"https://api.github.com/repos/tonsky/datascript/releases")
104-
[_ id] (re-find #"\"id\": (\d+)" response)]
106+
"body" changelog}
107+
response (sh "curl" "-u" GITHUB_BASIC
108+
"-X" "POST"
109+
"--data" (map->json request)
110+
"https://api.github.com/repos/tonsky/datascript/releases")
111+
[_ id] (re-find #"\"id\": (\d+)" response)]
105112
(sh "curl" "-u" GITHUB_BASIC
106-
"-X" "POST"
107-
"-H" "Content-Type: application/javascript"
108-
"--data-binary" (str "@release-js/datascript-" new-v ".min.js")
109-
(str "https://uploads.github.com/repos/tonsky/datascript/releases/" id "/assets?name=datascript-" new-v ".min.js"))))
113+
"-X" "POST"
114+
"-H" "Content-Type: application/javascript"
115+
"--data-binary" (str "@release-js/datascript-" new-v ".min.js")
116+
(str "https://uploads.github.com/repos/tonsky/datascript/releases/" id "/assets?name=datascript-" new-v ".min.js"))))
110117

111118
(defn -main []
112119
(sh "lein" "clean")

src/datascript/db.cljc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@
11531153
cmp #?(:clj (.comparator ^clojure.lang.Sorted set) :cljs (.-comparator set))
11541154
from (components->pattern db index c0 c1 c2 c3 e0 tx0)
11551155
to (components->pattern db index c0 c1 c2 c3 emax txmax)
1156-
datom (first (set/seek (seq set) from))]
1156+
datom (some-> set seq (set/seek from) first)]
11571157
(when (and (some? datom) (<= 0 (cmp to datom)))
11581158
datom)))
11591159

@@ -1167,6 +1167,13 @@
11671167
(defn+ ^boolean multival? [db attr]
11681168
(is-attr? db attr :db.cardinality/many))
11691169

1170+
(defn+ ^boolean multi-value? [db attr value]
1171+
(and
1172+
(is-attr? db attr :db.cardinality/many)
1173+
(or
1174+
(arrays/array? value)
1175+
(and (coll? value) (not (map? value))))))
1176+
11701177
(defn+ ^boolean ref? [db attr]
11711178
(is-attr? db attr :db.type/ref))
11721179

@@ -1307,8 +1314,7 @@
13071314
(cond
13081315
(not (or (keyword? a) (string? a)))
13091316
(assoc entity a v)
1310-
1311-
(and (ref? db a) (multival? db a) (sequential? v))
1317+
(and (ref? db a) (multi-value? db a v))
13121318
(assoc entity a (assoc-auto-tempids db v))
13131319

13141320
(ref? db a)
@@ -1332,7 +1338,7 @@
13321338
:let [[op e a v] entity]
13331339
(= :db/add op)
13341340
(ref? db a))
1335-
(if (and (multival? db a) (sequential? v))
1341+
(if (multi-value? db a v)
13361342
[op e a (assoc-auto-tempids db v)]
13371343
[op e a (first (assoc-auto-tempids db [v]))])
13381344

@@ -1552,11 +1558,7 @@
15521558
(not (contains? idents a))
15531559
[(assoc entity' a v) upserts]
15541560

1555-
(and
1556-
(multival? db a)
1557-
(or
1558-
(arrays/array? v)
1559-
(and (coll? v) (not (map? v)))))
1561+
(multi-value? db a v)
15601562
(let [[insert upsert] (split a v)]
15611563
[(cond-> entity'
15621564
(not (empty? insert)) (assoc a insert))

test/datascript/test/explode.cljc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@
3636
(deftest test-explode-ref
3737
(let [db0 (d/empty-db {:children {:db/valueType :db.type/ref
3838
:db/cardinality :db.cardinality/many}})]
39-
(let [db (d/db-with db0 [{:db/id -1, :name "Ivan", :children [-2 -3]}
40-
{:db/id -2, :name "Petr"}
41-
{:db/id -3, :name "Evgeny"}])]
42-
(is (= (d/q '[:find ?n
43-
:where [_ :children ?e]
44-
[?e :name ?n]] db)
45-
#{["Petr"] ["Evgeny"]})))
39+
(doseq [children [[-2 -3]
40+
#{-2 -3}
41+
(list -2 -3)]]
42+
(testing (str "ref + many + " children)
43+
(let [db (d/db-with db0 [{:db/id -1, :name "Ivan", :children children}
44+
{:db/id -2, :name "Petr"}
45+
{:db/id -3, :name "Evgeny"}])]
46+
(is (= #{["Petr"] ["Evgeny"]}
47+
(d/q '[:find ?n
48+
:where
49+
[_ :children ?e]
50+
[?e :name ?n]] db))))))
4651

4752
(let [db (d/db-with db0 [{:db/id -1, :name "Ivan"}
4853
{:db/id -2, :name "Petr", :_children -1}
4954
{:db/id -3, :name "Evgeny", :_children -1}])]
50-
(is (= (d/q '[:find ?n
51-
:where [_ :children ?e]
52-
[?e :name ?n]] db)
53-
#{["Petr"] ["Evgeny"]})))
55+
(is (= #{["Petr"] ["Evgeny"]}
56+
(d/q '[:find ?n
57+
:where
58+
[_ :children ?e]
59+
[?e :name ?n]] db))))
5460

5561
(is (thrown-msg? "Bad attribute :_parent: reverse attribute name requires {:db/valueType :db.type/ref} in schema"
5662
(d/db-with db0 [{:name "Sergey" :_parent 1}])))))
@@ -78,9 +84,9 @@
7884
(let [schema {:profile {:db/valueType :db.type/ref
7985
:db/cardinality :db.cardinality/many}}
8086
db (d/empty-db schema)]
81-
(are [tx res] (= (d/q '[:find ?e ?a ?v
82-
:where [?e ?a ?v]]
83-
(d/db-with db tx)) res)
87+
(are [tx res] (= res (d/q '[:find ?e ?a ?v
88+
:where [?e ?a ?v]]
89+
(d/db-with db tx)))
8490
[{:db/id 5 :name "Ivan" :profile {:db/id 7 :email "@2"}}]
8591
#{[5 :name "Ivan"] [5 :profile 7] [7 :email "@2"]}
8692

@@ -92,6 +98,13 @@
9298

9399
[{:name "Ivan" :profile [{:email "@2"} {:email "@3"}]}]
94100
#{[1 :name "Ivan"] [1 :profile 2] [2 :email "@2"] [1 :profile 3] [3 :email "@3"]}
101+
102+
;; issue-467
103+
[{:name "Ivan" :profile #{{:email "@2"} {:email "@3"}}}]
104+
#{[1 :name "Ivan"] [1 :profile 2] [2 :email "@3"] [1 :profile 3] [3 :email "@2"]}
105+
106+
[{:name "Ivan" :profile (list {:email "@2"} {:email "@3"})}]
107+
#{[1 :name "Ivan"] [1 :profile 2] [2 :email "@2"] [1 :profile 3] [3 :email "@3"]}
95108

96109
[{:email "@2" :_profile {:name "Ivan"}}]
97110
#{[1 :email "@2"] [2 :name "Ivan"] [2 :profile 1]}

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 %))

test/datascript/test/transact.cljc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
(is (= (d/q '[:find ?v
1919
:where [1 :aka ?v]] db)
2020
#{["Devil"] ["Tupen"]}))
21-
21+
2222
(testing "Retract"
2323
(let [db (-> db
2424
(d/db-with [[:db/retract 1 :name "Petr"]])
@@ -219,7 +219,21 @@
219219
(let [{:keys [db-after]} (d/transact! conn [[:db.fn/call inc-age "Petr"]])
220220
e (d/entity db-after 1)]
221221
(is (= (:age e) 32))
222-
(is (:had-birthday e)))))
222+
(is (:had-birthday e)))
223+
224+
(let [{:keys [db-after]} (d/transact! conn
225+
[[:db.fn/call (fn [db]
226+
[{:name "Oleg"}])]])
227+
e (d/entity db-after 2)]
228+
(is (= "Oleg" (:name e))))
229+
230+
(let [{:keys [db-after
231+
tempids]} (d/transact! conn
232+
[[:db.fn/call (fn [db]
233+
[{:db/id -1
234+
:name "Vera"}])]])
235+
e (d/entity db-after (tempids -1))]
236+
(is (= "Vera" (:name e))))))
223237

224238
(deftest test-db-ident-fn
225239
(let [conn (d/create-conn {:name {:db/unique :db.unique/identity}})

0 commit comments

Comments
 (0)