Module: Legion::Extensions::Neo4j::Runners::Transactions
- Includes:
- Helpers::Lex, Helpers::Client
- Included in:
- Client
- Defined in:
- lib/legion/extensions/neo4j/runners/transactions.rb
Instance Method Summary collapse
- #begin_transaction(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
- #commit_transaction(transaction_url:, url: nil, username: nil, password: nil) ⇒ Object
- #execute_in_transaction(transaction_url:, statements:, url: nil, username: nil, password: nil) ⇒ Object
- #rollback_transaction(transaction_url:, url: nil, username: nil, password: nil) ⇒ Object
Methods included from Helpers::Client
Instance Method Details
#begin_transaction(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/legion/extensions/neo4j/runners/transactions.rb', line 12 def begin_transaction(database: 'neo4j', url: nil, username: nil, password: nil, **) resp = connection(url: url, username: username, password: password) .post("/db/#{database}/tx", { statements: [] }) location = resp.headers&.[]('location') { body: resp.body, location: location } end |
#commit_transaction(transaction_url:, url: nil, username: nil, password: nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/neo4j/runners/transactions.rb', line 37 def commit_transaction(transaction_url:, url: nil, username: nil, password: nil, **) resp = connection(url: url, username: username, password: password) .post("#{transaction_url}/commit", { statements: [] }) body = resp.body raise CypherError, body[:errors].map { |e| e['message'] }.join('; ') if body.is_a?(Hash) && body[:errors] && !body[:errors].empty? body end |
#execute_in_transaction(transaction_url:, statements:, url: nil, username: nil, password: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/legion/extensions/neo4j/runners/transactions.rb', line 19 def execute_in_transaction(transaction_url:, statements:, url: nil, username: nil, password: nil, **) payload = { statements: statements.map do |s| if s.is_a?(String) { statement: s, parameters: {} } else { statement: s[:statement], parameters: s[:parameters] || {} } end end } resp = connection(url: url, username: username, password: password) .post(transaction_url, payload) body = resp.body raise CypherError, body[:errors].map { |e| e['message'] }.join('; ') if body.is_a?(Hash) && body[:errors] && !body[:errors].empty? body end |
#rollback_transaction(transaction_url:, url: nil, username: nil, password: nil) ⇒ Object
46 47 48 |
# File 'lib/legion/extensions/neo4j/runners/transactions.rb', line 46 def rollback_transaction(transaction_url:, url: nil, username: nil, password: nil, **) connection(url: url, username: username, password: password).delete(transaction_url) end |