Add clause-order to see current clause order
This should help when folks are figuing out `register-clause!` calls.
This commit is contained in:
parent
af382708e5
commit
106b19bcf6
2 changed files with 15 additions and 7 deletions
|
|
@ -33,12 +33,10 @@ The third argument to `register-clause!` allows you to
|
||||||
insert your new clause formatter so that clauses are
|
insert your new clause formatter so that clauses are
|
||||||
formatted in the correct order for your SQL dialect.
|
formatted in the correct order for your SQL dialect.
|
||||||
For example, `:select` comes before `:from` which comes
|
For example, `:select` comes before `:from` which comes
|
||||||
before `:where`. This is the most implementation-specific
|
before `:where`. You can call `clause-order` to see what the
|
||||||
part of extending HoneySQL because you'll need to look at
|
current ordering of clauses is.
|
||||||
the (private) Var `default-clause-order` in `honey.sql`
|
|
||||||
for guidance. _[I plan to add a section in the documentation
|
> 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.
|
||||||
somewhere that lists built-in clauses in order which this
|
|
||||||
can link to...]_
|
|
||||||
|
|
||||||
## Registering a New Operator
|
## Registering a New Operator
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1205,6 +1205,14 @@
|
||||||
(when-let [f (:clause-order-fn @default-dialect)]
|
(when-let [f (:clause-order-fn @default-dialect)]
|
||||||
(reset! current-clause-order (f @base-clause-order))))
|
(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!
|
(defn register-clause!
|
||||||
"Register a new clause formatter. If `before` is `nil`, the clause is
|
"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
|
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
|
clause `before` a clause that is ordered differently in different
|
||||||
dialects, your new clause may also end up in a different place. The
|
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
|
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]
|
[clause formatter before]
|
||||||
(let [clause (sym->kw clause)
|
(let [clause (sym->kw clause)
|
||||||
before (sym->kw before)]
|
before (sym->kw before)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue