Merge branch 'neo4j-4'

alfred
Josha von Gizycki 4 years ago
commit a52c15649e

3
.gitignore vendored

@ -17,5 +17,4 @@ resources/public/js/out
.rebel_readline_history .rebel_readline_history
/elm-stuff /elm-stuff
*.*~ *.*~
*# *#*
.#*

@ -7,12 +7,12 @@
:dependencies [;;clojure core :dependencies [;;clojure core
[org.clojure/clojure "1.10.1"] [org.clojure/clojure "1.10.1"]
[nrepl "0.7.0"] [nrepl "0.8.3"]
;; static site ;; static site
[compojure "1.6.1"] [compojure "1.6.2"]
[ring/ring-defaults "0.3.2"] [ring/ring-defaults "0.3.2"]
[ring/ring-jetty-adapter "1.8.0" [ring/ring-jetty-adapter "1.8.2"
:exclusions [ring/ring-core :exclusions [ring/ring-core
ring/ring-codec ring/ring-codec
commons-io commons-io
@ -24,29 +24,32 @@
;; compojure uses old transitive dependencies of ring ;; compojure uses old transitive dependencies of ring
;; specifiy them here explicitly so newer versions ;; specifiy them here explicitly so newer versions
;; will be used ;; will be used
[ring/ring-core "1.8.0"] [ring/ring-core "1.8.2"]
[ring/ring-codec "1.1.2"] [ring/ring-codec "1.1.2"]
;; neo4j ;; neo4j
[gorillalabs/neo4j-clj "2.0.1" [gorillalabs/neo4j-clj "4.1.0"]
:exclusions [com.github.ben-manes.caffeine/caffeine]] [org.neo4j.test/neo4j-harness "4.2.1"
;; neo4j-clj 2.0.1 uses version 1.7.2 of neo4j-java-driver :exclusions
;; this seems to be too old because there's a class [com.fasterxml.jackson.core/jackson-core
;; missing, so we use a newer version of the commons-codec]]
;; transitive dependency
[org.neo4j.driver/neo4j-java-driver "4.2.0"]
;; additional server side libs ;; additional server side libs
[buddy/buddy-hashers "1.4.0" [buddy/buddy-hashers "1.7.0"
:exclusions [commons-codec]] :exclusions
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile
com.fasterxml.jackson.dataformat/jackson-dataformat-cbor
com.fasterxml.jackson.core/jackson-core
org.bouncycastle/bcprov-jdk15on
org.bouncycastle/bcpkix-jdk15on
commons-codec
cheshire
tigris]]
[clj-time "0.15.2"] [clj-time "0.15.2"]
[markdown-clj "1.10.1"] [markdown-clj "1.10.5"]
[dorothy "0.0.7"]] [dorothy "0.0.7"]]
:profiles {:dev {:plugins [;; neo4j db :profiles {:dev {:plugins [;; web stuff
[joshavg/lein-neo4j "0.5.0"]
;; web stuff
[lein-less "1.7.5"] [lein-less "1.7.5"]
;; code quality ;; code quality

@ -3,7 +3,7 @@
(neo4j/defquery findy-by-schema (neo4j/defquery findy-by-schema
"MATCH (a:attribute)-->(s:schema) "MATCH (a:attribute)-->(s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
RETURN a RETURN a
ORDER BY a.name") ORDER BY a.name")
(defn find-by-schema! [schema-uuid] (defn find-by-schema! [schema-uuid]
@ -14,8 +14,8 @@
(neo4j/defquery with-name-in-schema (neo4j/defquery with-name-in-schema
"MATCH (a:attribute)-[:of]->(s:schema) "MATCH (a:attribute)-[:of]->(s:schema)
WHERE a.name = {name} WHERE a.name = $name
AND s.uuid = {schema_uuid} AND s.uuid = $schema_uuid
RETURN a") RETURN a")
(defn with-name-in-schema! [matching-name schema-uuid] (defn with-name-in-schema! [matching-name schema-uuid]
(-> (neo4j/exec-query! with-name-in-schema (-> (neo4j/exec-query! with-name-in-schema
@ -25,16 +25,16 @@
:a)) :a))
(neo4j/defquery create-new (neo4j/defquery create-new
"MATCH (s:schema {uuid:{schema_uuid}}), "MATCH (s:schema {uuid: $schema_uuid}),
(u:user {uuid:{user_uuid}}) (u:user {uuid: $user_uuid})
CREATE (a:attribute) CREATE (a:attribute)
CREATE (a)-[:created_by]->(u) CREATE (a)-[:created_by]->(u)
CREATE (a)-[:of]->(s) CREATE (a)-[:of]->(s)
SET a.type = {type} SET a.type = $type
SET a.name = {name} SET a.name = $name
SET a.uuid = {attribute_uuid} SET a.uuid = $attribute_uuid
SET a.required = {required} SET a.required = $required
SET a.created_at = {created_at}") SET a.created_at = $created_at")
(defn create-new! [attr schema-uuid user-uuid] (defn create-new! [attr schema-uuid user-uuid]
(neo4j/exec-query! (neo4j/exec-query!
create-new create-new
@ -46,10 +46,10 @@
(neo4j/defquery edit (neo4j/defquery edit
"MATCH (a:attribute) "MATCH (a:attribute)
WHERE a.uuid = {uuid} WHERE a.uuid = $uuid
SET a.type = {type} SET a.type = $type
SET a.name = {name} SET a.name = $name
SET a.required = {required}") SET a.required = $required")
(defn edit! [attr] (defn edit! [attr]
(neo4j/exec-query! (neo4j/exec-query!
edit edit
@ -57,7 +57,7 @@
(neo4j/defquery delete-by-uuid (neo4j/defquery delete-by-uuid
"MATCH (a:attribute)-[c]-() "MATCH (a:attribute)-[c]-()
WHERE a.uuid = {uuid} WHERE a.uuid = $uuid
DELETE c, a") DELETE c, a")
(defn delete-by-uuid! [uuid] (defn delete-by-uuid! [uuid]
(neo4j/exec-query! (neo4j/exec-query!
@ -65,7 +65,7 @@
{:uuid uuid})) {:uuid uuid}))
(neo4j/defquery required (neo4j/defquery required
"MATCH (a:attribute)-[:of]->(s:schema {uuid:{schema_uuid}}) "MATCH (a:attribute)-[:of]->(s:schema {uuid: $schema_uuid})
WHERE a.required = 1 WHERE a.required = 1
RETURN a RETURN a
ORDER BY a.name") ORDER BY a.name")
@ -84,7 +84,7 @@
first)) first))
(neo4j/defquery find-by-instance (neo4j/defquery find-by-instance
"MATCH (i:instance {uuid:{instance_uuid}}), "MATCH (i:instance {uuid: $instance_uuid}),
(i)-[:of]->(s:schema), (i)-[:of]->(s:schema),
(a:attribute)-[:of]->(s) (a:attribute)-[:of]->(s)
RETURN a RETURN a

@ -1,5 +1,6 @@
(ns wanijo.infrastructure.neo4j (ns wanijo.infrastructure.neo4j
(:require [neo4j-clj.core :as db] (:require [neo4j-clj.core :as db]
[neo4j-clj.in-memory :as db-inm]
[wanijo.infrastructure.devmode :as devmode] [wanijo.infrastructure.devmode :as devmode]
[clj-time.format :as time-format] [clj-time.format :as time-format]
[clj-time.local :as time-local] [clj-time.local :as time-local]
@ -43,6 +44,9 @@
([port host user pass] ([port host user pass]
(reset! conn (create-conn! port host user pass)))) (reset! conn (create-conn! port host user pass))))
(defn in-memory-conn! []
(reset! conn (db-inm/create-in-memory-connection)))
(defmacro defquery [& args] `(db/defquery ~@args)) (defmacro defquery [& args] `(db/defquery ~@args))
(defn uuid [] (defn uuid []
@ -58,14 +62,17 @@
(cljs/join \newline))) (cljs/join \newline)))
(defn exec-query! [qry params] (defn exec-query! [qry params]
(let [live-conn (if (nil? @conn) (let [live-conn (or @conn (reset-conn!))]
(reset-conn!)
@conn)]
(with-open [session (db/get-session live-conn)] (with-open [session (db/get-session live-conn)]
(devmode/send-to-bar (devmode/send-to-bar
(str (butiful-query qry) (str (butiful-query qry)
"<br>---Params---<br>" "<br>---Params---<br>"
params)) params))
;; neo4j-clj returns lazy lists, but when we leave with-open,
;; the ResultSet (?) is already closed, so the list cannot
;; be processed
;; doall to the rescue to force the list to be evaluated
;; eagerly
(doall (qry session params))))) (doall (qry session params)))))
(spec/def ::tuple-query-list (spec/def ::tuple-query-list

@ -5,9 +5,9 @@
(neo4j/defquery create-user (neo4j/defquery create-user
"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] (defn create-user! [ident pw]
(neo4j/exec-query! (neo4j/exec-query!
@ -19,13 +19,13 @@
(neo4j/defquery init-config (neo4j/defquery init-config
"MERGE (c:dbconfig) "MERGE (c:dbconfig)
ON CREATE SET ON CREATE SET
c.installed_at = {now}, c.installed_at = $now,
c.db_version = 0, c.db_version = 0,
c.last_migration = ''") c.last_migration = ''")
(neo4j/defquery merge-config (neo4j/defquery merge-config
"MATCH (c:dbconfig) "MATCH (c:dbconfig)
SET c.last_migration = {now}, SET c.last_migration = $now,
c.db_version = {version}") c.db_version = {version}")
(neo4j/defquery config (neo4j/defquery config
@ -114,8 +114,13 @@
(main/start-server-dev!) (main/start-server-dev!)
(println "Started server at http://localhost:8080")) (println "Started server at http://localhost:8080"))
(defn setup-in-memory! []
(neo4j/in-memory-conn!)
(create-user! "admin" "admin"))
(comment (comment
(dev-server!) (dev-server!)
(setup-in-memory!)
(neo4j/reset-conn! "7688" (neo4j/reset-conn! "7688"
"mokoscha" "mokoscha"
neo4j/standard-user neo4j/standard-user

@ -6,7 +6,7 @@
(neo4j/defquery findy-by-schema (neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema) "MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
OPTIONAL MATCH OPTIONAL MATCH
(i)-[:tagged_with]->(t:tag) (i)-[:tagged_with]->(t:tag)
OPTIONAL MATCH OPTIONAL MATCH
@ -34,21 +34,21 @@
(sort-by :name))) (sort-by :name)))
(neo4j/defquery create-instance (neo4j/defquery create-instance
"MATCH (s:schema {uuid:{schema_uuid}}), "MATCH (s:schema {uuid: $schema_uuid}),
(u:user {uuid:{user_uuid}}) (u:user {uuid: $user_uuid})
CREATE (i:instance {uuid:{uuid}})-[:of]->(s), CREATE (i:instance {uuid: $uuid})-[:of]->(s),
(i)-[:created_by]->(u) (i)-[:created_by]->(u)
SET i.name = {name}, SET i.name = $name,
i.created_at = {created_at}, i.created_at = $created_at,
i.updated_at = {created_at}") i.updated_at = $created_at")
(neo4j/defquery create-property (neo4j/defquery create-property
"MATCH (i:instance {uuid:{uuid}}), "MATCH (i:instance {uuid: $uuid}),
(a:attribute {uuid:{attr_uuid}}) (a:attribute {uuid: $attr_uuid})
CREATE (p:property {uuid:{prop_uuid}})-[:of]->(i), CREATE (p:property {uuid: $prop_uuid})-[:of]->(i),
(p)-[:of]->(a) (p)-[:of]->(a)
SET p.value = {value}, SET p.value = $value,
p.created_at = {created_at}, p.created_at = $created_at,
p.updated_at = {updated_at}") p.updated_at = $updated_at")
(defn create! [user-uuid (defn create! [user-uuid
schema-uuid schema-uuid
{:keys [name properties]}] {:keys [name properties]}]
@ -73,7 +73,7 @@
prop-tuples)))) prop-tuples))))
(neo4j/defquery find-by-uuid (neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema) "MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema)
RETURN i, s") RETURN i, s")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
{:post [(spec/assert ::domain-instance/instance-with-schema %)]} {:post [(spec/assert ::domain-instance/instance-with-schema %)]}
@ -85,7 +85,7 @@
first)) first))
(neo4j/defquery find-properties (neo4j/defquery find-properties
"MATCH (i:instance {uuid:{uuid}}), "MATCH (i:instance {uuid: $uuid}),
(p:property)-[:of]->(i), (p:property)-[:of]->(i),
(p)-[:of]->(a:attribute) (p)-[:of]->(a:attribute)
RETURN p, a RETURN p, a
@ -98,19 +98,19 @@
{:uuid uuid}))) {:uuid uuid})))
(neo4j/defquery edit-instance (neo4j/defquery edit-instance
"MATCH (i:instance {uuid:{uuid}}) "MATCH (i:instance {uuid: $uuid})
SET i.name = {name}, SET i.name = $name,
i.updated_at = {updated_at}") i.updated_at = $updated_at")
(neo4j/defquery edit-property (neo4j/defquery edit-property
"MATCH (i:instance {uuid:{instance_uuid}}), "MATCH (i:instance {uuid: $instance_uuid}),
(a:attribute {uuid:{attribute_uuid}}) (a:attribute {uuid: $attribute_uuid})
MERGE (p:property {uuid:{uuid}})-[:of]->(i) MERGE (p:property {uuid: $uuid})-[:of]->(i)
MERGE (p)-[:of]->(a) MERGE (p)-[:of]->(a)
ON CREATE SET p.created_at = {now}, ON CREATE SET p.created_at = $now,
p.updated_at = {now}, p.updated_at = $now,
p.value = {value} p.value = $value
ON MATCH SET p.updated_at = {now}, ON MATCH SET p.updated_at = $now,
p.value = {value}") p.value = $value")
(defn instance->prop-tuples [instance] (defn instance->prop-tuples [instance]
{:post [(spec/assert ::domain-instance/prop-tuple %)]} {:post [(spec/assert ::domain-instance/prop-tuple %)]}
(map (fn [prop] (map (fn [prop]
@ -135,7 +135,7 @@
prop-tuples)))) prop-tuples))))
(neo4j/defquery delete (neo4j/defquery delete
"MATCH (i:instance {uuid:{uuid}}), "MATCH (i:instance {uuid: $uuid}),
(i)-[ic:of]->(s:schema), (i)-[ic:of]->(s:schema),
(i)-[cb:created_by]->(:user) (i)-[cb:created_by]->(:user)
OPTIONAL MATCH OPTIONAL MATCH
@ -164,7 +164,7 @@
#(-> % direction :created_at))))) #(-> % direction :created_at)))))
(neo4j/defquery outgoing-links (neo4j/defquery outgoing-links
"MATCH (inst:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid: $uuid}),
(inst)-[link:link]->(target:instance), (inst)-[link:link]->(target:instance),
(target)-[:of]->(schema:schema) (target)-[:of]->(schema:schema)
OPTIONAL MATCH OPTIONAL MATCH
@ -175,7 +175,7 @@
(group-by-link-and-assoc-tags uuid outgoing-links :target)) (group-by-link-and-assoc-tags uuid outgoing-links :target))
(neo4j/defquery incoming-links (neo4j/defquery incoming-links
"MATCH (inst:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid: $uuid}),
(inst)<-[link:link]-(source:instance), (inst)<-[link:link]-(source:instance),
(source)-[:of]->(schema:schema) (source)-[:of]->(schema:schema)
OPTIONAL MATCH OPTIONAL MATCH
@ -199,8 +199,8 @@
(db-tag/tags-by-instance! uuid))) (db-tag/tags-by-instance! uuid)))
(neo4j/defquery is-starred (neo4j/defquery is-starred
"MATCH (u:user {uuid:{user_uuid}}), "MATCH (u:user {uuid: $user_uuid}),
(i:instance {uuid:{uuid}}) (i:instance {uuid: $uuid})
RETURN EXISTS((i)-[:starred_by]->(u)) AS starred") RETURN EXISTS((i)-[:starred_by]->(u)) AS starred")
(defn is-starred! [uuid user-uuid] (defn is-starred! [uuid user-uuid]
(-> (neo4j/exec-query! is-starred (-> (neo4j/exec-query! is-starred
@ -210,11 +210,11 @@
:starred)) :starred))
(neo4j/defquery mark-starred (neo4j/defquery mark-starred
"MATCH (i:instance {uuid:{uuid}}), "MATCH (i:instance {uuid: $uuid}),
(u:user {uuid:{user_uuid}}) (u:user {uuid: $user_uuid})
MERGE (i)-[s:starred_by]->(u) MERGE (i)-[s:starred_by]->(u)
ON CREATE ON CREATE
SET s.created_at = {now}") SET s.created_at = $now")
(defn mark-starred! [uuid user-uuid] (defn mark-starred! [uuid user-uuid]
(neo4j/exec-query! mark-starred (neo4j/exec-query! mark-starred
{:uuid uuid {:uuid uuid
@ -222,9 +222,9 @@
:now (neo4j/now-str)})) :now (neo4j/now-str)}))
(neo4j/defquery remove-starred (neo4j/defquery remove-starred
"MATCH (:instance {uuid:{uuid}}) "MATCH (:instance {uuid: $uuid})
-[s:starred_by]-> -[s:starred_by]->
(:user {uuid:{user_uuid}}) (:user {uuid: $user_uuid})
DELETE s") DELETE s")
(defn remove-starred! [uuid user-uuid] (defn remove-starred! [uuid user-uuid]
(neo4j/exec-query! remove-starred (neo4j/exec-query! remove-starred
@ -232,7 +232,7 @@
:user_uuid user-uuid})) :user_uuid user-uuid}))
(neo4j/defquery starred-by-user (neo4j/defquery starred-by-user
"MATCH (u:user {uuid:{user_uuid}}) "MATCH (u:user {uuid: $user_uuid})
<-[s:starred_by]- <-[s:starred_by]-
(i:instance) (i:instance)
RETURN i, s RETURN i, s

@ -140,10 +140,10 @@
(let [names (-> req :params :name) (let [names (-> req :params :name)
instances (-> req :params :instances) instances (-> req :params :instances)
source-uuid (-> req :params :source-uuid)] source-uuid (-> req :params :source-uuid)]
(clojure.pprint/pprint names) ; (clojure.pprint/pprint names)
(clojure.pprint/pprint instances) ; (clojure.pprint/pprint instances)
(clojure.pprint/pprint source-uuid) ; (clojure.pprint/pprint source-uuid)
(clojure.pprint/pprint #_ (clojure.pprint/pprint
(map (fn [[target-schema target-instances]] (map (fn [[target-schema target-instances]]
{:link-name (get names target-schema) {:link-name (get names target-schema)
:instances target-instances}) :instances target-instances})

@ -9,13 +9,13 @@
::name])) ::name]))
(neo4j/defquery create (neo4j/defquery create
"MATCH (i:instance {uuid:{from}}), "MATCH (i:instance {uuid: $from}),
(t:instance {uuid:{target}}) (t:instance {uuid: $target})
CREATE (i)-[l:link]->(t) CREATE (i)-[l:link]->(t)
SET l.created_at = {created_at}, SET l.created_at = $created_at,
l.name = {name}, l.name = $name,
l.created_by = {by}, l.created_by = $by,
l.uuid = {uuid}") l.uuid = $uuid")
(defn create! [{:keys [from name to by]}] (defn create! [{:keys [from name to by]}]
(let [tuples (map (fn [target-uuid] (let [tuples (map (fn [target-uuid]
[create [create

@ -5,7 +5,7 @@
(neo4j/defquery all-created-by (neo4j/defquery all-created-by
"MATCH (s:schema)-[:created_by]->(u:user) "MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.uuid = {uuid} WHERE u.uuid = $uuid
RETURN s RETURN s
ORDER BY s.name") ORDER BY s.name")
(defn all-created-by! [user-uuid] (defn all-created-by! [user-uuid]
@ -24,11 +24,11 @@
(neo4j/defquery create-new (neo4j/defquery create-new
"MATCH (u:user) "MATCH (u:user)
WHERE u.uuid = {u_uuid} WHERE u.uuid = $u_uuid
CREATE (s:schema)-[:created_by]->(u) CREATE (s:schema)-[:created_by]->(u)
SET s.name = {name} SET s.name = $name
SET s.uuid = {s_uuid} SET s.uuid = $s_uuid
SET s.created_at = {created_at} SET s.created_at = $created_at
RETURN s") RETURN s")
(defn create-new! [schema-name user-uuid] (defn create-new! [schema-name user-uuid]
(->> (->>
@ -43,7 +43,7 @@
(neo4j/defquery find-by-uuid (neo4j/defquery find-by-uuid
"MATCH (s:schema) "MATCH (s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
OPTIONAL MATCH OPTIONAL MATCH
(s)<-[:of]-(a:attribute) (s)<-[:of]-(a:attribute)
WHERE a.required = 1 WHERE a.required = 1
@ -60,13 +60,13 @@
:req-attrs (map :a result))))) :req-attrs (map :a result)))))
(neo4j/defquery schema-permissions (neo4j/defquery schema-permissions
"MATCH (s:schema {uuid:{schema_uuid}}) "MATCH (s:schema {uuid: $schema_uuid})
RETURN RETURN
EXISTS((:user {uuid:{user_uuid}}) EXISTS((:user {uuid: $user_uuid})
-[:permission {type:{type}}]- -[:permission {type: $type}]-
(s)) AS user_has_permission, (s)) AS user_has_permission,
NOT EXISTS((:user) NOT EXISTS((:user)
-[:permission {type:{type}}]- -[:permission {type: $type}]-
(s)) AS is_public") (s)) AS is_public")
(defn has-user-permission? [perm-type schema-uuid user-uuid] (defn has-user-permission? [perm-type schema-uuid user-uuid]
(let [perms (first (let [perms (first
@ -82,7 +82,7 @@
(neo4j/defquery accessible-schemas (neo4j/defquery accessible-schemas
"MATCH (s:schema), "MATCH (s:schema),
(u:user {uuid:{user_uuid}}) (u:user {uuid: $user_uuid})
WHERE EXISTS((u)-[:permission {type:'read'}]->(s)) WHERE EXISTS((u)-[:permission {type:'read'}]->(s))
OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s)) OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s))
WITH s WITH s
@ -100,7 +100,7 @@
{:user_uuid user-uuid}))) {:user_uuid user-uuid})))
(neo4j/defquery delete (neo4j/defquery delete
"MATCH (s:schema {uuid:{uuid}}) "MATCH (s:schema {uuid: $uuid})
WITH s WITH s
OPTIONAL MATCH (s)--(a:attribute)-[cb:created_by]-(:user) OPTIONAL MATCH (s)--(a:attribute)-[cb:created_by]-(:user)
DELETE cb, a DELETE cb, a
@ -114,8 +114,8 @@
(neo4j/defquery edit (neo4j/defquery edit
"MATCH (s:schema) "MATCH (s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
SET s.name = {name}") SET s.name = $name")
(defn edit! [schema] (defn edit! [schema]
(neo4j/exec-query! (neo4j/exec-query!
edit edit
@ -123,7 +123,7 @@
(neo4j/defquery assigned-users (neo4j/defquery assigned-users
"MATCH (s:schema)-[p:permission]-(u:user) "MATCH (s:schema)-[p:permission]-(u:user)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
RETURN u, p RETURN u, p
ORDER BY u.ident") ORDER BY u.ident")
(defn assigned-users! [uuid] (defn assigned-users! [uuid]
@ -133,7 +133,7 @@
(neo4j/defquery assigned-schemas (neo4j/defquery assigned-schemas
"MATCH (s1:schema)-[p:permission]-(s2:schema) "MATCH (s1:schema)-[p:permission]-(s2:schema)
WHERE s1.uuid = {uuid} WHERE s1.uuid = $uuid
RETURN s2 RETURN s2
ORDER BY s2.name") ORDER BY s2.name")
(defn assigned-schemas! [uuid] (defn assigned-schemas! [uuid]
@ -157,14 +157,14 @@
(neo4j/defquery remove-assignments (neo4j/defquery remove-assignments
"MATCH (s:schema)-[c:permission]-(:user) "MATCH (s:schema)-[c:permission]-(:user)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
AND c.type = {permtype} AND c.type = $permtype
DELETE c") DELETE c")
(neo4j/defquery create-assignments (neo4j/defquery create-assignments
"MATCH (s:schema), (u:user) "MATCH (s:schema), (u:user)
WHERE s.uuid = {uuid} WHERE s.uuid = $uuid
AND u.uuid IN {users} AND u.uuid IN $users
CREATE (s)<-[:permission{type:{permtype}}]-(u)") CREATE (s)<-[:permission{type: $permtype}]-(u)")
(defn assign-users! [uuid users permission] (defn assign-users! [uuid users permission]
(neo4j/exec-queries! (neo4j/exec-queries!
[remove-assignments [remove-assignments
@ -177,12 +177,12 @@
(neo4j/defquery remove-schema-assignments (neo4j/defquery remove-schema-assignments
"MATCH (s1:schema)-[p:permission]-(s2:schema) "MATCH (s1:schema)-[p:permission]-(s2:schema)
WHERE s1.uuid = {uuid} WHERE s1.uuid = $uuid
DELETE p") DELETE p")
(neo4j/defquery create-schema-assignments (neo4j/defquery create-schema-assignments
"MATCH (s1:schema), (s2:schema) "MATCH (s1:schema), (s2:schema)
WHERE s1.uuid = {uuid} WHERE s1.uuid = $uuid
AND s2.uuid IN {schemas} AND s2.uuid IN $schemas
CREATE (s1)-[:permission]->(s2)") CREATE (s1)-[:permission]->(s2)")
(defn assign-schemas! [uuid schemas] (defn assign-schemas! [uuid schemas]
(neo4j/exec-queries! (neo4j/exec-queries!
@ -192,7 +192,7 @@
{:uuid uuid :schemas schemas}])) {:uuid uuid :schemas schemas}]))
(neo4j/defquery find-by-instance (neo4j/defquery find-by-instance
"MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema) "MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema)
RETURN s") RETURN s")
(defn find-by-instance! [uuid] (defn find-by-instance! [uuid]
(-> find-by-instance (-> find-by-instance

@ -12,7 +12,7 @@
::name])) ::name]))
(neo4j/defquery tags-by-instance (neo4j/defquery tags-by-instance
"MATCH (i:instance {uuid:{uuid}})-[:tagged_with]->(t:tag) "MATCH (i:instance {uuid: $uuid})-[:tagged_with]->(t:tag)
RETURN t RETURN t
ORDER BY t.name") ORDER BY t.name")
(defn tags-by-instance! [instance-uuid] (defn tags-by-instance! [instance-uuid]
@ -22,11 +22,11 @@
{:uuid instance-uuid}))) {:uuid instance-uuid})))
(neo4j/defquery merge-tag (neo4j/defquery merge-tag
"MATCH (i:instance {uuid:{instance_uuid}}), "MATCH (i:instance {uuid: $instance_uuid}),
(u:user {uuid:{user_uuid}}) (u:user {uuid: $user_uuid})
MERGE (t:tag {name:{name}})-[:created_by]->(u) MERGE (t:tag {name: $name})-[:created_by]->(u)
ON CREATE SET t.uuid = {uuid}, ON CREATE SET t.uuid = $uuid,
t.created_at = {now} t.created_at = $now
MERGE (i)-[:tagged_with]->(t)") MERGE (i)-[:tagged_with]->(t)")
(spec/def ::merge-tag-tuple (spec/def ::merge-tag-tuple
(spec/keys :req-un [::specs/instance_uuid (spec/keys :req-un [::specs/instance_uuid
@ -59,9 +59,9 @@
(merge-tag-tuples tags instance-uuid user-uuid))) (merge-tag-tuples tags instance-uuid user-uuid)))
(neo4j/defquery remove-tag (neo4j/defquery remove-tag
"MATCH (i:instance {uuid:{instance_uuid}}) "MATCH (i:instance {uuid: $instance_uuid})
-[c:tagged_with]-> -[c:tagged_with]->
(t:tag {uuid:{uuid}}) (t:tag {uuid: $uuid})
DELETE c") DELETE c")
(defn remove-tag! [uuid instance-uuid] (defn remove-tag! [uuid instance-uuid]
(neo4j/exec-query! remove-tag (neo4j/exec-query! remove-tag

@ -13,7 +13,7 @@
(neo4j/defquery (neo4j/defquery
find-user find-user
"MATCH (n:user) "MATCH (n:user)
WHERE n.ident = {ident} WHERE n.ident = $ident
RETURN n") RETURN n")
(defn find! [ident] (defn find! [ident]
@ -24,6 +24,20 @@
first first
:n)) :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 (neo4j/defquery
all all
"MATCH (u:user) "MATCH (u:user)

@ -27,7 +27,7 @@
(neo4j/defquery search (neo4j/defquery search
"MATCH (i:instance) "MATCH (i:instance)
WHERE i.name =~ {term} WHERE i.name =~ $term
RETURN i RETURN i
LIMIT 10") LIMIT 10")
(defn enrich-links [instance] (defn enrich-links [instance]

Loading…
Cancel
Save