forked from infi-nl/alibi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns timi.server.components.db | ||
(:require | ||
[com.stuartsierra.component :as component] | ||
[clojure.java.jdbc :as jdbc] | ||
[taoensso.timbre :as log])) | ||
|
||
(defn get-db-spec | ||
[config] | ||
(-> config | ||
:persistence | ||
(config))) | ||
|
||
(defrecord DBManager [] | ||
component/Lifecycle | ||
|
||
(start [component] | ||
(log/info "Starting database manager ...") | ||
(let [cfg (get-in component [:cfg-mgr :cfg]) | ||
db-spec (get-db-spec cfg) | ||
conn (jdbc/get-connection db-spec)] | ||
(log/trace "Using config:" cfg) | ||
(log/debug "Using db spec:" db-spec) | ||
(log/debug "Component keys:" (keys component)) | ||
(log/debug "Successfully created database manager.") | ||
(assoc component | ||
:db-spec db-spec | ||
:conn conn))) | ||
|
||
(stop [component] | ||
(log/info "Stopping database manager ...") | ||
(log/debug "Component keys" (keys component)) | ||
component)) | ||
|
||
(defn new-db-manager [] | ||
(->DBManager)) |