|
|
|
@ -4,7 +4,8 @@
|
|
|
|
|
[clj-time.format :as time-format]
|
|
|
|
|
[clj-time.local :as time-local]
|
|
|
|
|
[clojure.spec.alpha :as spec]
|
|
|
|
|
[clojure.string :as cljs])
|
|
|
|
|
[clojure.string :as cljs]
|
|
|
|
|
[wanijo.infra.sysconfig :refer [env]])
|
|
|
|
|
(:import (java.util UUID)
|
|
|
|
|
(java.net URI)))
|
|
|
|
|
|
|
|
|
@ -22,8 +23,7 @@
|
|
|
|
|
|
|
|
|
|
(defn create-conn!
|
|
|
|
|
([]
|
|
|
|
|
(let [env #(or (System/getenv %1) %2)
|
|
|
|
|
port (env "NEO4J_PORT" standard-port)
|
|
|
|
|
(let [port (env "NEO4J_PORT" standard-port)
|
|
|
|
|
host (env "NEO4J_HOST" standard-host)
|
|
|
|
|
user (env "NEO4J_USER" standard-user)
|
|
|
|
|
pass (env "NEO4J_PASS" standard-pass)]
|
|
|
|
@ -34,8 +34,7 @@
|
|
|
|
|
user
|
|
|
|
|
pass)))
|
|
|
|
|
|
|
|
|
|
(def conn
|
|
|
|
|
(atom nil))
|
|
|
|
|
(def conn (atom nil))
|
|
|
|
|
|
|
|
|
|
(defn reset-conn!
|
|
|
|
|
([]
|
|
|
|
@ -46,13 +45,17 @@
|
|
|
|
|
(defn in-memory-conn! []
|
|
|
|
|
(reset! conn (db-inm/create-in-memory-connection)))
|
|
|
|
|
|
|
|
|
|
(defmacro defquery [& args] `(db/defquery ~@args))
|
|
|
|
|
(defonce query-strings (atom {}))
|
|
|
|
|
(defmacro defquery [name query]
|
|
|
|
|
`(do (def ~name (db/create-query ~query))
|
|
|
|
|
(swap! wanijo.infra.neo4j/query-strings
|
|
|
|
|
assoc (hash ~name) ~query)))
|
|
|
|
|
|
|
|
|
|
(defn uuid []
|
|
|
|
|
(str (UUID/randomUUID)))
|
|
|
|
|
|
|
|
|
|
(defn butiful-query [qry]
|
|
|
|
|
(->> qry
|
|
|
|
|
(->> (get @query-strings (hash qry) "unknown query")
|
|
|
|
|
str
|
|
|
|
|
cljs/trim-newline
|
|
|
|
|
cljs/split-lines
|
|
|
|
@ -60,9 +63,14 @@
|
|
|
|
|
(filter #(pos? (count %)))
|
|
|
|
|
(cljs/join \newline)))
|
|
|
|
|
|
|
|
|
|
(def log-queries (= "true" (env "LOG_QUERIES" "false")))
|
|
|
|
|
(comment (def log-queries true))
|
|
|
|
|
|
|
|
|
|
(defn exec-query! [qry params]
|
|
|
|
|
(let [live-conn (or @conn (reset-conn!))]
|
|
|
|
|
(with-open [session (db/get-session live-conn)]
|
|
|
|
|
(when log-queries
|
|
|
|
|
(println (butiful-query qry) \newline params \newline))
|
|
|
|
|
;; neo4j-clj returns lazy lists, but when we leave with-open,
|
|
|
|
|
;; the ResultSet (?) is already closed, so the list cannot
|
|
|
|
|
;; be processed
|
|
|
|
|