Fork me on GitHub
#sql
<
2019-07-26
>
osi22:07:14

when going over some code that uses next-jdbc/execute-one! with a co-worker today, they had asked me if it would fail if used with a statement that returned more than one row. when digging into the implementation, the answer appears to be no. would this be a welcome contribution? or should I build that into my application layer instead?

shaun-mahood22:07:43

I don't think that's an error - https://github.com/seancorfield/next-jdbc/blob/master/doc/getting-started.md#execute--execute-one says it can be used to return the first row of any result set. I can certainly think of places where it would be useful.

osi22:07:31

totally fair - i’ll bake this logic into our application code.

seancorfield22:07:54

@peter.royal The intent is that you use execute-one! if you either know you'll only get one row back or you want the first one and don't care about anything else. get-by-id, which exists in clojure.java.jdbc as well, returns the first match, for example. This is so you can rely on execute-one! returning a hash map (or nil if there are no matches), whereas execute! will always return a vector of hash maps (and may be empty). That way you get some guarantees.

👍 4