With next.jdbc
I’m trying to move some code from clojure.java.jdbc
that uses a string URL like so. "<postgresql://USERNAME>:PASSWORD@0.0.0.0:5432/DBNAME"
. However this ends up different than using the spec hashmap when passed to (jdbc/get-datasource db-spec)
. If I use the existing URL the queries fail. What am I doing wrong?
using the information in that connection string can you create a db-spec with the required information?
This is datasource when I provide the details as the spec hash.
#object[next.jdbc.connection$url_PLUS_etc$reify__6503 0x3e3886c2 "jdbc:<postgresql://0.0.0.0:5432/db-name>"]
This is when I provide the URL
#object[next.jdbc.connection$url_PLUS_etc$reify__6503 0x16e837fc "<postgresql://USERNAME>:PASSWORD0.0.0.0:5432/DBNAME"]
can you validate your db-spec? (clojure.spec.alpha/valid? :next.jdbc.specs/db-spec {:dbtype "postgres" :dbname "bob" :username "bob" :password "secretbob"})
or turn on the instrumentation in next.jdbc.specs
and read the doc of (doc jdbc/get-datasource)
Ok I will try. I can run queries with the db-spec hash just not the URL.
Both validate as true
next.jdbc
requires the jdbc:
prefix.
clojure.java.jdbc
incorrectly let you omit it and it worked anyway (for some drivers?).
The JDBC spec says all URLs must begin with jdbc:
.
Ah thanks!
It's mentioned in https://cljdoc.org/d/seancorfield/next.jdbc/1.0.409/doc/migration-from-clojure-java-jdbc by the way.
About halfway down the page "Note that clojure.java.jdbc allowed the jdbc: prefix in a JDBC URI to be omitted but next.jdbc requires that prefix!"
I will open an issue to update the spec to check the format of the URL anyway, so at least if folks instrument next.jdbc
it would fail validation.