Skip to content

Commit dbbf35d

Browse files
committed
Regression: transacting many ref value as a set of inline maps (closes #476)
1 parent 0fd30aa commit dbbf35d

File tree

5 files changed

+100
-58
lines changed

5 files changed

+100
-58
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+
- Regression: transacting many ref value as a set of inline maps #476
4+
15
# 1.7.1 - Jun 20, 2024
26

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

script/release.clj

Lines changed: 43 additions & 35 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. "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,36 +89,41 @@
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")
113120
(update-version)
114-
(run-tests)
115-
(make-commit)
116-
(publish-npm)
117-
(github-release)
118-
(sh "lein" "deploy" "clojars")
119-
(System/exit 0))
121+
; (run-tests)
122+
; (make-commit)
123+
; (publish-npm)
124+
; (github-release)
125+
; (sh "lein" "deploy" "clojars")
126+
; (System/exit 0)
127+
)
120128

121129
(-main)

src/datascript/db.cljc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,13 @@
11631163
(defn+ ^boolean multival? [db attr]
11641164
(is-attr? db attr :db.cardinality/many))
11651165

1166+
(defn+ ^boolean multi-value? [db attr value]
1167+
(and
1168+
(is-attr? db attr :db.cardinality/many)
1169+
(or
1170+
(arrays/array? value)
1171+
(and (coll? value) (not (map? value))))))
1172+
11661173
(defn+ ^boolean ref? [db attr]
11671174
(is-attr? db attr :db.type/ref))
11681175

@@ -1304,7 +1311,7 @@
13041311
(not (or (keyword? a) (string? a)))
13051312
(assoc entity a v)
13061313

1307-
(and (ref? db a) (multival? db a) (sequential? v))
1314+
(and (ref? db a) (multi-value? db a v))
13081315
(assoc entity a (assoc-auto-tempids db v))
13091316

13101317
(ref? db a)
@@ -1328,7 +1335,7 @@
13281335
:let [[op e a v] entity]
13291336
(= :db/add op)
13301337
(ref? db a))
1331-
(if (and (multival? db a) (sequential? v))
1338+
(if (multi-value? db a v)
13321339
[op e a (assoc-auto-tempids db v)]
13331340
[op e a (first (assoc-auto-tempids db [v]))])
13341341

@@ -1490,11 +1497,7 @@
14901497
(not (contains? idents a))
14911498
[(assoc entity' a v) upserts]
14921499

1493-
(and
1494-
(multival? db a)
1495-
(or
1496-
(arrays/array? v)
1497-
(and (coll? v) (not (map? v)))))
1500+
(multi-value? db a v)
14981501
(let [[insert upsert] (split a v)]
14991502
[(cond-> entity'
15001503
(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/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)