seancorfield / next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/
Eclipse Public License 1.0
772 stars 91 forks source link

`next.jdbc/execute` overrides `:return-keys false` opts for prepared statements #287

Closed dwwoelfel closed 4 hours ago

dwwoelfel commented 5 hours ago

Describe the bug When you call next.jdbc/execute on a prepared statement, it inserts {:return-keys true} into the opts and won't return {:next.jdbc/update-count n}.

To Reproduce

(next.jdbc/execute conn ["update users set name = 'Bob'"] {:return-keys false})
=> [{:next.jdbc/update-count 0}]
(next.jdbc/execute (next.jdbc/prepare ["update users set name = 'Bob'"]) nil {:return-keys false})
=> []

Expected behavior I expected the behavior of next.jdbc/execute to be similar whether it was called on a statement or a connection.

project.clj/deps.edn https://github.com/instantdb/instant/blob/main/server/deps.edn

Environment (please complete the following information):

Additional context The :return-keys true override was added in this commit https://github.com/seancorfield/next-jdbc/commit/a56c18d53165eed9af709ddc68998dbd49e38f71#diff-22c6ec8f301ff0e5dfed0e813e483951f0fc4ab97e0b1ed20319532984f76c23R754

If you're curious, this is what I implemented to patch over the behavior: https://github.com/instantdb/instant/pull/490/commits/3cb1bada9d6d1c83d5af2c9f6f671394b53b03b3

seancorfield commented 5 hours ago

Good catch! I sort of vaguely remember why that was added, but you are correct that it should not override :return-keys false!

seancorfield commented 4 hours ago

Oops! Accidentally closed it, sorry!

So, I looked in the codebase and there are some places where it specifically does (merge {:return-keys true} opts) in order to allow user-supplied options to override that.

seancorfield commented 4 hours ago

There will be a new 1.3.999-SNAPSHOT on Clojars in a few minutes you can try, or via git deps. LMK if that works and whether you need a new release cut "soon" or can wait for the next cycle.