Trouble creating via with-transaction.

17 views
Skip to first unread message

Raymond Pendergraph

unread,
Dec 29, 2015, 3:26:06 PM12/29/15
to clojure-neo4j
I'm trying to figure out what I'm doing wrong. This is similar to the code in the documentation but can't seem to get it to work. There are no exceptions and the response code is 200 but nothing is getting added to the DB and only the transaction record is returned. 
This is using Clojure 1.7 and neocons 3.1.0-beta3

Is there anything wrong with this code?

(require
 
'[clojurewerkz.neocons.rest :as neo-rest]
  '
[clojurewerkz.neocons.rest.transaction :as tx]
 
'[clojurewerkz.neocons.rest.cypher :as cypher])

(def NEO4J_HOST "http://192.168.99.100:7474/db/data/")
(def NEO4J_USER "neo4j")
(def NEO4J_PASSWORD "password")

(defn single-cypher
   ([query]
     (single-cypher query nil))
   ([query parameters]
     (let [connection  (neo-rest/connect NEO4J_HOST NEO4J_USER NEO4J_PASSWORD)
           transaction (tx/begin-tx connection)
           statement   (tx/statement query nil)]
       (tx/with-transaction
        connection
        transaction
        true
        (tx/execute connection transaction statement)))))

Here is the query:

(single-cypher "CREATE (n) RETURN ID(n)")
=>
[{:commit "http://192.168.99.100:7474/db/data/transaction/129/commit",
 
:location "http://192.168.99.100:7474/db/data/transaction/129",
 
:expires "Tue, 29 Dec 2015 20:14:25 +0000"}
 
()]


Raymond Pendergraph

unread,
Dec 29, 2015, 3:46:41 PM12/29/15
to clojure-neo4j
I caught the hard coded nil in the statement assignment after I posted, that is an issue from playing around but it is not the issue.

Rohit Aggarwal

unread,
Dec 29, 2015, 4:44:35 PM12/29/15
to clojure-neo4j
Hi Raymond, 
I think the issue may be that tx/execute expects a list (of cypher statements) whereas you are passing it a cypher statement. Could you try changing your code to:

(tx/execute connection transaction [statement])

-Rohit

Raymond Pendergraph

unread,
Dec 29, 2015, 7:05:49 PM12/29/15
to clojure-neo4j
Yes that fixed it. I completely overlooked the vector. Thank you. 

Rohit Aggarwal

unread,
Dec 30, 2015, 4:38:27 AM12/30/15
to clojure-neo4j
Thats great!

cheers
Rohit
Reply all
Reply to author
Forward
0 new messages