Skip to content

Commit

Permalink
Rolling back last change, uniqueness was breaking upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsbarbosa committed Mar 19, 2023
1 parent 1554608 commit 02a864f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.clojars.majorcluster/datomic-helper "2.1.0"
(defproject org.clojars.majorcluster/datomic-helper "2.1.1"
:description "A Clojure Library with tools to help using datomic"
:url "https://github.com/majorcluster/datomic-helper"
:license {:name "The MIT License"
Expand Down
7 changes: 2 additions & 5 deletions src/datomic_helper/entity.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@
(insert! database-context conn to-be-saved)))

(defn upsert!
([dcontext conn [id-ks id] to-be-saved unique-check]
([dcontext conn [id-ks id] to-be-saved]
(let [found-entity (find-by-id dcontext conn id-ks id)]
(cond found-entity
(when (unique-check)
(update! dcontext conn id-ks id found-entity to-be-saved))
(update! dcontext conn id-ks id found-entity to-be-saved)
:else (insert! dcontext conn to-be-saved))))
([dcontext conn [id-ks id] to-be-saved]
(upsert! dcontext conn [id-ks id] to-be-saved (fn [] true)))
([conn [id-ks id] to-be-saved]
(upsert! database-context conn [id-ks id] to-be-saved)))

Expand Down
5 changes: 1 addition & 4 deletions test/datomic_helper/entity_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@
(testing "when entity is not found, db/cas cols are returned"
(let [db-context (test-database-context nil)]
(is (= [{:age 49}]
(d-h.entity/upsert! db-context {} [:name "Rosa"] {:age 49})))))
(testing "when entity is not unique"
(let [db-context (test-database-context {:age 35, :name "Rosa"})]
(is (nil? (d-h.entity/upsert! db-context {} [:name "Rosa"] {:age 49} (fn [] false)))))))
(d-h.entity/upsert! db-context {} [:name "Rosa"] {:age 49}))))))

(deftest upsert-foreign-test
(testing "when entity is found, db/add is returned"
Expand Down

0 comments on commit 02a864f

Please sign in to comment.