sql

All things SQL and JDBC...
grounded_sage 2020-03-17T14:07:08.215300Z

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?

dpsutton 2020-03-17T14:37:41.216300Z

using the information in that connection string can you create a db-spec with the required information?

grounded_sage 2020-03-17T14:45:26.217300Z

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"]

dpsutton 2020-03-17T14:46:10.217800Z

can you validate your db-spec? (clojure.spec.alpha/valid? :next.jdbc.specs/db-spec {:dbtype "postgres" :dbname "bob" :username "bob" :password "secretbob"})

dpsutton 2020-03-17T14:46:32.218100Z

or turn on the instrumentation in next.jdbc.specs

dpsutton 2020-03-17T14:49:50.218400Z

and read the doc of (doc jdbc/get-datasource)

grounded_sage 2020-03-17T14:52:22.218900Z

Ok I will try. I can run queries with the db-spec hash just not the URL.

grounded_sage 2020-03-17T14:54:50.219100Z

Both validate as true

seancorfield 2020-03-17T16:45:46.219400Z

next.jdbc requires the jdbc: prefix.

seancorfield 2020-03-17T16:46:12.220Z

clojure.java.jdbc incorrectly let you omit it and it worked anyway (for some drivers?).

seancorfield 2020-03-17T16:46:26.220400Z

The JDBC spec says all URLs must begin with jdbc:.

seancorfield 2020-03-17T16:46:32.220600Z

@grounded_sage ^

grounded_sage 2020-03-17T16:47:14.220800Z

Ah thanks!

seancorfield 2020-03-17T16:47:27.221100Z

It's mentioned in https://cljdoc.org/d/seancorfield/next.jdbc/1.0.409/doc/migration-from-clojure-java-jdbc by the way.

seancorfield 2020-03-17T16:47:49.221500Z

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!"

seancorfield 2020-03-17T16:49:51.222600Z

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.

seancorfield 2020-03-17T16:56:22.222800Z

https://github.com/seancorfield/next-jdbc/issues/101