This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-03
Channels
- # announcements (1)
- # asami (13)
- # babashka (14)
- # beginners (58)
- # calva (49)
- # cljs-dev (6)
- # clojure (99)
- # clojure-europe (28)
- # clojure-gamedev (4)
- # clojure-nl (19)
- # clojure-spec (4)
- # clojure-uk (39)
- # clojured (5)
- # clojurescript (39)
- # code-reviews (3)
- # conjure (4)
- # cryogen (12)
- # cursive (21)
- # data-science (4)
- # datalog (1)
- # datomic (16)
- # duct (4)
- # events (1)
- # fulcro (6)
- # graalvm (1)
- # graphql (1)
- # jobs (13)
- # jobs-discuss (23)
- # kaocha (2)
- # lsp (15)
- # malli (24)
- # missionary (6)
- # off-topic (21)
- # polylith (75)
- # releases (2)
- # remote-jobs (4)
- # shadow-cljs (47)
- # sql (35)
- # vim (10)
- # xtdb (4)
Hi there, we are trying sslkey
, sslcert
and sslrootcert
as variables in the spec but if I set them and try to connect it still complains that it needs the cert.
However if I set the connection-uri
with those values set it connects. Is there a known problem with passing those keys via db map?
What do you mean by :spec
? There’s no such key in clojure.java.jdbc
or next.jdbc
.
Yeah well right I meant what also jasonrussel
down there has - the map that includes all the options
Show code please.
(defn env-db
"Compute the db containing the spec from the environment."
[]
{:spec {:dbtype "postgresql"
:host "localhost"
:dbname "server"
:user "user"
:password "INeedToBeMoreSecureThanThis!"
:port "5432"
:ssl true
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
:sslcert "/path/to/cert"
:sslkey "/path/to/key"
:sslrootcert "/path/to/root-cert"}})
And that does not connect whereas the same params passed in a connection string seem to be passed down to the driver and it connects properlyHow are you using that nested hash map?
I am using it in something like this
(jdbc/with-db-transaction [tx spec]
(expire-existing-configuration! tx procedure-type)
(let [sequence-id-by-unique-id-lookup (save-sequence-groups tx procedure-type sequence-groups)]
(save-protocol-groups tx procedure-type sequence-id-by-unique-id-lookup protocol-groups)))
but we also have Hugsql for some other queryWe use a db-spec hash map with extra keys to control SSL stuff at work and it works exactly as expected so “you’re doing it wrong” is my first reaction to this 🙂
That’s not next.jdbc
, that’s clojure.java.jdbc
.
yeah I am trying to understand what the wrong is
OK, and spec
in that call is … what?
the nested map
(:spec env-db)
specifically you mean?
uhm...no I {:keys [spec]}
in that function arguments
(it connects fine without SSL so I am fairly sure that I got that part right :D)
checking now the library source
Can you show me the connection string that works?
sure one sec
Basically those extra fields are just passed to as-properties
which is then, in turn, passed directly into the JDBC driver itself.
I see - yeah I think that's something else there - just a sec I am basically helping a colleague on this
(my suspicion is you don’t have the correct case on the keys in the map compared to the JDBC query parameters)
I think you are on the money there - I am debugging that with my colleague - thanks for the hint!
Hey all 👋 Quick question from a clojure newbie.
I’m trying to create a postgres connection pool with next.jdbc
and HikariCP
by following this example from the next.jdbc
docs:
(def db-spec {:dbtype .. :dbname .. :user .. :password ..
:serverTimezone "UTC"})
(def ds (next.jdbc.connection/->pool
HikariCP {:jdbcUrl (next.jdbc.connection/jdbc-url db-spec)
:maximumPoolSize 15}))
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.659/api/next.jdbc.connection#jdbc-url
However, I don’t know where/how to require HikariCP
as referenced in the above snippet.
If anyone could please point me in the right direction it would be much appreciated. Thanks in advanced.I’ve managed to create a pool using hikari
like so:
You don’t need the Hikari Clojure lib.
HikariCP
is a class, so you would :import
it, not :require
it. You’ll need the dependency in your deps.edn
file (or project.clj
file if you’re still using Leiningen): com.zaxxer/HikariCP
, version "3.4.2"
. And in your namespace you’ll need this: https://github.com/seancorfield/next-jdbc/blob/develop/test/next/jdbc_test.clj#L18
This is all explained in the next.jdbc
Getting Started documentation: https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.659/doc/getting-started#connection-pooling — let me know if any of that isn’t clear.
Great, its working, thanks @seancorfield 🙂 The only thing I didn’t understand was that [com.zaxxer/HikariCP "3.4.2"]
and [hikari-cp "2.13.0"]
are different deps.
So if I understand this correctly:
I’m adding the java Hikari lib to my deps with [com.zaxxer/HikariCP "3.4.2"]
, and referencing the underlying Java class through (:import (com.zaxxer.hikari HikariDataSource))
and passing that to next.jdbc.connection/->pool
.
Is my understanding correct here?
Yup, exactly right. Per the next.jdbc
docs 🙂
Great, the docs make complete sense in hindsight. Thanks!
If you have suggestions on how to make any of that clearer, especially for new folks, let me know. Always happy to update the docs.
Will do so, thanks for your help 🙂