Fork me on GitHub
#sql
<
2019-09-26
>
Ben Hammond16:09:46

I am looking at how I could use http://testcontainers.org to automate Postgres testing If I can rewrite the jdbc url from jdbc: to jdbc:tc: then test containers should hook itself up but then I need to get clojure.java.jdbc to be aware of the tc subprotocol https://github.com/clojure/java.jdbc/blob/1f1ff8144b4a9a4447b2a2fbb9e592f90ccd2659/src/main/clojure/clojure/java/jdbc.clj#L172-L179 seems to have its protocols locked down as private is there an official way to extend with new protocols ?

Ben Hammond16:09:50

well my goal would be to not use jdbc URLs either, but something more like

(jdbc/with-db-connection [db {:dbtype "tc:postgres",
                              :host "localhost",
                              :port "5432",
                              :user "testuser",
                              :password "testpassword",
                              :dbname "testdatabase"}]
...

seancorfield16:09:09

Just add :classname to that db-spec

👍 4
seancorfield16:09:39

This is a lot easier (and better documented) in next.jdbc...

Ben Hammond19:09:05

ooh I failed to spot that

seancorfield19:09:48

Also may be useful for PostgreSQL testing: there's an embedded PostgreSQL database library, which is what next.jdbc uses. See https://github.com/seancorfield/next-jdbc/blob/master/test/next/jdbc/test_fixtures.clj#L53 (code to start an in-memory instance) and https://github.com/seancorfield/next-jdbc/blob/master/deps.edn#L17 (dependency for it)

Ben Hammond20:09:13

com.opentable.components/otj-pg-embedded
I'll take a look at that