Add clause-order to see current clause order

This should help when folks are figuing out `register-clause!` calls.
This commit is contained in:
Sean Corfield 2021-04-09 16:31:16 -07:00
parent af382708e5
commit 106b19bcf6
2 changed files with 15 additions and 7 deletions

View file

@ -33,12 +33,10 @@ The third argument to `register-clause!` allows you to
insert your new clause formatter so that clauses are
formatted in the correct order for your SQL dialect.
For example, `:select` comes before `:from` which comes
before `:where`. This is the most implementation-specific
part of extending HoneySQL because you'll need to look at
the (private) Var `default-clause-order` in `honey.sql`
for guidance. _[I plan to add a section in the documentation
somewhere that lists built-in clauses in order which this
can link to...]_
before `:where`. You can call `clause-order` to see what the
current ordering of clauses is.
> Note: if you call `register-clause!` more than once for the same clause, the last call "wins". This allows you to correct an incorrect clause order insertion by simply calling `register-clause!` again with a different third argument.
## Registering a New Operator

View file

@ -1205,6 +1205,14 @@
(when-let [f (:clause-order-fn @default-dialect)]
(reset! current-clause-order (f @base-clause-order))))
(defn clause-order
"Return the current order that known clauses will be applied when
formatting a data structure into SQL. This may be useful when you are
figuring out the `before` argument of `register-clause!` as well as
for debugging new clauses you have registered."
[]
@current-clause-order)
(defn register-clause!
"Register a new clause formatter. If `before` is `nil`, the clause is
added to the end of the list of known clauses, otherwise it is inserted
@ -1216,7 +1224,9 @@
clause `before` a clause that is ordered differently in different
dialects, your new clause may also end up in a different place. The
only clause so far where that would matter is `:set` which differs in
MySQL."
MySQL.
Use `clause-order` to see the full ordering of existing clauses."
[clause formatter before]
(let [clause (sym->kw clause)
before (sym->kw before)]