Skip to content

Conversation

@mpenet
Copy link

@mpenet mpenet commented Dec 10, 2025

Modified the q* function to enable reducing results via IReduceInit. Added a result-set-fn option in q to allow customization of query result transformations, defaulting to a vector (same as current behavior).

[blind shot, untested]

Modified the `q*` function to enable reducing results via `IReduceInit`.
Added a `result-set-fn` option in `q` to allow customization of query result
transformations, defaulting to a vector.
@mpenet mpenet changed the title refactor(core): Update query handling with customizable result-set-fn refactor(q): Update query handling with customizable result-set-fn Dec 10, 2025
Previously, unexpected step codes were ignored
@andersmurphy
Copy link
Owner

Thanks for starting on this!

Just a heads up I'll be adding and caching the meta data for table, column name and alias which will probably be useful for this.

@mpenet
Copy link
Author

mpenet commented Dec 16, 2025

Just a heads up I'll be adding and caching the meta data for table, column name and alias which will probably be useful for this.

Thanks for the info. I somewhat forgot about this pr :), blaming another side-project on that one. I ll try to get this moving during the holidays.

andersmurphy added a commit that referenced this pull request Dec 16, 2025
Based off of the work on (#5) by @mpenet
@andersmurphy
Copy link
Owner

@mpenet I needed this behaviour so I've finished it here (now on master).

It was a bit more involved to get the meta data, but your initial draft made it much easier, I had no idea about clojure.lang.IReduceInit. Really appreciate the help!

@mpenet
Copy link
Author

mpenet commented Dec 16, 2025

Oh nice!
Something similar could be done with column -> make it a first class thing and allow to specify it as a 3 arity fn:

Something along those lines:

(defn row-generator
  [ctx] ; ctx is potentially useful to retrieve column metadata, ex col name
  (fn
    ([] (transient! []))
    ([row k v] (conj! row v))
    ([row] (persistent! row))))

@mpenet
Copy link
Author

mpenet commented Dec 16, 2025

To expand on this: this would open the possibility to users to generate a map from a row, or do some more fancy things like pack values together, build records, etc...

It's quite common in db libraries, I used that here for instance: https://github.com/mpenet/alia/blob/master/modules/alia/src/qbits/alia/result_set.clj#L39-L42 (I did it with a Protocol of 3 fns, but a simple fn with 3 different arities would work just fine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants