Skip to content

Commit

Permalink
Added get-many for relationships.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoldar committed Oct 7, 2012
1 parent 860970a commit c13b0c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/clojure/clojurewerkz/neocons/rest/relationships.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions test/clojurewerkz/neocons/rest/test/cypher_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit c13b0c2

Please sign in to comment.