parent
d7947c431a
commit
2b09913ca4
@ -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…
Reference in new issue