Skip to content
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

Easier counting with next.jdbc.sql/find-by-keys #274

Closed
vemv opened this issue Jan 29, 2024 · 5 comments
Closed

Easier counting with next.jdbc.sql/find-by-keys #274

vemv opened this issue Jan 29, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@vemv
Copy link
Contributor

vemv commented Jan 29, 2024

Is your feature request related to a problem? Please describe.

I'd like to sql-count more easily while using find-by-keys.

I can pass :columns [["count(*)" :total]] and then -> ,,, first :total the result.

But neither bit seems intuitive to me.

Describe the solution you'd like

An option in find-by-keys that translates to a count, maybe?

Describe alternatives you've considered

A separate function in the same ns that takes similar options to find-by-keys, but that performs a count and returns a number (the count) rather than a coll of results.

Thanks - V

@seancorfield
Copy link
Owner

I'll think about it -- I really don't want to expand the "Friendly SQL Functions": I'd rather folks used HoneySQL for more complex SQL and plan/select-one! to get a single column value out of a result set.

@seancorfield seancorfield self-assigned this Jan 29, 2024
@seancorfield seancorfield added enhancement New feature or request needs analysis The solution is non-obvious labels Jan 29, 2024
@vemv
Copy link
Contributor Author

vemv commented Jan 29, 2024

Yes, agreed. I much appreciate Honey but in my current context, socially we decided to stick to next.jdbc.sql for the time being.

@seancorfield
Copy link
Owner

How would you feel about this:

(aggregate-by-keys ds :table "count(*)" :total where-map opts)
;; would call:
(-> (find-by-keys ds :table where-map (assoc opts :columns [["count(*)" :total]])) first :total)

This would allow for more general aggregation. Perhaps the alias keyword (:total here) could be some weird, internal gensym'd name so you didn't need to specify it at all...?

@vemv
Copy link
Contributor Author

vemv commented Feb 4, 2024

Yes the :total would seem like some friction for users.

Other than that, it looks reasonable to me!

@seancorfield seancorfield removed the needs analysis The solution is non-obvious label Feb 15, 2024
@vemv
Copy link
Contributor Author

vemv commented Mar 16, 2024

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants