-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(q): Update query handling with customizable result-set-fn #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
Previously, unexpected step codes were ignored
|
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. |
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. |
|
@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 |
|
Oh nice! 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)))) |
|
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). |
Modified the
q*function to enable reducing results viaIReduceInit. Added aresult-set-fnoption inqto allow customization of query result transformations, defaulting to a vector (same as current behavior).[blind shot, untested]