class Neo4j::Core::CypherSession::Responses::Bolt
Attributes
result_info[R]
results[R]
Public Class Methods
new(queries, flush_messages_proc, options = {})
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 11 def initialize(queries, flush_messages_proc, options = {}) 12 @wrap_level = options[:wrap_level] || Neo4j::Core::Config.wrapping_level 13 14 @results = queries.map do 15 fields, result_messages, _footer_messages = extract_message_groups(flush_messages_proc) 16 # @result_info = footer_messages[0].args[0] 17 18 data = result_messages.map do |result_message| 19 validate_message_type!(result_message, :record) 20 21 result_message.args[0] 22 end 23 24 result_from_data(fields, data) 25 end 26 end
Public Instance Methods
result_from_data(columns, entities_data)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 28 def result_from_data(columns, entities_data) 29 rows = entities_data.map do |entity_data| 30 wrap_entity(entity_data) 31 end 32 33 Result.new(columns, rows) 34 end
wrap_entity(entity_data)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 36 def wrap_entity(entity_data) 37 case entity_data 38 when Array 39 entity_data.map(&method(:wrap_entity)) 40 when PackStream::Structure 41 wrap_structure(entity_data) 42 when Hash 43 entity_data.each_with_object({}) do |(k, v), result| 44 result[k.to_sym] = wrap_entity(v) 45 end 46 else 47 entity_data 48 end 49 end
Private Instance Methods
extract_message_groups(flush_messages_proc)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 53 def extract_message_groups(flush_messages_proc) 54 fields_messages = flush_messages_proc.call 55 56 validate_message_type!(fields_messages[0], :success) 57 58 result_messages = [] 59 messages = nil 60 61 loop do 62 messages = flush_messages_proc.call 63 next if messages.nil? 64 break if messages[0].type == :success 65 result_messages.concat(messages) 66 end 67 68 [fields_messages[0].args[0]['fields'], 69 result_messages, 70 messages] 71 end
validate_message_type!(message, type)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 109 def validate_message_type!(message, type) 110 case message.type 111 when type 112 nil 113 when :failure 114 data = message.args[0] 115 throw :cypher_bolt_failure, data 116 else 117 fail "Unexpected message type: #{message.type} (#{message.inspect})" 118 end 119 end
wrap_direction(_direction_int)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 105 def wrap_direction(_direction_int) 106 '' 107 end
wrap_node(id, labels, properties)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 84 def wrap_node(id, labels, properties) 85 wrap_by_level(properties) { ::Neo4j::Core::Node.new(id, labels, properties) } 86 end
wrap_path(nodes, relationships, directions)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 96 def wrap_path(nodes, relationships, directions) 97 none_value = nodes.zip(relationships).flatten.compact.map { |obj| obj.list.last } 98 wrap_by_level(none_value) do 99 ::Neo4j::Core::Path.new(nodes.map(&method(:wrap_entity)), 100 relationships.map(&method(:wrap_entity)), 101 directions.map(&method(:wrap_direction))) 102 end 103 end
wrap_relationship(id, from_node_id, to_node_id, type, properties)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 88 def wrap_relationship(id, from_node_id, to_node_id, type, properties) 89 wrap_by_level(properties) { ::Neo4j::Core::Relationship.new(id, type, properties, from_node_id, to_node_id) } 90 end
wrap_structure(structure)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 73 def wrap_structure(structure) 74 case structure.signature 75 when 0x4E then wrap_node(*structure.list) 76 when 0x52 then wrap_relationship(*structure.list) 77 when 0x72 then wrap_unbound_relationship(*structure.list) 78 when 0x50 then wrap_path(*structure.list) 79 else 80 fail CypherError, "Unsupported structure signature: #{structure.signature}" 81 end 82 end
wrap_unbound_relationship(id, type, properties)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/bolt.rb 92 def wrap_unbound_relationship(id, type, properties) 93 wrap_by_level(properties) { ::Neo4j::Core::Relationship.new(id, type, properties) } 94 end