I see an odd behavior here: https://github.com/nilenso/honeysql-postgres/blob/feb22bf7a164a23d4dbcffba35c3af4f3e4e38a3/test/honeysql_postgres/postgres_test.cljc#L3
If [honeysql-postgres.format :as sqlpf]
is removed from the ns
declaration, ON CONFLICT ON ...
stops getting added despite sqlpf
not being used. How come?
Even worse, everything keeps working after the removal until the webserver is restarted
Is that the monkey patching version of Clojure? 🙂
That's just how multimethods work: if you don't require the namespace containing the definitions of specific "clauses", then those clauses won't work.
It's the same with protocol extensions.
Namespaces are one of the few mutable, side-effect-y things in Clojure and require
modifies your "environment" by executing the top-level forms in a namespace, which both adds their definitions (bindings) to the namespace and runs any side-effecting changes those definitions cause (`def` forms have their body evaluated, defrecord
introduces several new helper functions that are "in the code", defmethod
adds to an existing defmulti
, extend-protocol
adds to an existing defprotocol
-- the latter two are potentially cross-namespace). There are probably a few other things.
Thanks for the clarification @seancorfield. It seems like I should add some tests to this area, the code is super fragile by itself.
The same is true of some namespaces in next.jdbc
BTW: next.jdbc.datafy
and next.jdbc.date-time
-- requiring them adds/changes behavior. They're optional, but if you want that behavior, you have to require them (the former exposes a single dynamic Var that controls how exceptions should be handled in the optional functionality enabled by that namespace, the latter exposes three functions that let you modify the additional behavior that requiring that namespace provides by default).