clj-r2dbc.impl.sql.reduce

Result reduction for clj-r2dbc execution paths.

Provides:
  make-row-fn         - builds an AtomicReference-cached row-builder function from opts.
  collect-all-results - subscribes to Publisher<Result>, collects a flat vector.
  partition-results   - partitions a flat result vector into :clj-r2dbc/rows and
                        :clj-r2dbc/update-count.

This namespace is an implementation detail; do not use from application code.

collect-all-results

(collect-all-results result-pub row-fn filter-pred)
Subscribe to result-pub (Publisher<Result>), iterate over every Result,
and collect a flat vector of all row maps and update-count maps.

Uses transient vector accumulation for O(N) performance across M Results x N rows.

Args:
  result-pub  - Publisher<Result> to subscribe to.
  row-fn      - 1-arity (Row -> value) function.
  filter-pred - optional Predicate passed to Result.filter() before processing;
                nil to skip filtering.

Returns a Missionary task resolving to a persistent vector.

make-row-fn

(make-row-fn opts)
Return a 1-arity (Row -> value) function.

Builds the RowMetadataCache lazily on the first row then reuses it for
all subsequent rows in the same result set. This is the hot-loop path.

Args:
  opts - options map; relevant keys:
           :qualifier  - column name conversion mode; one of :unqualified-kebab
                         (default), :unqualified, or :qualified-kebab.
           :builder-fn - 2-arity (Row, RowMetadata) -> value function; when
                         present, wraps it instead of building a cache.

Returns a 1-arity function (Row -> value).

partition-results

(partition-results ctx flat-vec)
Partition a flat vector of row maps and update-count maps into context keys.

Args:
  ctx      - context map to update.
  flat-vec - flat vector of row maps and update-count maps.

Returns ctx with :clj-r2dbc/rows set to the vector of row maps and
:clj-r2dbc/update-count set to the sum of all UpdateCount values (absent
when no UpdateCount segments were present).