https://github.com/gorillalabs/neo4j-clj
Clojure bindings for Bolt / the Java Neo4j driver, complete with Joplin support for managing database migrations.
https://github.com/gorillalabs/neo4j-clj
bolt clojure neo4j neo4j-driver
Last synced: 7 months ago
JSON representation
Clojure bindings for Bolt / the Java Neo4j driver, complete with Joplin support for managing database migrations.
- Host: GitHub
- URL: https://github.com/gorillalabs/neo4j-clj
- Owner: gorillalabs
- License: mit
- Created: 2017-04-12T12:24:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-26T13:43:42.000Z (9 months ago)
- Last Synced: 2025-05-16T13:05:09.863Z (7 months ago)
- Topics: bolt, clojure, neo4j, neo4j-driver
- Language: Clojure
- Homepage:
- Size: 589 KB
- Stars: 94
- Watchers: 13
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# neo4j-clj
Clojuresque client to Neo4j database, based upon the bolt protocol.
[](https://clojars.org/gorillalabs/neo4j-clj)
[](https://travis-ci.org/gorillalabs/neo4j-clj)
[](https://versions.deps.co/gorillalabs/neo4j-clj)
[](https://versions.deps.co/gorillalabs/neo4j-clj)
neo4j-clj is a clojure client library to the [Neo4j graph database](https://neo4j.com/),
relying on the [Bolt protocol](https://boltprotocol.org/).
## Features
This library provides a clojuresque way to deal with connections, sessions, transactions
and [Cypher](https://www.opencypher.org/) queries.
## Status
neo4j-clj was in active use at our own projects, but not anymore.
It's not a feature complete client library in every possible sense, and it
is not in active development anymore, but only as a hobby project.
You might choose to issue new feature requests,
or clone the repo to add the feature and create a PR.
We appreciate any help on the open source projects we provide. See [Development section](#development) below for more info
on how to build your own version.
## Example usage
Throughout the examples, we assume you're having a Neo4j instance up and running.
See our [Neo4j survival guide](docs/neo4j.md) for help on that.
You can clone our repository and run the [example](example/) for yourself.
```clojure
(ns example.core
(:require [neo4j-clj.core :as db])
(:import (java.net URI)))
(def local-db
(db/connect (URI. "bolt://localhost:7687")
"neo4j"
"YA4jI)Y}D9a+y0sAj]T5s|C5qX!w.T0#u ({:user {...}})
;; Extracted parameters
(db/defquery create-user "CREATE (u:User {name: $name, age: $age})")
(create-user tx {:name "..." :age 42})
(db/defquery get-users "MATCH (u:User) RETURN u.name as name, u.age as age")
(get-users tx)
;; => ({:name "..." :age 42}, ...)
```
-->
#### Return values
The result of a query is a list, even if your query returns a single item. Each "result row" is one map in that sequence
returned.
The values are provided using the ususal Clojure datastructures, no need to wrap/unwrap stuff. That's handled for you by
neo4j-clj.
I'd like to elaborarte a little on the handling of node/edge labels. You can run a query labels like this:
```clojure
(db/defquery get-users "MATCH (u:User) RETURN u as user,labels(u) as labels")
(get-users tx)
```
and this will return a collection of maps with two keys: `user` and `labels` where `labels` are a collection of labels
associated with the nodes. At the moment, `labels` are not sets! It's up to you to convert collections into appropriate
types yourself (because we just do not know on the neo4j-clj level), and this is especially true for `labels`.
## Joplin integration
neo4j-clj comes equipped with support for [Joplin](https://github.com/juxt/joplin)
for datastore migration and seeding.
As we do not force our users into Joplin dependencies, you have to add [joplin.core "0.3.10"]
to your projects dependencies yourself.
## Caveats
Neo4j cannot cope with dashes really well (you need to escape them),
so the Clojure kebab-case style is not really acceptable.
## Development
We appreciate any help on our open source projects. So, feel free to fork and clone this repository.
We use [leiningen](https://leiningen.org/). So, after you've cloned your repo you should be able to run 'lein test' to
run the tests sucessfully.
### Testing
For testing purposes, we provide access to the Neo4j in-memory database feature, which we address using the bolt protocol.
To do so, you need to add a dependency to `[org.neo4j.test/neo4j-harness "4.0.0"]` to your project and require the
`neo4j-clj.in-memory` namespace.
```clojure
(def test-db
(neo4j-clj.in-memory/create-in-memory-connection))
;; instead of (neo4j/connect url user password)
```
So, you can easily run tests on your stuff without requiring an external database.