Class: Neo4j::Core::CypherSession::Adaptors::HTTP
- Inherits:
-
Base
- Object
- Base
- Neo4j::Core::CypherSession::Adaptors::HTTP
show all
- Defined in:
- lib/neo4j/core/cypher_session/adaptors/http.rb
Constant Summary
collapse
- ROW_REST =
%w(row REST)
Constants inherited
from Base
Base::EMPTY, Base::NEWLINE_W_SPACES
Instance Method Summary
collapse
Methods inherited from Base
instrument_queries, #queries, #query, #transaction
included
Constructor Details
#initialize(url, _options = {}) ⇒ HTTP
nil, :open_requested, :open, :close_requested
13
14
15
16
17
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 13
def initialize(url, _options = {})
@url = url
@url_components = url_components!(url)
@transaction_state = nil
end
|
Instance Method Details
#connect ⇒ Object
19
20
21
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 19
def connect
@connection ||= connection
end
|
#end_transaction ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 59
def end_transaction
if @transaction_state.nil?
fail 'Cannot close transaction without starting one'
end
@transaction_state = :close_requested
query_set([])
@transaction_state = nil
@transaction_id = nil
true
end
|
#indexes_for_label(label) ⇒ Object
Schema inspection methods
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 82
def indexes_for_label(label)
url = db_data_url + "schema/index/#{label}"
response = @connection.get(url)
if response.body && response.body[0]
response.body[0][:property_keys].map(&:to_sym)
else
[]
end
end
|
#query_set(queries) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 25
def query_set(queries)
fail 'Query attempted without a connection' if @connection.nil?
statements_data = queries.map do |query|
{statement: query.cypher, parameters: query.parameters || {},
resultDataContents: ROW_REST}
end
request_data = {statements: statements_data}
self.class.instrument_queries(queries)
return unless url = full_transaction_url
faraday_response = self.class.instrument_request(url, request_data) do
@connection.post(url, request_data)
end
store_transaction_id!(faraday_response)
Responses::HTTP.new(faraday_response, request_data).results
end
|
#start_transaction ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 48
def start_transaction
case @transaction_state
when :open
return
when :close_requested
fail 'Cannot start transaction when a close has been requested'
end
@transaction_state = :open_requested
end
|
#transaction_started? ⇒ Boolean
73
74
75
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 73
def transaction_started?
!!@transaction_id
end
|
#uniqueness_constraints_for_label(label) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 93
def uniqueness_constraints_for_label(label)
url = db_data_url + "schema/constraint/#{label}/uniqueness"
response = @connection.get(url)
if response.body && response.body[0]
response.body[0][:property_keys].map(&:to_sym)
else
[]
end
end
|
#version ⇒ Object
77
78
79
|
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 77
def version
@version ||= @connection.get(db_data_url).body[:neo4j_version]
end
|