The clojure-neo4j
project provides a lispy interface to Neo4j, a graph-structured on-disk transactional database.
The latest version, 0.3.0-SNAPSHOT, is available from clojars.
Add [clojure-neo4j "0.3.0-SNAPSHOT"]
to your project's dependency list and fetch with lein deps
.
lein jar
(use '[neo4j.core :exclude [open shutdown]])
(def db (neo4j.core/open "/path/to/db"))
;;; Create a root for customers and add a customer.
(with-tx db
(let [customer-root (new-node db)
bob (new-node db)]
(relate (top-node db) :customers customer-root)
(relate customer-root :customer bob)
(properties bob {"name" "Bob"
"age" 30
"id" "C12345"})))
;;; Fetch all customer IDs
(with-tx db
(let [customer-root (-> (top-node db)
(.getSingleRelationship (relationship :customers) outgoing)
(.getEndNode))]
(doall (map #(property % "id")
(traverse customer-root
breadth-first
(depth-of 1)
all-but-start
{:customer outgoing})))))
(neo4j.core/shutdown db)