hi folks!! I am struggling a little bit setting up a Postgres
HikariCP
-backed connection pool with next.jdbc
. I have a Postgres running in a docker and exposed via the standard port. Nothing too fancy so far in the db-spec
:db-spec {:dbtype "postgresql"
:dbname "mydb"
:user "postgres"
:username "postgres" ;; HikariCP-specific as per the next.jdbc documentation
:password "postgres"
:host "localhost"}
though, it seems that when I call (connection/->pool HikariDataSource db-spec)
it does not set things up properly. While inspecting the returned object I have this :
Class: com.zaxxer.hikari.HikariDataSource
Value: "#object[com.zaxxer.hikari.HikariDataSource 0x390380 \"HikariDataSource (null)\"]"
---
Fields:
"catalog" = nil
...
"dataSource" = nil
"dataSourceClassName" = nil
"dataSourceProperties" = { }
"driverClassName" = nil
...
"jdbcUrl" = "jdbc:<postgresql://localhost:5432/mydb>"
"password" = "postgres"
"pool" = nil
"poolName" = nil
"schema" = nil
...
"username" = "postgres"
Does anyone have an idea of what I am missing please ? thanks in adv.@kaffein Can you explain what you mean by "not set things up properly"? What is wrong with what comes back? What code does not work that you expect to?
it seems that when I use the the returned object for my requests, it is not sent to the db... I am not sure what I screwed up
You need to provide us with more details of what you are doing...
my bad, I will revert to my previous state and check everything again. I might have some dirty state as well so I will check it again one more time first and will come back here with details. thanks a lot @seancorfield
I just did this, very quickly and works for me
(ns main
(:require
[honeysql.core :as sql]
[honeysql.helpers :as helpers :refer [select from]]
[next.jdbc :as jdbc]
[next.jdbc.connection :as connection])
(:import
[com.zaxxer.hikari HikariDataSource]))
(def config {:dbtype "postgresql"
:dbname "postgres"
:host "localhost"
:port 5432
:username "postgres"
:password "password"}) ;; #'main/config
(defn connection-pool-start
^HikariDataSource [config]
(connection/->pool HikariDataSource config))
(defn connection-pool-stop
[^HikariDataSource datasource]
(.close datasource))
(def connection (connection-pool-start config))
(jdbc/execute! connection (-> (select :*)
(from :foo)
sql/format)) ;; [#:foo{:firstname "david"}]
(connection-pool-stop connection)
that's with postgres running in a docker container, thus: docker run --rm --name postgres -it -e POSTGRES_PASSWORD=password -p 5432:5432 postgres
.
thanks a lot @dharrigan I will check that out
you're most welcome 🙂
I tore everything down and restarted and it works like charm : the only stuff I have added was the type hinting. I might have had a dirty state somewhere too. Thanks again @seancorfield and @dharrigan
no problemo 🙂