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]))
|
||||||
|
|
||||||
(defn find! [ident]
|
(neo4j/defquery
|
||||||
(first
|
find-user
|
||||||
(neo4j/query-rawdata!
|
|
||||||
:query
|
|
||||||
"MATCH (n:user)
|
"MATCH (n:user)
|
||||||
WHERE n.ident = {ident}
|
WHERE n.ident = {ident}
|
||||||
RETURN n"
|
RETURN n")
|
||||||
:alias "n"
|
|
||||||
:params {:ident ident})))
|
(defn find! [ident]
|
||||||
|
(->>
|
||||||
|
(neo4j/exec-query
|
||||||
|
find-user
|
||||||
|
{:ident ident})
|
||||||
|
first
|
||||||
|
:n))
|
||||||
|
@ -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 query)
|
(str (butiful-query qry)
|
||||||
"<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]))
|
||||||
|
|
||||||
(defn create-user! [ident pw]
|
(db/defquery
|
||||||
(cypher/tquery
|
create-user
|
||||||
(neo4j/conn!)
|
|
||||||
"CREATE (n:user)
|
"CREATE (n:user)
|
||||||
SET n.ident = {ident}
|
SET n.ident = {ident}
|
||||||
SET n.pw = {pw}
|
SET n.pw = {pw}
|
||||||
SET n.uuid = {uuid}"
|
SET n.uuid = {uuid}")
|
||||||
|
|
||||||
|
(defn create-user! [ident pw]
|
||||||
|
(neo4j/exec-query
|
||||||
|
create-user
|
||||||
{:ident ident
|
{:ident ident
|
||||||
:pw (hashers/derive pw)
|
:pw (hashers/derive pw)
|
||||||
:uuid (neo4j/uuid)}))
|
:uuid (neo4j/uuid)}))
|
||||||
|
Loading…
Reference in new issue