Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-adding db-do-prepared-return-keys to retain backwards compatibility
  • Loading branch information
ninanator committed Mar 6, 2016
commit 800ab7b28361f7bfd9eb3b9dc4455229e336aa7e
13 changes: 7 additions & 6 deletions src/yesql/generate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@

(defn insert-handler
[db sql params call-options]
(let [table-string-position 0
table-position 2
table-keyword (keyword ((split (sql table-string-position) #" ") table-position))]
(if (vector? params)
(apply jdbc/insert! db table-keyword params)
(jdbc/insert! db table-keyword params))))
(if (vector? params)
(let [table-string-position 0
table-position 2
table-keyword (keyword ((split (sql table-string-position) #" ") table-position))]
(apply jdbc/insert! db table-keyword params))
(let [[rewritten-sql & rewritten-params] (rewrite-query-for-jdbc sql params)]
(jdbc/db-do-prepared-return-keys db rewritten-sql rewritten-params))))

(defn query-handler
[db sql params
Expand Down
6 changes: 3 additions & 3 deletions test/yesql/acceptance_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
(expect (create-person-table!))

;; Insert -> Select.
(expect (list {:1 1M}) (insert-person<! {:name "Alice" :age 20}))
(expect (list {:1 2M}) (insert-person<! {:name "Bob" :age 25}))
(expect (list {:1 3M}) (insert-person<! {:name "Charlie" :age 35}))
(expect {:1 1M} (insert-person<! {:name "Alice" :age 20}))
(expect {:1 2M} (insert-person<! {:name "Bob" :age 25}))
(expect {:1 3M} (insert-person<! {:name "Charlie" :age 35}))
(expect (list {:1 4M} {:1 5M}) (insert-person<! [{:name "Pepper" :age 50} {:name "Tony" :age 55}]))

(expect 5 (count (find-older-than {:age 10})))
Expand Down