use*_*914 7 clojure neo4j cypher
对clojure和neo4j都是新手我确信我错过了Neocons库的重点,但我找不到一种合理的方法来混合库的"本机"函数,如节点/更新与从cypher返回的结果/ TQuery的.
通过node/create在neo4j中创建节点返回:
clojurewerkz.neocons.rest.records.Node{:id 999,
:location-uri http://localhost:7474/db/data/node/999,
:data {:url http://clojureneo4j.info :color "blue"},
:relationships-uri nil,
:create-relationship-uri http://localhost:7474/db/data/node/999/relationships}
Run Code Online (Sandbox Code Playgroud)
node/find"使用索引查找节点".但在这种情况下,我没有设置一个,我可能在将来不知道节点的ID.所以我求助于Cypher通过其他属性找到节点(在这种情况下,为了参数,它的id):
(clojurewerkz.neocons.rest.cypher/tquery conn "MATCH (n) WHERE id(n) = 999 RETURN n")
Run Code Online (Sandbox Code Playgroud)
哪个回报
({"n"
{:properties "http://localhost:7474/db/data/node/999/properties",
:create_relationship
"http://localhost:7474/db/data/node/999/relationships",
:labels "http://localhost:7474/db/data/node/999/labels",
:incoming_relationships
"http://localhost:7474/db/data/node/999/relationships/in",
:outgoing_relationships
"http://localhost:7474/db/data/node/999/relationships/out",
:property "http://localhost:7474/db/data/node/999/properties/{key}",
:paged_traverse
"http://localhost:7474/db/data/node/999/paged/traverse/{returnType}{?pageSize,leaseTime}",
:incoming_typed_relationships
"http://localhost:7474/db/data/node/999/relationships/in/{-list|&|types}",
:traverse
"http://localhost:7474/db/data/node/999/traverse/{returnType}",
:all_relationships
"http://localhost:7474/db/data/node/999/relationships/all",
:extensions {},
:outgoing_typed_relationships
"http://localhost:7474/db/data/node/999/relationships/out/{-list|&|types}",
:metadata {:id 999, :labels []},
:all_typed_relationships
"http://localhost:7474/db/data/node/999/relationships/all/{-list|&|types}",
:self "http://localhost:7474/db/data/node/999",
:data {:domain "clojureneo4j.info" :color "blue"}}})
Run Code Online (Sandbox Code Playgroud)
现在,如果我想更新此找到的节点的"color"属性,那么我必须对结果进行解构以从其获取其id:metadata,并且我必须从以下元素中重新提供所有旧属性:元数据以使它们成为保留以及新的关联颜色值.就像是:
(node/update conn (:id (:metadata node)) (assoc (:data node) :color "green"))
Run Code Online (Sandbox Code Playgroud)
(这可能不完全正确,但我不会坐在一个repl.希望它得到了重点.)
我错过了一些明显的东西吗 在Cypher查询中混合时,或者当我没有索引或节点的ID被归档时,我应该如何轻松地检索和更新节点?我不应该能够将新值与Cypher查询结果相关联并将其交还给节点/更新吗?
谢谢!