forked from michaelklishin/neocons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and The ClojureWerkz | ||
;; Team | ||
;; | ||
;; The use and distribution terms for this software are covered by the | ||
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
;; which can be found in the file epl-v10.html at the root of this distribution. | ||
;; By using this software in any fashion, you are agreeing to be bound by | ||
;; the terms of this license. | ||
;; You must not remove this notice, or any other, from this software. | ||
|
||
(ns clojurewerkz.neocons.bolt | ||
(:require [clojure.string :as string]) | ||
(:import (java.util Map) | ||
(org.neo4j.driver.v1 AuthTokens Config Driver | ||
GraphDatabase Record Session | ||
StatementResult Values))) | ||
|
||
(defn- env-var | ||
[^String s] | ||
(get (System/getenv) s)) | ||
|
||
(defn connect | ||
(^Driver [^String url] | ||
(let [login (env-var "NEO4J_LOGIN") | ||
password (env-var "NEO4J_PASSWORD")] | ||
(if (or (string/blank? login) | ||
(string/blank? password)) | ||
(GraphDatabase/driver url) | ||
(connect url login password)))) | ||
(^Driver [^String url ^String username ^String password] | ||
(GraphDatabase/driver url (AuthTokens/basic username password))) | ||
(^Driver [^String url ^String username ^String password ^Config config] | ||
(GraphDatabase/driver url (AuthTokens/basic username password) config))) | ||
|
||
(defn create-session | ||
^Session [^Driver driver] | ||
(.session driver)) | ||
|
||
(defn query | ||
([^Session session ^String qry] | ||
(query session qry {})) | ||
([^Session session ^String qry ^Map params] | ||
(map (fn [^Record r] | ||
(into {} (.asMap r))) | ||
(iterator-seq (.run session qry params))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and The ClojureWerkz | ||
;; Team | ||
;; | ||
;; The use and distribution terms for this software are covered by the | ||
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
;; which can be found in the file epl-v10.html at the root of this distribution. | ||
;; By using this software in any fashion, you are agreeing to be bound by | ||
;; the terms of this license. | ||
;; You must not remove this notice, or any other, from this software. | ||
|
||
(ns clojurewerkz.neocons.bolt.test.bolt-test | ||
(:require [clojurewerkz.neocons.bolt :as neobolt] | ||
[clojure.test :refer :all]) | ||
(:import (java.util Map) | ||
(org.neo4j.driver.v1 Driver Session))) | ||
|
||
(deftest test-connection | ||
(with-open [driver (neobolt/connect "bolt://localhost")] | ||
(is (instance? Driver driver)))) | ||
|
||
(deftest test-session | ||
(with-open [driver (neobolt/connect "bolt://localhost")] | ||
(with-open [session (neobolt/create-session driver)] | ||
(is (instance? Session session))))) | ||
|
||
(deftest test-simple-query | ||
(with-open [driver (neobolt/connect "bolt://localhost")] | ||
(with-open [session (neobolt/create-session driver)] | ||
(let [res (neobolt/query session "CREATE (n {name: {name}}) RETURN n.name AS name;" {"name" "Arthur"})] | ||
(is (= res [{"name" "Arthur"}])))))) |