sql

All things SQL and JDBC...
2021-02-24T19:04:39.042800Z

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.

seancorfield 2021-02-24T19:25:29.044Z

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

2021-02-24T19:29:01.046900Z

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

seancorfield 2021-02-24T19:32:44.049800Z

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

2021-02-24T19:36:49.053800Z

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

dharrigan 2021-02-24T19:37:58.054400Z

I just did this, very quickly and works for me

dharrigan 2021-02-24T19:38:01.054600Z

(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/-&gt;pool HikariDataSource config))

(defn connection-pool-stop
  [^HikariDataSource datasource]
  (.close datasource))

(def connection (connection-pool-start config))

(jdbc/execute! connection (-&gt; (select :*)
                              (from :foo)
                              sql/format)) ;; [#:foo{:firstname "david"}]

(connection-pool-stop connection)

🙏 1
dharrigan 2021-02-24T19:38:43.055100Z

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

dharrigan 2021-02-24T19:38:44.055300Z

.

2021-02-24T19:39:10.055800Z

thanks a lot @dharrigan I will check that out

dharrigan 2021-02-24T19:39:17.056Z

you're most welcome 🙂

2021-02-24T20:03:16.057900Z

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
dharrigan 2021-02-24T20:09:02.058400Z

no problemo 🙂