Having used plan fairly extensively in production code, I see two common patterns emerging:
Obtaining a single column value (from the first row returned)
Obtaining a vector with just a subset of columns in each row
Both of these are ways to avoid realizing result sets, but they require uglier code than just using execute-one! or execute!.
;; extract a column from the first row (could apply an eager function to that first row):
(reduce (fn [_ row] (reduced (col row))) nil (jdbc/plan ...))
;; extract a subset of each row:
(into [] (map #(select-keys % cols)) (jdbc/plan ...))
;; alternative (to produce vectors instead of maps):
(into [] (map (juxt cols)) (jdbc/plan ...))
Proposal:
Add next.jdbc.plan namespace, containing select-one! and select!:
Having used
plan
fairly extensively in production code, I see two common patterns emerging:Both of these are ways to avoid realizing result sets, but they require uglier code than just using
execute-one!
orexecute!
.Proposal:
Add
next.jdbc.plan
namespace, containingselect-one!
andselect!
:In the latter,
cols-or-selector
could be a vector or a function-like thing. Passing a vector would be equivalent to passing#(select-keys % cols)
.