Back

plan (clj)

(source)

function

(plan stmt) (plan connectable sql-params) (plan connectable sql-params opts)
General SQL execution function (for working with result sets). Returns a reducible that, when reduced (with an initial value), runs the SQL and yields the result. `plan` returns an `IReduceInit` object so you must provide an initial value when calling `reduce` on it. The reducible is also foldable (in the `clojure.core.reducers` sense) but see the **Tips & Tricks** section of the documentation for some important caveats about that. Can be called on a `PreparedStatement`, a `Connection`, or something that can produce a `Connection` via a `DataSource`. Your reducing function can read columns by name (string or simple keyword) from each row of the underlying `ResultSet` without realizing the row as a Clojure hash map. `select-keys` can also be used without realizing the row. Operations that imply an actual Clojure data structure (such as `assoc`, `dissoc`, `seq`, `keys`, `vals`, etc) will realize the row into a hash map using the supplied `:builder-fn` (or `as-maps` by default). If your reducing function needs to produce a hash map without calling a function that implicitly realizes the row, you can call: `(next.jdbc.result-set/datafiable-row row connectable opts)` passing in the current row (passed to the reducing function), a `connectable`, and an `opts` hash map. These can be the same values that you passed to `plan` (or they can be different, depending on how you want the row to be built, and how you want any subsequent lazy navigation to be handled).

Examples