replace old param syntax

neo4j-4
Josha von Gizycki 4 years ago
parent 337422ae16
commit 1f42aad23e

1
.gitignore vendored

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

@ -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

@ -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

@ -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

@ -1,7 +1,6 @@
(ns wanijo.user.db (ns wanijo.user.db
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[wanijo.infrastructure.neo4j :as neo4j] [wanijo.infrastructure.neo4j :as neo4j]))
[neo4j-clj.core :as db]))
(spec/def ::ident (spec/def ::ident
(spec/and string? not-empty)) (spec/and string? not-empty))
@ -14,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]
@ -27,14 +26,14 @@
(comment (comment
(macroexpand '(db/defquery test-find-user (macroexpand '(db/defquery test-find-user
"MATCH (u:user) WHERE u.ident = {ident} RETURN u")) "MATCH (u:user) WHERE u.ident = $ident RETURN u"))
(macroexpand '(neo4j/defquery (macroexpand '(neo4j/defquery
find-user find-user
"MATCH (n:user) WHERE n.ident = {ident} RETURN n")) "MATCH (n:user) WHERE n.ident = $ident RETURN n"))
(require '[neo4j-clj.core :as db]) (require '[neo4j-clj.core :as db])
(db/defquery test-find-user (db/defquery test-find-user
"MATCH (u:user) WHERE u.ident = {ident} RETURN u") "MATCH (u:user) WHERE u.ident = $ident RETURN u")
(with-open [s (db/get-session @neo4j/conn)] (with-open [s (db/get-session @neo4j/conn)]
(test-find-user s {:ident "admin"})) (test-find-user s {:ident "admin"}))
(neo4j/exec-query! test-find-user {:ident "admin"})) (neo4j/exec-query! test-find-user {:ident "admin"}))

@ -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