Fork me on GitHub
#duct
<
2019-05-01
>
pablohenriq18:05:11

This channel still work?

jahson19:05:12

Yeah, but chances are nobody used duct with toucan.

jahson19:05:45

What are you trying to implement?

jahson19:05:19

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

jahson19:05:12

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

jahson19:05:07

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
  )

jahson19:05:25

Then use toucan as usual.

jahson19:05:19

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

👍 4
jahson19:05:11

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

jahson19:05:23

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

jahson19:05:54

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

jahson20:05:33

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