Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added get-many for relationships.

  • Loading branch information...
commit c13b0c2ce6e8615b8ccbd675b6e836595a3bb0b0 1 parent 860970a
@zoldar zoldar authored
View
10 src/clojure/clojurewerkz/neocons/rest/relationships.clj
@@ -2,6 +2,7 @@
(:refer-clojure :exclude [get find])
(:require [cheshire.custom :as json]
[clojurewerkz.neocons.rest :as rest]
+ [clojurewerkz.neocons.rest.cypher :as cypher]
[clojurewerkz.neocons.rest.paths :as paths])
(:use clojurewerkz.support.http.statuses
clojurewerkz.neocons.rest.helpers
@@ -110,6 +111,15 @@
nil
(instantiate-rel-from payload id))))
+(defn get-many
+ "Fetches multiple relationships by id.
+
+ This is a non-standard operation that requires Cypher support as well as support for that very feature
+ by Cypher itself (Neo4j Server versions 1.6.3 and later)."
+ ([coll]
+ (let [{:keys [data]} (cypher/query "START x = relationship({ids}) RETURN x" {:ids coll})]
+ (map (comp instantiate-rel-from first) data))))
+
(defn delete
"Deletes relationship by id"
[rel]
View
9 test/clojurewerkz/neocons/rest/test/cypher_test.clj
@@ -75,6 +75,15 @@
ids (vec (map :id [sarah john]))]
(is (= ids (vec (map :id (nodes/get-many ids)))))))
+(deftest ^{:cypher true} test-cypher-query-example6
+ (let [john (nodes/create { :name "John" })
+ sarah (nodes/create { :name "Sarah" })
+ tim (nodes/create { :name "Tim" })
+ rel1 (rel/create john sarah :friend)
+ rel2 (rel/create sarah tim :friend)
+ ids (vec (map :id [rel1 rel2]))]
+ (is (= ids (vec (map :id (rel/get-many ids)))))))
+
(deftest ^{:cypher true} test-cypher-tquery
(let [john (nodes/create { :name "John" :age 27 })
sarah (nodes/create { :name "Sarah" :age 28 })
Please sign in to comment.
Something went wrong with that request. Please try again.