parent
d7947c431a
commit
2b09913ca4
@ -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))
|
||||
|
@ -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)
|
||||
"<br>---Params---<br>"
|
||||
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)
|
||||
"<br>---Params---<br>"
|
||||
params))
|
||||
(qry session params)))
|
||||
|
@ -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)}))
|
||||
|
Loading…
Reference in new issue