move form neocons to neo4j-clj, update dependencies

integration-tests
Josha von Gizycki 6 years ago
parent d7947c431a
commit 2b09913ca4

@ -3,10 +3,9 @@
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:min-lein-version "2.0.0" :min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.9.0"] :dependencies [[org.clojure/clojure "1.9.0"]
[compojure "1.5.1"] [compojure "1.6.1"]
[ring/ring-defaults "0.2.1"] [ring/ring-defaults "0.3.2"]
[clojurewerkz/neocons "3.2.0" [gorillalabs/neo4j-clj "1.1.0"]
:exclusions [commons-codec]]
[hiccup "1.0.5"] [hiccup "1.0.5"]
[buddy/buddy-hashers "1.3.0" [buddy/buddy-hashers "1.3.0"
:exclusions [commons-codec]]] :exclusions [commons-codec]]]
@ -14,7 +13,7 @@
:ring {:handler wanijo.handler/app} :ring {:handler wanijo.handler/app}
:profiles {:dev {:dependencies :profiles {:dev {:dependencies
[[javax.servlet/servlet-api "2.5"] [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]] [ring/ring-mock "0.3.2"]]
:plugins [[lein-less "1.7.5"]]}} :plugins [[lein-less "1.7.5"]]}}
:less {:source-paths ["resources/app/stylesheets"] :less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"} :target-path "resources/public/css"}

@ -11,27 +11,34 @@
:str (spec/and string? :str (spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %)))) #(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(neo4j/defquery
all-created-by
"MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.uuid = {uuid}
RETURN s
ORDER BY s.name")
(defn all-created-by! [user-uuid] (defn all-created-by! [user-uuid]
(neo4j/query-rawdata! (map :s
:query (neo4j/exec-query
"MATCH (s:schema)-[:created_by]->(u:user) all-created-by
WHERE u.uuid = {uuid} {:uuid user-uuid})))
RETURN s
ORDER BY s.name" (neo4j/defquery
:params {:uuid user-uuid} create-new
:alias "s")) "MATCH (u:user)
WHERE u.uuid = {u_uuid}
CREATE (s:schema)-[:created_by]->(u)
SET s.name = {name}
SET s.uuid = {s_uuid}
RETURN s")
(defn create-new! [name user-uid] (defn create-new! [name user-uuid]
(:uuid (->>
(neo4j/query-rawdata! (neo4j/exec-query
:query create-new
"MATCH (u:user) {:u_uuid user-uuid
WHERE u.uuid = {u_uuid} :name name
CREATE (s:schema)-[:created_by]->(u) :s_uuid (neo4j/uuid)})
SET s.name = {name} first
SET s.uuid = {s_uuid} :uuid))
RETURN s"
:params {:u_uuid user-uid
:name name
:s_uuid (neo4j/uuid)}
:alias "s")))

@ -1,12 +1,16 @@
(ns wanijo.domain.user (ns wanijo.domain.user
(:require [wanijo.neo4j :as neo4j])) (:require [wanijo.neo4j :as neo4j]))
(neo4j/defquery
find-user
"MATCH (n:user)
WHERE n.ident = {ident}
RETURN n")
(defn find! [ident] (defn find! [ident]
(first (->>
(neo4j/query-rawdata! (neo4j/exec-query
:query find-user
"MATCH (n:user) {:ident ident})
WHERE n.ident = {ident} first
RETURN n" :n))
:alias "n"
:params {:ident ident})))

@ -1,34 +1,31 @@
(ns wanijo.neo4j (ns wanijo.neo4j
(:require [clojurewerkz.neocons.rest :as nr] (:require [neo4j-clj.core :as db]
[clojurewerkz.neocons.rest.nodes :as nrn]
[clojurewerkz.neocons.rest.cypher :as cypher]
[wanijo.devmode :as devmode])) [wanijo.devmode :as devmode]))
(def conn (def conn
(delay (nr/connect "http://neo4j:b@localhost:7474/db/data"))) (delay (db/connect
"bolt://localhost:7687"
"neo4j"
"b")))
(defn conn! [] (defmacro defquery [& args] `(db/defquery ~@args))
@conn)
(defn uuid [] (defn uuid []
(str (java.util.UUID/randomUUID))) (str (java.util.UUID/randomUUID)))
(defn butiful-query [qry] (defn butiful-query [qry]
(->> qry (->> qry
str
clojure.string/trim-newline clojure.string/trim-newline
clojure.string/split-lines clojure.string/split-lines
(map clojure.string/trim) (map clojure.string/trim)
(filter #(> (count %) 0)) (filter #(> (count %) 0))
(clojure.string/join \newline))) (clojure.string/join \newline)))
(defn query-rawdata! (defn exec-query [qry params]
[& {:keys [query alias params] (with-open [session (db/get-session @conn)]
:or {params {}}}] (devmode/send-to-bar
(devmode/send-to-bar (str (butiful-query qry)
(str (butiful-query query) "<br>---Params---<br>"
"<br>---Params---<br>" params))
params)) (qry session params)))
(->>
(cypher/tquery (conn!) query params)
(map #(get % alias))
(map :data)))

@ -1,17 +1,18 @@
(ns wanijo.repl (ns wanijo.repl
(:require [clojurewerkz.neocons.rest.nodes :as nodes] (:require [buddy.hashers :as hashers]
[clojurewerkz.neocons.rest.labels :as labels] [neo4j-clj.core :as db]
[clojurewerkz.neocons.rest.cypher :as cypher]
[buddy.hashers :as hashers]
[wanijo.neo4j :as neo4j])) [wanijo.neo4j :as neo4j]))
(db/defquery
create-user
"CREATE (n:user)
SET n.ident = {ident}
SET n.pw = {pw}
SET n.uuid = {uuid}")
(defn create-user! [ident pw] (defn create-user! [ident pw]
(cypher/tquery (neo4j/exec-query
(neo4j/conn!) create-user
"CREATE (n:user)
SET n.ident = {ident}
SET n.pw = {pw}
SET n.uuid = {uuid}"
{:ident ident {:ident ident
:pw (hashers/derive pw) :pw (hashers/derive pw)
:uuid (neo4j/uuid)})) :uuid (neo4j/uuid)}))

Loading…
Cancel
Save