Class: Tina4::Drivers::BoltConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/drivers/bolt_graph_driver.rb

Overview

A minimal Bolt 4.4 / PackStream v2 client — just enough to run Cypher with bound parameters and read records back. Not a general Bolt library; it implements exactly the message set the graph layer needs (HELLO, RUN, PULL, RESET, GOODBYE) and the PackStream types Cypher returns.

Defined Under Namespace

Classes: BoltConnectError, BoltError, StringScanner

Constant Summary collapse

NULL =

PackStream markers reused across encode/decode.

0xC0
FALSE =
0xC2
TRUE =
0xC3
FLOAT64 =
0xC1
INT8 =
0xC8
INT16 =
0xC9
INT32 =
0xCA
INT64 =
0xCB
MSG_HELLO =

Bolt request message struct tags.

0x01
MSG_GOODBYE =
0x02
MSG_RESET =
0x0F
MSG_RUN =
0x10
MSG_PULL =
0x3F
MSG_SUCCESS =

Bolt response message struct tags.

0x70
MSG_RECORD =
0x71
MSG_IGNORED =
0x7E
MSG_FAILURE =
0x7F
NODE =

Structure tags for graph values (only meaningful for raw queries that return whole nodes/relationships; the portable core returns decomposed id/labels/props scalars and never hits these).

0x4E
RELATIONSHIP =
0x52
UNBOUND_RELATIONSHIP =
0x72
PATH =
0x50

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, user: nil, password: nil, connect_timeout: nil, use_tls: false) ⇒ BoltConnection

Returns a new instance of BoltConnection.



70
71
72
73
74
75
76
77
78
# File 'lib/tina4/drivers/bolt_graph_driver.rb', line 70

def initialize(host:, port:, user: nil, password: nil, connect_timeout: nil, use_tls: false)
  @host = host
  @port = port
  @user = user
  @password = password
  @connect_timeout = connect_timeout
  @use_tls = use_tls
  connect
end

Instance Method Details

#closeObject



92
93
94
95
96
97
98
99
# File 'lib/tina4/drivers/bolt_graph_driver.rb', line 92

def close
  write_message(MSG_GOODBYE)
  @socket&.close
rescue StandardError
  # closing is best-effort — a dead socket needs no goodbye.
ensure
  @socket = nil
end

#run(cypher, params = nil) ⇒ Object

Run one Cypher statement, PULL all records, return an array of row hashes keyed by the RETURN column names (string keys — parity with the Ultipa driver and the Python master's record.data()).



83
84
85
86
87
88
89
90
# File 'lib/tina4/drivers/bolt_graph_driver.rb', line 83

def run(cypher, params = nil)
  fields = send_run(cypher, params || {})
  records = []
  pull_all do |values|
    records << fields.zip(values).to_h
  end
  records
end