duct

pablohenriq 2019-05-01T18:47:11.003100Z

This channel still work?

2019-05-01T19:28:12.003800Z

Yeah, but chances are nobody used duct with toucan.

2019-05-01T19:28:45.004300Z

What are you trying to implement?

2019-05-01T19:31:19.005300Z

For me it looks like you should create your component, which will connect / disconnect to database on init / halt

2019-05-01T19:36:16.005800Z

You should also note https://github.com/metabase/toucan/issues/42

2019-05-01T19:37:12.006700Z

Looks like toucan prefers to set global default connection and then all functions will use it.

2019-05-01T19:49:07.010400Z

So, one of the ways is like this

clojure
(ns foo.database.toucan
  (:require [toucan.db :as db]))

(defmethod ig/init-key :foo.database/toucan [_ options]
  ; the options are
  ; {:classname   "org.postgresql.Driver"
  ;  :subprotocol "postgresql"
  ;  :subname     "//localhost:5432/my_db"
  ;  :user        "cam"}
  (db/set-default-db-connection! options))

(defmethod ig/halt-key! :foo.database/toucan [_ {:keys [spec]}]
  ;; somehow close connection, probably should look into toucan / clojure.java.jdbc
  )

2019-05-01T19:50:25.011400Z

Then use toucan as usual.

2019-05-01T19:52:19.012800Z

The problem with connection closing is that duct workflow includes reloading the system, and when the system reloads you should, probably, close old connections.

đź‘Ť 1
2019-05-01T19:53:11.013700Z

For connection pools it might be easier, because connection pool will be component by itself.

2019-05-01T19:55:23.014700Z

Looking at toucan code you might not need to close the connection.

2019-05-01T19:58:54.016100Z

But there’s other issue with toucan — the default db connection is an implicit dependency, and duct / integrant style prefers explicit dependencies.

2019-05-01T20:02:33.018600Z

Issue https://github.com/metabase/toucan/issues/42 contains a general description of explicit dependency usage.