This is my first foray into Clojure (and functional programming altogether) and I'm trying to extend support for JSONB using clojure.jdbc library. I've been using this as a guide:
http://niwibe.github.io/clojure.jdbc/#_extend_sql_types
Also using leinengen so I have my dependencies setup with the following:
[org.clojure/clojure "1.6.0"]
[clj-http "0.9.1"]
[clojure.jdbc "0.3.1"]
[postgresql "9.3-1102.jdbc41"]
[org.clojure/data.json "0.2.5"]
Then I have my code which looks like this:
(require '[jdbc.proto])
(require '[clojure.data.json :as json])
(import 'org.postgresql.util.PGobject)
(extend-protocol jdbc.proto/ISQLType
clojure.lang.IPersistentMap
(set-stmt-parameter! [this conn stmt index]
(let [prepared-value (as-sql-type this conn)]
(.setObject stmt index prepared-value)))
(as-sql-type [this conn]
(doto (PGobject.)
(.setType "jsonb")
(.setValue (json/write-str)))))
When I run the REPL and try to run my load file command like
(load-file "src/db/jdbc-types-jsonb.clj")
The compiler complaines with this error:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: as-sql-type in this context, compiling:(/Users/akmiller/Source/personal/clojure-pg/src/db/jdbc-types-jsonb.clj:14:26)
I'm trying to understand why it doesn't see as-sql-type as 'this' at that point should be the protocol correct? Sorry if this is a noob type issue (I'm sure it is) but I just don't see the issue and I need some Clojure expertise to help me get past this very small hurdle!