2015-10-20 12:53:09 +00:00
|
|
|
(ns app.nyse
|
2015-10-20 01:33:56 +00:00
|
|
|
(:require [mount :refer [defstate]]
|
|
|
|
|
[datomic.api :as d]
|
2015-10-20 12:53:09 +00:00
|
|
|
[clojure.tools.logging :refer [info]]
|
|
|
|
|
[app.config :refer [app-config]]))
|
2015-10-20 01:33:56 +00:00
|
|
|
|
|
|
|
|
(defn- new-connection [conf]
|
|
|
|
|
(info "conf: " conf)
|
|
|
|
|
(let [uri (get-in conf [:datomic :uri])]
|
|
|
|
|
(info "creating a connection to datomic:" uri)
|
|
|
|
|
(d/create-database uri)
|
|
|
|
|
(d/connect uri)))
|
|
|
|
|
|
|
|
|
|
(defn disconnect [conf conn]
|
|
|
|
|
(let [uri (get-in conf [:datomic :uri])]
|
|
|
|
|
(info "disconnecting from " uri)
|
2015-10-20 12:36:00 +00:00
|
|
|
(.release conn) ;; usually it's not released, here just to illustrate the access to connection on (stop)
|
2015-10-20 01:33:56 +00:00
|
|
|
(d/delete-database uri)))
|
|
|
|
|
|
|
|
|
|
(defstate conn :start (new-connection app-config)
|
|
|
|
|
:stop (disconnect app-config conn))
|