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

Register a clause using existing formatter #380

Closed
shay-rf opened this issue Jan 21, 2022 · 4 comments
Closed

Register a clause using existing formatter #380

shay-rf opened this issue Jan 21, 2022 · 4 comments
Assignees
Labels
bug It's broken, I'll fix it!

Comments

@shay-rf
Copy link

shay-rf commented Jan 21, 2022

When I try to register a new clause via:
(sql/register-clause! :qualify :having :window )

It raises an exception "The formatter must be a function or existing clause"
Since (fn? #'honey.sql/format-on-expr ) returns false

@seancorfield seancorfield self-assigned this Jan 21, 2022
@seancorfield seancorfield added the bug It's broken, I'll fix it! label Jan 21, 2022
@seancorfield
Copy link
Owner

This also affects register-fn!.

@seancorfield
Copy link
Owner

Available to test on develop.

@shay-rf
Copy link
Author

shay-rf commented Jan 22, 2022

Thanks! a short followup question -
Now that I have :qualify registered, is there a way for a user to setup a helper function somehow? I mean, I can just assoc - but I wonder if there is a way to get the other ergonomics from the helper of the original clause I mimic.

For example:
(-> (h/select :*) (h/from :foo) (h/where [:= :a "a"]) (my-qualify [...] )

@seancorfield
Copy link
Owner

There isn't anything public right now, but you could do:

(defn my-qualifiy [& args]
  (#'honey.sql.helpers/generic :qualify args))

Most helper functions look like that, or else use generic-1 for clauses that don't "merge", such as update, delete, truncate (generic-1 does an assoc inserting an empty map if the first argument is not a map).

I could make those public (with better names) and document them -- open a new issue if you think that's worthwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's broken, I'll fix it!
Projects
None yet
Development

No branches or pull requests

2 participants