diff --git a/project.clj b/project.clj
index aaaf167..89f3beb 100644
--- a/project.clj
+++ b/project.clj
@@ -3,10 +3,9 @@
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.9.0"]
- [compojure "1.5.1"]
- [ring/ring-defaults "0.2.1"]
- [clojurewerkz/neocons "3.2.0"
- :exclusions [commons-codec]]
+ [compojure "1.6.1"]
+ [ring/ring-defaults "0.3.2"]
+ [gorillalabs/neo4j-clj "1.1.0"]
[hiccup "1.0.5"]
[buddy/buddy-hashers "1.3.0"
:exclusions [commons-codec]]]
@@ -14,7 +13,7 @@
:ring {:handler wanijo.handler/app}
:profiles {:dev {:dependencies
[[javax.servlet/servlet-api "2.5"]
- [ring/ring-mock "0.3.0"]]
+ [ring/ring-mock "0.3.2"]]
:plugins [[lein-less "1.7.5"]]}}
:less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"}
diff --git a/src/wanijo/domain/schema.clj b/src/wanijo/domain/schema.clj
index ade07c0..26be080 100644
--- a/src/wanijo/domain/schema.clj
+++ b/src/wanijo/domain/schema.clj
@@ -11,27 +11,34 @@
:str (spec/and string?
#(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]
- (neo4j/query-rawdata!
- :query
- "MATCH (s:schema)-[:created_by]->(u:user)
- WHERE u.uuid = {uuid}
- RETURN s
- ORDER BY s.name"
- :params {:uuid user-uuid}
- :alias "s"))
+ (map :s
+ (neo4j/exec-query
+ all-created-by
+ {:uuid user-uuid})))
+
+(neo4j/defquery
+ create-new
+ "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]
- (:uuid
- (neo4j/query-rawdata!
- :query
- "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"
- :params {:u_uuid user-uid
- :name name
- :s_uuid (neo4j/uuid)}
- :alias "s")))
+(defn create-new! [name user-uuid]
+ (->>
+ (neo4j/exec-query
+ create-new
+ {:u_uuid user-uuid
+ :name name
+ :s_uuid (neo4j/uuid)})
+ first
+ :uuid))
diff --git a/src/wanijo/domain/user.clj b/src/wanijo/domain/user.clj
index 4b8bb6c..efe9725 100644
--- a/src/wanijo/domain/user.clj
+++ b/src/wanijo/domain/user.clj
@@ -1,12 +1,16 @@
(ns wanijo.domain.user
(:require [wanijo.neo4j :as neo4j]))
+(neo4j/defquery
+ find-user
+ "MATCH (n:user)
+ WHERE n.ident = {ident}
+ RETURN n")
+
(defn find! [ident]
- (first
- (neo4j/query-rawdata!
- :query
- "MATCH (n:user)
- WHERE n.ident = {ident}
- RETURN n"
- :alias "n"
- :params {:ident ident})))
+ (->>
+ (neo4j/exec-query
+ find-user
+ {:ident ident})
+ first
+ :n))
diff --git a/src/wanijo/neo4j.clj b/src/wanijo/neo4j.clj
index f1b2d7d..250bc05 100644
--- a/src/wanijo/neo4j.clj
+++ b/src/wanijo/neo4j.clj
@@ -1,34 +1,31 @@
(ns wanijo.neo4j
- (:require [clojurewerkz.neocons.rest :as nr]
- [clojurewerkz.neocons.rest.nodes :as nrn]
- [clojurewerkz.neocons.rest.cypher :as cypher]
+ (:require [neo4j-clj.core :as db]
[wanijo.devmode :as devmode]))
(def conn
- (delay (nr/connect "http://neo4j:b@localhost:7474/db/data")))
+ (delay (db/connect
+ "bolt://localhost:7687"
+ "neo4j"
+ "b")))
-(defn conn! []
- @conn)
+(defmacro defquery [& args] `(db/defquery ~@args))
(defn uuid []
(str (java.util.UUID/randomUUID)))
(defn butiful-query [qry]
(->> qry
+ str
clojure.string/trim-newline
clojure.string/split-lines
(map clojure.string/trim)
(filter #(> (count %) 0))
(clojure.string/join \newline)))
-(defn query-rawdata!
- [& {:keys [query alias params]
- :or {params {}}}]
- (devmode/send-to-bar
- (str (butiful-query query)
- "
---Params---
"
- params))
- (->>
- (cypher/tquery (conn!) query params)
- (map #(get % alias))
- (map :data)))
+(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)))
diff --git a/src/wanijo/repl.clj b/src/wanijo/repl.clj
index 28e421e..d955a76 100644
--- a/src/wanijo/repl.clj
+++ b/src/wanijo/repl.clj
@@ -1,17 +1,18 @@
(ns wanijo.repl
- (:require [clojurewerkz.neocons.rest.nodes :as nodes]
- [clojurewerkz.neocons.rest.labels :as labels]
- [clojurewerkz.neocons.rest.cypher :as cypher]
- [buddy.hashers :as hashers]
+ (:require [buddy.hashers :as hashers]
+ [neo4j-clj.core :as db]
[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]
- (cypher/tquery
- (neo4j/conn!)
- "CREATE (n:user)
- SET n.ident = {ident}
- SET n.pw = {pw}
- SET n.uuid = {uuid}"
+ (neo4j/exec-query
+ create-user
{:ident ident
:pw (hashers/derive pw)
:uuid (neo4j/uuid)}))