diff --git a/CHANGELOG.md b/CHANGELOG.md index 33f7e7b..9633787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.4.next in progress + * Address [#458](https://github.com/seancorfield/honeysql/issues/458) by adding `registered-*?` predicates. + * 2.4.972 -- 2023-02-02 * Address [#456](https://github.com/seancorfield/honeysql/issues/456) by allowing `format` to handle expressions (like 1.x could) as well as statements. This should aid with migration from 1.x to 2.x. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 25f2a00..3cabe55 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -1784,6 +1784,11 @@ (swap! current-clause-order add-clause-before clause before) (swap! clause-format assoc clause f)))) +(defn registered-clause? + "Return true if the clause is known to HoneySQL." + [clause] + (contains? @clause-format (sym->kw clause))) + (defn register-dialect! "Register a new dialect. Accepts a dialect name (keyword) and a hash map that must contain at least a `:quoted` key whose value is a unary @@ -1814,6 +1819,11 @@ {:dialect-spec dialect-spec})))) (swap! dialects assoc dialect (assoc dialect-spec :dialect dialect))) +(defn registered-dialect? + "Return true if the dialect is known to HoneySQL." + [dialect] + (contains? @dialects dialect)) + (defn get-dialect "Given a dialect name (keyword), return its definition. Returns `nil` if the dialect is unknown." @@ -1839,6 +1849,11 @@ {:type (type formatter)}))) (swap! special-syntax assoc function f)))) +(defn registered-fn? + "Return true if the function is known to HoneySQL." + [function] + (contains? @special-syntax (sym->kw function))) + (defn register-op! "Register a new infix operator. Operators can be defined to be variadic (the default is that they are binary) and may choose to ignore `nil` arguments @@ -1852,6 +1867,11 @@ (when ignore-nil (swap! op-ignore-nil conj op)))) +(defn registered-op? + "Return true if the operator is known to HoneySQL." + [op] + (contains? @infix-ops (sym->kw op))) + ;; helper functions to create HoneySQL data structures from other things (defn map=