Class: Neo4j::Core::CypherSession::Adaptors::Bolt

Inherits:
Base
  • Object
show all
Includes:
HasUri
Defined in:
lib/neo4j/core/cypher_session/adaptors/bolt.rb

Defined Under Namespace

Classes: Job, Message

Constant Summary collapse

SUPPORTED_VERSIONS =
[1, 0, 0, 0].freeze
VERSION =
'0.0.1'.freeze

Constants inherited from Base

Neo4j::Core::CypherSession::Adaptors::Base::EMPTY, Neo4j::Core::CypherSession::Adaptors::Base::NEWLINE_W_SPACES, Neo4j::Core::CypherSession::Adaptors::Base::USER_AGENT_STRING

Instance Attribute Summary

Attributes inherited from Base

#wrap_level

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasUri

#url, #url=

Methods inherited from Base

instrument_queries, #logger, #queries, #query, #setup_queries!, #transaction

Methods included from Instrumentable

included

Constructor Details

#initialize(url, options = {}) ⇒ Bolt

Returns a new instance of Bolt.



23
24
25
26
27
28
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 23

def initialize(url, options = {})
  self.url = url
  @options = options

  open_socket
end

Class Method Details

.transaction_classObject



82
83
84
85
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 82

def self.transaction_class
  require 'neo4j/core/cypher_session/transactions/bolt'
  Neo4j::Core::CypherSession::Transactions::Bolt
end

Instance Method Details

#connectObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 30

def connect
  handshake

  init

  message = flush_messages[0]
  return if message.type == :success

  data = message.args[0]
  fail "Init did not complete successfully\n\n#{data['code']}\n#{data['message']}"
end

#connected?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 60

def connected?
  !!@socket
end

#constraints(session) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 73

def constraints(session)
  result = query(session, 'CALL db.indexes()', {}, skip_instrumentation: true)

  result.select { |row| row.type == 'node_unique_property' }.map do |row|
    label, property = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)[1, 2]
    {type: :uniqueness, label: label.to_sym, properties: [property.to_sym]}
  end
end

#indexes(session) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 64

def indexes(session)
  result = query(session, 'CALL db.indexes()', {}, skip_instrumentation: true)

  result.map do |row|
    label, property = row.description.match(/INDEX ON :([^\(]+)\(([^\)]+)\)/)[1, 2]
    {type: row.type.to_sym, label: label.to_sym, properties: [property.to_sym], state: row.state.to_sym}
  end
end

#query_set(transaction, queries, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 42

def query_set(transaction, queries, options = {})
  setup_queries!(queries, transaction, skip_instrumentation: options[:skip_instrumentation])

  if @socket.ready?
    debug_remaining_buffer
    fail "Making query, but expected there to be no buffer remaining!\n"\
         "Queries: #{queries.map(&:cypher)}"
  end

  send_query_jobs(queries)

  build_response(queries, options[:wrap_level] || @options[:wrap_level])
end

#versionObject



56
57
58
# File 'lib/neo4j/core/cypher_session/adaptors/bolt.rb', line 56

def version
  fail 'should be implemented!'
end