Transactions

Ujjwal Thaakar edited this page Dec 26, 2013 · 8 revisions

Begin a transaction:

@neo.begin_transaction                                     # Begin a transaction
@neo.begin_transaction("start n=node(0) return n")         # Begin a transaction with statements

Keep a transaction alive:

tx = @neo.begin_transaction
@neo.keep_transaction(tx)                                  # Keep a transaction alive (extend timeout)

Add to a transaction:

@neo.in_transaction(tx, "start n=node(0) return n")        # Add a statement to a transaction
@neo.in_transaction(tx, ["start n=node({id}) return n",    # Add a statement to a transaction with 
                         {:id => 0}])                      # parameters 
@neo.in_transaction(tx, ["start n=node({id}) return n",    # Add statements to a transaction with 
                         {:id => 0},                       # parameters
                         "start n=node({id}) return n",     
                         {:id => 1}])                       

Commit a transaction:

@neo.commit_transaction(tx)                                 # Commit a transaction
@neo.commit_transaction("start n=node(0) return n")         # Start and Commit a transaction
@neo.commit_transaction(["start n=node({id}) return n",     # Start and Commit a transaction
                         :id => 0}])                        # with a parameter
@neo.commit_transaction(tx, "start n=node(0) return n")     # Commit a transaction with a new statement
@neo.commit_transaction(tx, ["start n=node({id}) return n", # Commit a transaction with a new statement 
                            {:id => 0}])                    # with parameters 
@neo.commit_transaction(tx, ["start n=node({id}) return n", # Commit a transaction with new statements  
                            {:id => 0},                     # with parameters
                            "start n=node({id}) return n",  
                            {:id => 1}])                     

Rollback a transaction:

@neo.rollback_transaction(tx)                               # Rollback a transaction

Get multiple representations of data from a transaction:

@neo.in_transaction(tx, ["start n=node({id}) return n",    # Add a statement to a transaction with 
                         {:id => 0}, [:graph,:rest,:row]])  # parameters and multiple representations

The default is [:row] which is a very sparse representation. See http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html#rest-api-return-results-in-graph-format for more details.