Module: Neography::Rest::Transactions

Includes:
Helpers
Included in:
Neography::Rest
Defined in:
lib/neography/rest/transactions.rb

Instance Method Summary collapse

Methods included from Helpers

#encode, #escape, #get_id, #json_content_type, #parse_depth, #parse_direction, #parse_order, #parse_type, #parse_uniqueness

Instance Method Details

#begin_transaction(statements = [], commit = "") ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/neography/rest/transactions.rb', line 6

def begin_transaction(statements = [], commit = "")
  options = {
    :body => (
      convert_cypher(statements)
    ).to_json,
    :headers => json_content_type
  }
  @connection.post("/transaction" + commit, options)
end

#commit_transaction(tx, statements = []) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/neography/rest/transactions.rb', line 30

def commit_transaction(tx, statements = [])
  if (tx.is_a?(Hash) || tx.is_a?(Integer))
    options = {
      :body => (
        convert_cypher(statements)
      ).to_json,
      :headers => json_content_type
    }
    @connection.post("/transaction/%{id}/commit" %  {:id => get_tx_id(tx)}, options)
  else
    begin_transaction(tx, "/commit")
  end
end

#in_transaction(tx, statements = []) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/neography/rest/transactions.rb', line 16

def in_transaction(tx, statements = [])
  options = {
    :body => (
      convert_cypher(statements)
    ).to_json,
    :headers => json_content_type
  }
  @connection.post("/transaction/%{id}" % {:id => get_tx_id(tx)}, options)
end

#keep_transaction(tx) ⇒ Object


26
27
28
# File 'lib/neography/rest/transactions.rb', line 26

def keep_transaction(tx)
  in_transaction(tx)
end

#rollback_transaction(tx) ⇒ Object


44
45
46
# File 'lib/neography/rest/transactions.rb', line 44

def rollback_transaction(tx)
  @connection.delete("/transaction/%{id}" % {:id => get_tx_id(tx)})
end