diff --git a/doc/extending-honeysql.md b/doc/extending-honeysql.md index 69dafe9..ed734e6 100644 --- a/doc/extending-honeysql.md +++ b/doc/extending-honeysql.md @@ -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 diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 4e58ee6..baf0ce3 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -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)]