Skip to content

Commit

Permalink
fixing transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 19, 2013
1 parent cbbcc22 commit bc22a90
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ It supports indexes, Gremlin scripts, Cypher queries and batch operations.

Some of this functionality is shown here, but all of it is explained in the following Wiki pages:

2.0 Only features:

* [Schema indexes](https://github.com/maxdemarzi/neography/wiki/Schema-indexes) - Create, get and delete schema indexes.
* [Node labels](https://github.com/maxdemarzi/neography/wiki/Node-labels) - Create, get and delete node labels.
* [Transactions](https://github.com/maxdemarzi/neography/wiki/Transactions) - Begin, add to, commit, rollback transactions.

1.8+ features:

* [Nodes](https://github.com/maxdemarzi/neography/wiki/Nodes) - Create, get and delete nodes.
* [Node properties](https://github.com/maxdemarzi/neography/wiki/Node-properties) - Set, get and remove node properties.
* [Node relationships](https://github.com/maxdemarzi/neography/wiki/Node-relationships) - Create and get relationships between nodes.
Expand Down
6 changes: 3 additions & 3 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def keep_transaction(tx)
end

def commit_transaction(tx, statements=[])
if tx.is_a?(Array)
@transactions.begin(tx, "commit")
else
if (tx.is_a?(Hash) || tx.is_a?(Integer))
@transactions.commit(tx, statements)
else
@transactions.begin(tx, "/commit")
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/neography/rest/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def convert_cypher(statements)
query = nil
parameters = nil
Array(statements).each do |statement|
if query & parameters
if query && parameters
array << {:statement => query, :parameters => {:props => parameters}}
query = statement
parameters = nil
elsif query & statement.is_a?(String)
elsif query && statement.is_a?(String)
array << {:statement => query}
query = statement
parameters = nil
elsif query & statement.is_a?(Hash)
elsif query && statement.is_a?(Hash)
array << {:statement => query, :parameters => {:props => parameters}}
query = nil
parameters = nil
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/rest_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@
existing_tx.should have_key("results")
existing_tx["results"].should_not be_empty
end

it "can commit an new transaction right away" do
tx = @neo.commit_transaction(["start n=node(0) return n"])
tx.should_not have_key("transaction")
tx.should have_key("results")
tx["results"].should_not be_empty
end

it "can commit an new transaction right away with parameters" do
tx = @neo.commit_transaction(["start n=node({id}) return n", {:id => 0}])
tx.should_not have_key("transaction")
tx.should have_key("results")
tx["results"].should_not be_empty
end

it "can commit an new transaction right away without parameters" do
tx = @neo.commit_transaction("start n=node(0) return n")
tx.should_not have_key("transaction")
tx.should have_key("results")
tx["results"].should_not be_empty
end

end

describe "rollback a transaction" do
Expand Down

0 comments on commit bc22a90

Please sign in to comment.