You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wanijo/src/wanijo/user/db.clj

52 lines
1.2 KiB

(ns wanijo.user.db
(:require [clojure.spec.alpha :as spec]
[wanijo.infra.neo4j :as neo4j]))
(spec/def ::ident
(spec/and string? not-empty))
(spec/def ::name
(spec/or :empty #(or (empty? %) (nil? %))
:given (spec/and string? some?)))
(spec/def ::password
(spec/and string? #(> 7 (count %))))
(neo4j/defquery
find-user
"MATCH (n:user)
WHERE n.ident = $ident
RETURN n")
(defn find! [ident]
(->>
(neo4j/exec-query!
find-user
{:ident ident})
first
:n))
(comment
(macroexpand '(db/defquery test-find-user
"MATCH (u:user) WHERE u.ident = $ident RETURN u"))
(macroexpand '(neo4j/defquery
find-user
"MATCH (n:user) WHERE n.ident = $ident RETURN n"))
(require '[neo4j-clj.core :as db])
(db/defquery test-find-user
"MATCH (u:user) WHERE u.ident = $ident RETURN u")
(with-open [s (db/get-session @neo4j/conn)]
(test-find-user s {:ident "admin"}))
(neo4j/exec-query! test-find-user {:ident "admin"}))
(neo4j/defquery
all
"MATCH (u:user)
RETURN u
ORDER BY u.ident")
(defn all! []
(map :u
(neo4j/exec-query!
all
{})))