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