diff --git a/src/wanijo/infrastructure/neo4j.clj b/src/wanijo/infrastructure/neo4j.clj index ecbf1bb..6e63783 100644 --- a/src/wanijo/infrastructure/neo4j.clj +++ b/src/wanijo/infrastructure/neo4j.clj @@ -14,16 +14,28 @@ #(re-matches #"[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+" %)) +(defn create-conn! + ([] + (let [env #(or (System/getenv %1) %2) + port (env "NEO4J_PORT" "7687") + host (env "NEO4J_HOST" "localhost") + user (env "NEO4J_USER" "neo4j") + pass (env "NEO4J_PASS" "b")] + (create-conn! port host user pass))) + ([port host user pass] + (db/connect + (str "bolt://" host ":" port) + user + pass))) + (def conn - (let [env #(or (System/getenv %1) %2) - port (env "NEO4J_PORT" "7687") - host (env "NEO4J_HOST" "localhost") - user (env "NEO4J_USER" "neo4j") - pass (env "NEO4J_PASS" "b")] - (delay (db/connect - (str "bolt://" host ":" port) - user - pass)))) + (atom nil)) + +(defn reset-conn! + ([] + (reset! conn (create-conn!))) + ([port host user pass] + (reset! conn (create-conn! port host user pass)))) (defmacro defquery [& args] `(db/defquery ~@args)) @@ -40,12 +52,15 @@ (cljs/join \newline))) (defn exec-query! [qry params] - (with-open [session (db/get-session @conn)] - (devmode/send-to-bar - (str (butiful-query qry) - "
---Params---
" - params)) - (qry session params))) + (let [live-conn (if (nil? @conn) + (reset-conn!) + @conn)] + (with-open [session (db/get-session live-conn)] + (devmode/send-to-bar + (str (butiful-query qry) + "
---Params---
" + params)) + (qry session params)))) (spec/def ::tuple-query-list (spec/coll-of