Fork me on GitHub
#sql
<
2021-02-24
>
kaffein19:02:39

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:"
  "password" = "postgres"
  "pool" = nil
  "poolName" = nil
  "schema" = nil
   ...
  "username" = "postgres"
Does anyone have an idea of what I am missing please ? thanks in adv.

seancorfield19:02:29

@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?

kaffein19:02:01

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

seancorfield19:02:44

You need to provide us with more details of what you are doing...

kaffein19:02:49

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

dharrigan19:02:58

I just did this, very quickly and works for me

dharrigan19:02:01

(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)

🙏 1
dharrigan19:02:43

that's with postgres running in a docker container, thus: docker run --rm --name postgres -it -e POSTGRES_PASSWORD=password -p 5432:5432 postgres

kaffein19:02:10

thanks a lot @dharrigan I will check that out

dharrigan19:02:17

you're most welcome 🙂

kaffein20:02:16

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

1
dharrigan20:02:02

no problemo 🙂