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
750 stars 89 forks source link

Doc: Fix incorrect parentheses in doc for find-by-keys #253

Closed conan closed 1 year ago

conan commented 1 year ago

I just tried the find-by-keys function for the first time following the docs:

(sql/find-by-keys db/ds :messages {:email "joe@bloggs.com"} {:columns [[:id]]})

I got this error:

Execution error (NullPointerException) at next.jdbc.sql.builder/safe-name (builder.clj:27).
Cannot invoke "clojure.lang.Named.getName()" because "x" is null

I changed {:columns [[:id]]} to {:columns [:id]} and it worked and returned me the results I needed. My observed behaviour is what I'd expect anyway, so I think it's just a typo.

seancorfield commented 1 year ago

This is incorrect.

Per the docs:

The default behavior is to return all the columns in each row. You can specify a subset of columns to return using the :columns option. It takes a vector and each element of the vector can be:

The example in the docs has [[:email :address]] which means: select column email AS address

If you want just id then [:id] will select it. If you want id AS the_key then you want [[:id :the_key]]

conan commented 12 months ago

sorry, i misunderstood, thank you for the explanation