updates from trio branch, tests

master
Josha von Gizycki 3 years ago
parent 133eb49d6b
commit 4e5c86b808

@ -7,7 +7,7 @@
:dependencies [;;clojure core :dependencies [;;clojure core
[org.clojure/clojure "1.10.1"] [org.clojure/clojure "1.10.1"]
[nrepl "0.8.3"] ; [nrepl "0.9.0-beta2"]
;; static site ;; static site
[compojure "1.6.2"] [compojure "1.6.2"]
@ -65,7 +65,9 @@
[jonase/eastwood "LATEST"] [jonase/eastwood "LATEST"]
[lein-bikeshed "LATEST"] [lein-bikeshed "LATEST"]
[lein-cloverage "LATEST"] [lein-cloverage "LATEST"]
[lein-kibit "LATEST"]]} [lein-kibit "LATEST"]
; [cider/cider-nrepl "0.26.0"]
]}
:uberjar {:aot :all :uberjar {:aot :all
:main wanijo.main}} :main wanijo.main}}

@ -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

@ -125,6 +125,10 @@
(neo4j/in-memory-conn!) (neo4j/in-memory-conn!)
(create-user! "admin" "admin")) (create-user! "admin" "admin"))
(defn dev-env! []
(setup-in-memory!)
(dev-server!))
(comment (comment
(dev-server!) (dev-server!)
(setup-in-memory!) (setup-in-memory!)

@ -0,0 +1,7 @@
(ns wanijo.infra.sysconfig)
(defn env
([name]
(System/getenv name))
([name default]
(or (System/getenv name) default)))

@ -75,6 +75,7 @@
(let [form-data (form/form-data form-def req) (let [form-data (form/form-data form-def req)
form-instance (forms-inst/form-data->instance form-data attrs) form-instance (forms-inst/form-data->instance form-data attrs)
instance (assoc form-instance :uuid uuid)] instance (assoc form-instance :uuid uuid)]
(clojure.pprint/pprint instance)
(domain/edit! instance) (domain/edit! instance)
(resp/redirect (path :instance-show instance))) (resp/redirect (path :instance-show instance)))
(route-show! uuid req)))) (route-show! uuid req))))
@ -156,7 +157,7 @@
(resp/redirect (path :instance-show {:uuid uuid}))) (resp/redirect (path :instance-show {:uuid uuid})))
(defn schema-uuid-by-instance [req] (defn schema-uuid-by-instance [req]
(-> (get-in req [:params :schema-uuid]) (-> (get-in req [:params :uuid])
(domain-schema/find-by-instance!) (domain-schema/find-by-instance!)
:uuid)) :uuid))

Loading…
Cancel
Save