Class: Neo4j::Http::CypherClient

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/http/cypher_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, injected_connection = nil) ⇒ CypherClient

Returns a new instance of CypherClient.



15
16
17
18
# File 'lib/neo4j/http/cypher_client.rb', line 15

def initialize(configuration, injected_connection = nil)
  @configuration = configuration
  @injected_connection = injected_connection
end

Class Method Details

.defaultObject



11
12
13
# File 'lib/neo4j/http/cypher_client.rb', line 11

def self.default
  @default ||= new(Neo4j::Http.config)
end

Instance Method Details

#connection(access_mode) ⇒ Object



43
44
45
# File 'lib/neo4j/http/cypher_client.rb', line 43

def connection(access_mode)
  build_connection(access_mode)
end

#execute_cypher(cypher, parameters = {}) ⇒ Object

Executes a cypher query, passing in the cypher statement, with parameters as an optional hash e.g. Neo4j::Http::Cypherclient.execute_cypher(“MATCH (n { foo: $foo }) LIMIT 1 RETURN n”, { foo: “bar” })



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neo4j/http/cypher_client.rb', line 22

def execute_cypher(cypher, parameters = {})
  # By default the access mode is set to "WRITE", but can be set to "READ"
  # for improved routing performance on read only queries
  access_mode = parameters.delete(:access_mode) || @configuration.access_mode

  request_body = {
    statements: [
      {
        statement: cypher,
        parameters: parameters.as_json
      }
    ]
  }

  @connection = @injected_connection || connection(access_mode)
  response = @connection.post(transaction_path, request_body)
  results = check_errors!(cypher, response, parameters)

  Neo4j::Http::Results.parse(results&.first || {})
end