Skip to content

Commit

Permalink
Merge pull request #52 from metabase/fix-get-inserted-id-with-no-resu…
Browse files Browse the repository at this point in the history
…lts-returned

Fix get-inserted-id if no results are returned
  • Loading branch information
camsaul authored Jan 16, 2019
2 parents 12ed7cd + b32d7ab commit aa3d981
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/toucan/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@
(defn get-inserted-id
"Get the ID of a row inserted by `jdbc/db-do-prepared-return-keys`."
[insert-result]
(some insert-result inserted-id-keys))
(when insert-result
(some insert-result inserted-id-keys)))

(defn simple-insert-many!
"Do a simple JDBC `insert!` of multiple objects into the database.
Expand Down
5 changes: 5 additions & 0 deletions test/toucan/db_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@
(test/with-clean-db
(db/insert! User {:first-name "Grass" :last-name #sql/call [:upper "Hopper"]})))

;; get-inserted-id shouldn't fail if nothing is returned for some reason
(expect
nil
(db/get-inserted-id nil))

;; Test select-one
(expect
#toucan.test_models.user.UserInstance{:id 1, :first-name "Cam", :last-name "Saul"}
Expand Down

0 comments on commit aa3d981

Please sign in to comment.