readme example will try to connect to the datasource during compilation
yogthos opened this issue · 2 comments
yogthos commented
The example here will create the datasource at compile time, which is typically not what you want. It would be better to update it to use an atom:
(defonce datasource (atom nil))
(defn connect! []
(reset! datasource (make-datasource datasource-options)))
(defn disconnect! []
(swap! datasource #(when % (close-datasource %))))
(defn -main [& args]
(connect!)
(jdbc/with-db-connection [conn {:datasource @datasource}]
(let [rows (jdbc/query conn "SELECT 0")]
(println rows)))
(disconnect!))
alternatively with mount
(defstate datasource
:start (make-datasource datasource-options)
:stop (close-datasource datasource))
yogthos commented
sure thing