This is a small footgun (at least for me 😅)
(next.jdbc/execute conn ["SELECT count(*) FROM mytable"])
=> [{:count(*) 42}]Is there an option for execute so that the key isn't :count(*) (which doesn't seem to be a valid keyword), without changing the query?
1. You can construct the keyword from a string:
(keyword "count(*)")
:count(*)
define it as a constant and then
(-> result first (get COUNT_KEYWORD))
2. pass another result-set builder to your query, for example the one that produces a flat matrix (array or something). The first row will be a header, and the second row represents values:
(-> result second first)can you give the count a name? count(*) as cnt
if your query has no other columns, just take the first row and the first map entry, and its value :
(-> result first first val)count(*) is what JDBC returns for the column label if there is no alias. next.jdbc is a *very* thin wrapper here 🙂
@igrishaev minor note: you can ffirst instead of first first
Another option: (plan/select-one! ds (comp first vals) ["select count(*) from user"]) 🙂
why not specify a column alias explicitly, like SELECT count(*) AS 'frob/count' FROM mytable?
(the AS is optional, btw and the column alias quoting might be different, depending on the SQL dialect)
In this case I cannot control the query