neo4j-ruby-driver 5.7.0.alpha.4 → 5.7.0.alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +440 -40
- data/lib/neo4j/driver/{auto_closable.rb → auto_closeable.rb} +6 -6
- data/lib/neo4j/driver/internal/deprecator.rb +15 -0
- data/ruby/neo4j/driver/graph_database.rb +2 -2
- data/ruby/neo4j/driver/internal/delegating_transaction.rb +13 -0
- data/ruby/neo4j/driver/internal/eager_result_value.rb +5 -0
- data/ruby/neo4j/driver/internal/handlers/pulln/auto_pull_response_handler.rb +3 -2
- data/ruby/neo4j/driver/internal/internal_driver.rb +11 -2
- data/ruby/neo4j/driver/internal/internal_session.rb +16 -2
- data/ruby/neo4j/driver/version.rb +1 -1
- data/ruby/neo4j/driver.rb +2 -0
- metadata +39 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94eddb6ca44c911e72bc498048e91e3f3200147c67fe10b3a828d14ecce2bf7f
|
|
4
|
+
data.tar.gz: fcc696515c9fb11bd4581cb057b875e727e81cc0e61f0b688adbf3b4da1930a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d20a99580348b5313e5854cc6501dce13f0c09d92232faac3004b330cc64a97574d5b6ff0ff979ab24bc4c635e05b6c503ed901eb57d8f08469bec461e6a8528
|
|
7
|
+
data.tar.gz: 4e0da2ae6afefb5590752642c7a707071ac6f09c1f15492d5e31afaa88f084ff1ebd88a619d1a64ae4dd91ef0c1ddbf49754f3a73fed0a59ef305d87a98186f0
|
data/README.md
CHANGED
|
@@ -1,12 +1,50 @@
|
|
|
1
|
-
# Neo4j
|
|
1
|
+
# Neo4j Ruby Driver
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This repository contains 2 implementation of a Neo4j driver for Ruby:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
- pure ruby implmementation. Available on all ruby versions >= 3.1.
|
|
5
|
+
- based on official Java implementation. It provides a thin wrapper over the Java driver (only on jruby).
|
|
6
|
+
- pure Ruby implementation. Available on all Ruby versions >= 3.1.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
Network communication is handled using [Bolt Protocol](https://7687.org/).
|
|
9
|
+
|
|
10
|
+
<details>
|
|
11
|
+
<summary>Table of Contents</summary>
|
|
12
|
+
|
|
13
|
+
* [Getting started](#getting-started)
|
|
14
|
+
* [Installation](#installation)
|
|
15
|
+
* [Getting a Neo4j instance](#getting-a-neo4j-instance)
|
|
16
|
+
* [Quick start example](#quick-start-example)
|
|
17
|
+
* [Server Compatibility](#server-compatibility)
|
|
18
|
+
* [Usage](#usage)
|
|
19
|
+
* [Connecting to a database](#connecting-to-a-database)
|
|
20
|
+
* [URI schemes](#uri-schemes)
|
|
21
|
+
* [Authentication](#authentication)
|
|
22
|
+
* [Configuration](#configuration)
|
|
23
|
+
* [Connectivity check](#connectivity-check)
|
|
24
|
+
* [Sessions & transactions](#sessions--transactions)
|
|
25
|
+
* [Session](#session)
|
|
26
|
+
* [Auto-commit transactions](#auto-commit-transactions)
|
|
27
|
+
* [Explicit transactions](#explicit-transactions)
|
|
28
|
+
* [Read transactions](#read-transactions)
|
|
29
|
+
* [Write transactions](#write-transactions)
|
|
30
|
+
* [Working with results](#working-with-results)
|
|
31
|
+
* [Accessing Node and Relationship data](#accessing-node-and-relationship-data)
|
|
32
|
+
* [Working with Paths](#working-with-paths)
|
|
33
|
+
* [Working with temporal types](#working-with-temporal-types)
|
|
34
|
+
* [Type mapping](#type-mapping)
|
|
35
|
+
* [Advanced](#advanced)
|
|
36
|
+
* [Connection pooling](#connection-pooling)
|
|
37
|
+
* [Logging](#logging)
|
|
38
|
+
* [For Driver Engineers](#for-driver-engineers)
|
|
39
|
+
* [Testing](#testing)
|
|
40
|
+
* [Contributing](#contributing)
|
|
41
|
+
* [License](#license)
|
|
42
|
+
|
|
43
|
+
</details>
|
|
44
|
+
|
|
45
|
+
## Getting started
|
|
46
|
+
|
|
47
|
+
### Installation
|
|
10
48
|
|
|
11
49
|
Add this line to your application's Gemfile:
|
|
12
50
|
|
|
@@ -16,68 +54,430 @@ gem 'neo4j-ruby-driver'
|
|
|
16
54
|
|
|
17
55
|
And then execute:
|
|
18
56
|
|
|
19
|
-
|
|
57
|
+
```bash
|
|
58
|
+
bundle install
|
|
59
|
+
```
|
|
20
60
|
|
|
21
61
|
Or install it yourself as:
|
|
22
62
|
|
|
23
|
-
|
|
63
|
+
```bash
|
|
64
|
+
gem install neo4j-ruby-driver
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Getting a Neo4j instance
|
|
68
|
+
|
|
69
|
+
You need a running Neo4j database in order to use the driver with it. The easiest way to spin up a **local instance** is
|
|
70
|
+
through a Docker container.
|
|
71
|
+
|
|
72
|
+
The command below runs the latest Neo4j version in Docker, setting the admin username and password to `neo4j` and
|
|
73
|
+
`password` respectively:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
docker run \
|
|
77
|
+
-p7474:7474 \
|
|
78
|
+
-p7687:7687 \
|
|
79
|
+
-d \
|
|
80
|
+
-e NEO4J_AUTH=neo4j/password \
|
|
81
|
+
neo4j:latest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Quick start example
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
require 'neo4j/driver'
|
|
88
|
+
|
|
89
|
+
Neo4j::Driver::GraphDatabase.driver(
|
|
90
|
+
'bolt://localhost:7687',
|
|
91
|
+
Neo4j::Driver::AuthTokens.basic('neo4j', 'password')
|
|
92
|
+
) do |driver|
|
|
93
|
+
driver.session(database: 'neo4j') do |session|
|
|
94
|
+
query_result = session.run('RETURN 2+2 AS value')
|
|
95
|
+
puts "2+2 equals #{query_result.single['value']}"
|
|
96
|
+
|
|
97
|
+
# consume gives the execution summary
|
|
98
|
+
create_result = session.run('CREATE (n)').consume
|
|
99
|
+
puts "Nodes created: #{create_result.counters.nodes_created}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
```
|
|
24
103
|
|
|
25
104
|
## Server Compatibility
|
|
26
105
|
|
|
27
|
-
The compatibility with Neo4j Server versions is documented in
|
|
106
|
+
The compatibility with Neo4j Server versions is documented in
|
|
107
|
+
the [Neo4j Knowledge Base](https://neo4j.com/developer/kb/neo4j-supported-versions/).
|
|
28
108
|
|
|
29
109
|
## Usage
|
|
30
110
|
|
|
31
|
-
The API is to highest possible degree consistent with the official
|
|
32
|
-
|
|
111
|
+
The API is to highest possible degree consistent with the official Java driver. Please refer to
|
|
112
|
+
the [Neo4j Java Driver Manual](https://neo4j.com/docs/java-manual/current/), [examples in Ruby](https://github.com/neo4jrb/neo4j-ruby-driver/blob/master/docs/dev_manual_examples.rb),
|
|
113
|
+
and code snippets below to understand how to use it.
|
|
114
|
+
[Neo4j Java Driver API Docs](https://neo4j.com/docs/api/java-driver/current/) can be helpful as well.
|
|
115
|
+
|
|
116
|
+
### Connecting to a database
|
|
117
|
+
|
|
118
|
+
#### URI schemes
|
|
119
|
+
|
|
120
|
+
The driver supports the following URI schemes:
|
|
121
|
+
|
|
122
|
+
| URI Scheme | Description |
|
|
123
|
+
|----------------|---------------------------------------------------------------------------------|
|
|
124
|
+
| `neo4j://` | Connect using routing to a cluster/causal cluster. |
|
|
125
|
+
| `neo4j+s://` | Same as `neo4j://` but with full TLS encryption. |
|
|
126
|
+
| `neo4j+ssc://` | Same as `neo4j://` but with full TLS encryption, without hostname verification. |
|
|
127
|
+
| `bolt://` | Connect directly to a server using the Bolt protocol. |
|
|
128
|
+
| `bolt+s://` | Same as `bolt://` but with full TLS encryption. |
|
|
129
|
+
| `bolt+ssc://` | Same as `bolt://` but with full TLS encryption, without hostname verification. |
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
# Connect to a single instance
|
|
135
|
+
driver = Neo4j::Driver::GraphDatabase.driver(
|
|
136
|
+
'bolt://localhost:7687',
|
|
137
|
+
Neo4j::Driver::AuthTokens.basic('neo4j', 'password')
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Connect to a cluster
|
|
141
|
+
driver = Neo4j::Driver::GraphDatabase.driver(
|
|
142
|
+
'neo4j://graph.example.com:7687',
|
|
143
|
+
Neo4j::Driver::AuthTokens.basic('neo4j', 'password')
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Authentication
|
|
148
|
+
|
|
149
|
+
The driver provides multiple authentication methods:
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
# Basic authentication
|
|
153
|
+
auth = Neo4j::Driver::AuthTokens.basic('neo4j', 'password')
|
|
154
|
+
|
|
155
|
+
# With realm specification
|
|
156
|
+
auth = Neo4j::Driver::AuthTokens.basic('neo4j', 'password', 'realm')
|
|
157
|
+
|
|
158
|
+
# Kerberos authentication
|
|
159
|
+
auth = Neo4j::Driver::AuthTokens.kerberos('ticket')
|
|
160
|
+
|
|
161
|
+
# Bearer authentication
|
|
162
|
+
auth = Neo4j::Driver::AuthTokens.bearer('token')
|
|
163
|
+
|
|
164
|
+
# Custom authentication
|
|
165
|
+
auth = Neo4j::Driver::AuthTokens.custom('principal', 'credentials', 'realm', 'scheme')
|
|
166
|
+
|
|
167
|
+
# No authentication
|
|
168
|
+
auth = Neo4j::Driver::AuthTokens.none
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Configuration
|
|
172
|
+
|
|
173
|
+
You can configure the driver with additional options:
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
config = {
|
|
177
|
+
connection_timeout: 15.seconds,
|
|
178
|
+
connection_acquisition_timeout: 1.minute,
|
|
179
|
+
max_transaction_retry_time: 30.seconds,
|
|
180
|
+
encryption: true,
|
|
181
|
+
trust_strategy: :trust_all_certificates
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
driver = Neo4j::Driver::GraphDatabase.driver(
|
|
185
|
+
'neo4j://localhost:7687',
|
|
186
|
+
Neo4j::Driver::AuthTokens.basic('neo4j', 'password'),
|
|
187
|
+
**config
|
|
188
|
+
)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Connectivity check
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
194
|
+
if driver.verify_connectivity
|
|
195
|
+
puts "Driver is connected to the database"
|
|
196
|
+
else
|
|
197
|
+
puts "Driver cannot connect to the database"
|
|
198
|
+
end
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Sessions & transactions
|
|
202
|
+
|
|
203
|
+
The driver provides sessions to interact with the database and to execute queries.
|
|
204
|
+
|
|
205
|
+
#### Session
|
|
206
|
+
|
|
207
|
+
Sessions are lightweight and disposable database connections. Always close your sessions when done:
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
session = driver.session(database: 'neo4j')
|
|
211
|
+
begin
|
|
212
|
+
session.run('MATCH (n) RETURN n LIMIT 10')
|
|
213
|
+
ensure
|
|
214
|
+
session.close
|
|
215
|
+
end
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Or use a block that automatically closes the session:
|
|
219
|
+
|
|
220
|
+
```ruby
|
|
221
|
+
driver.session(database: 'neo4j') do |session|
|
|
222
|
+
session.run('MATCH (n) RETURN n LIMIT 10')
|
|
223
|
+
end
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Session options:
|
|
227
|
+
|
|
228
|
+
```ruby
|
|
229
|
+
# Default database
|
|
230
|
+
session = driver.session
|
|
231
|
+
|
|
232
|
+
# Specific database
|
|
233
|
+
session = driver.session(database: 'neo4j')
|
|
234
|
+
|
|
235
|
+
# With access mode
|
|
236
|
+
session = driver.session(database: 'neo4j', default_access_mode: Neo4j::Driver::AccessMode::READ)
|
|
237
|
+
|
|
238
|
+
# With bookmarks for causal consistency
|
|
239
|
+
session = driver.session(
|
|
240
|
+
database: 'neo4j',
|
|
241
|
+
bookmarks: [Neo4j::Driver::Bookmark.from('bookmark-1')]
|
|
242
|
+
)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Auto-commit transactions
|
|
246
|
+
|
|
247
|
+
For simple, one-off queries, use auto-commit transactions:
|
|
248
|
+
|
|
249
|
+
```ruby
|
|
250
|
+
session.run('CREATE (n:Person {name: $name})', name: 'Alice')
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### Explicit transactions
|
|
254
|
+
|
|
255
|
+
For multiple queries that need to be executed as a unit, use explicit transactions:
|
|
256
|
+
|
|
257
|
+
```ruby
|
|
258
|
+
tx = session.begin_transaction
|
|
259
|
+
begin
|
|
260
|
+
tx.run('CREATE (n:Person {name: $name})', name: 'Alice')
|
|
261
|
+
tx.run('CREATE (n:Person {name: $name})', name: 'Bob')
|
|
262
|
+
tx.commit
|
|
263
|
+
rescue
|
|
264
|
+
tx.rollback
|
|
265
|
+
raise
|
|
266
|
+
end
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### Read transactions
|
|
270
|
+
|
|
271
|
+
Specifically for read operations:
|
|
272
|
+
|
|
273
|
+
```ruby
|
|
274
|
+
result = session.read_transaction do |tx|
|
|
275
|
+
tx.run('MATCH (n:Person) RETURN n.name').map { |record| record['n.name'] }
|
|
276
|
+
end
|
|
277
|
+
puts result
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### Write transactions
|
|
281
|
+
|
|
282
|
+
Specifically for write operations:
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
session.write_transaction do |tx|
|
|
286
|
+
tx.run('CREATE (n:Person {name: $name})', name: 'Charlie')
|
|
287
|
+
end
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Working with results
|
|
291
|
+
|
|
292
|
+
```ruby
|
|
293
|
+
result = session.run('MATCH (n:Person) RETURN n.name AS name, n.age AS age')
|
|
294
|
+
|
|
295
|
+
# Process results
|
|
296
|
+
result.each do |record|
|
|
297
|
+
puts "#{record['name']} is #{record['age']} years old"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# Check if there are more results
|
|
301
|
+
puts "Has more results: #{result.has_next?}"
|
|
302
|
+
|
|
303
|
+
# Get a single record
|
|
304
|
+
single = result.single
|
|
305
|
+
puts single['name'] if single
|
|
306
|
+
|
|
307
|
+
# Get keys available in the result
|
|
308
|
+
puts "Keys: #{result.keys}"
|
|
309
|
+
|
|
310
|
+
# Access by field index
|
|
311
|
+
result.each do |record|
|
|
312
|
+
puts "First field: #{record[0]}"
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Convert to array
|
|
316
|
+
records = result.to_a
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
#### Accessing Node and Relationship data
|
|
320
|
+
|
|
321
|
+
Working with graph entities:
|
|
322
|
+
|
|
323
|
+
```ruby
|
|
324
|
+
result = session.run('MATCH (p:Person)-[r:KNOWS]->(friend) RETURN p, r, friend')
|
|
325
|
+
|
|
326
|
+
result.each do |record|
|
|
327
|
+
# Working with nodes
|
|
328
|
+
person = record['p']
|
|
329
|
+
puts "Node ID: #{person.id}"
|
|
330
|
+
puts "Labels: #{person.labels.join(', ')}"
|
|
331
|
+
puts "Properties: #{person.properties}"
|
|
332
|
+
puts "Name property: #{person.properties['name']}"
|
|
333
|
+
|
|
334
|
+
# Working with relationships
|
|
335
|
+
relationship = record['r']
|
|
336
|
+
puts "Relationship ID: #{relationship.id}"
|
|
337
|
+
puts "Type: #{relationship.type}"
|
|
338
|
+
puts "Properties: #{relationship.properties}"
|
|
339
|
+
|
|
340
|
+
# Start and end nodes of the relationship
|
|
341
|
+
puts "Relationship: #{relationship.start_node_id} -> #{relationship.end_node_id}"
|
|
342
|
+
end
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
#### Working with Paths
|
|
346
|
+
|
|
347
|
+
Processing paths returned from Cypher:
|
|
348
|
+
|
|
349
|
+
```ruby
|
|
350
|
+
result = session.run('MATCH p = (:Person)-[:KNOWS*]->(:Person) RETURN p')
|
|
351
|
+
|
|
352
|
+
result.each do |record|
|
|
353
|
+
path = record['p']
|
|
354
|
+
|
|
355
|
+
# Get all nodes in the path
|
|
356
|
+
nodes = path.nodes
|
|
357
|
+
puts "Nodes in path: #{nodes.map { |n| n.properties['name'] }.join(' -> ')}"
|
|
358
|
+
|
|
359
|
+
# Get all relationships in the path
|
|
360
|
+
relationships = path.relationships
|
|
361
|
+
puts "Relationship types: #{relationships.map(&:type).join(', ')}"
|
|
362
|
+
|
|
363
|
+
# Iterate through the path segments
|
|
364
|
+
path.each do |segment|
|
|
365
|
+
puts "#{segment.start_node.properties['name']} -[#{segment.relationship.type}]-> #{segment.end_node.properties['name']}"
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### Working with temporal types
|
|
371
|
+
|
|
372
|
+
Creating a node with properties of temporal types:
|
|
373
|
+
|
|
374
|
+
```ruby
|
|
375
|
+
session.run(
|
|
376
|
+
'CREATE (e:Event {datetime: $datetime, duration: $duration})',
|
|
377
|
+
datetime: DateTime.new(2025, 5, 5, 5, 55, 55), duration: 1.hour
|
|
378
|
+
)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Querying temporal values:
|
|
382
|
+
|
|
383
|
+
```ruby
|
|
384
|
+
session.run('MATCH (e:Event) LIMIT 1 RETURN e.datetime, e.duration').single.to_h
|
|
385
|
+
# => {"e.datetime": 2025-05-05 05:55:55 +0000, "e.duration": 3600 seconds}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Type mapping
|
|
33
389
|
|
|
34
|
-
|
|
390
|
+
The Neo4j Ruby Driver maps Cypher types to Ruby types:
|
|
35
391
|
|
|
36
|
-
|
|
392
|
+
| Cypher Type | Ruby Type |
|
|
393
|
+
|----------------|-----------------------------------------------|
|
|
394
|
+
| null | nil |
|
|
395
|
+
| List | Enumerable |
|
|
396
|
+
| Map | Hash (symbolized keys) |
|
|
397
|
+
| Boolean | TrueClass/FalseClass |
|
|
398
|
+
| Integer | Integer/String[^1] |
|
|
399
|
+
| Float | Float |
|
|
400
|
+
| String | String/Symbol[^2] (encoding: UTF-8) |
|
|
401
|
+
| ByteArray | String (encoding: BINARY) |
|
|
402
|
+
| Date | Date |
|
|
403
|
+
| Zoned Time | Neo4j::Driver::Types::OffsetTime |
|
|
404
|
+
| Local Time | Neo4j::Driver::Types::LocalTime |
|
|
405
|
+
| Zoned DateTime | Time/ActiveSupport::TimeWithZone/DateTime[^3] |
|
|
406
|
+
| Local DateTime | Neo4j::Driver::Types::LocalDateTime |
|
|
407
|
+
| Duration | ActiveSupport::Duration |
|
|
408
|
+
| Point | Neo4j::Driver::Types::Point |
|
|
409
|
+
| Node | Neo4j::Driver::Types::Node |
|
|
410
|
+
| Relationship | Neo4j::Driver::Types::Relationship |
|
|
411
|
+
| Path | Neo4j::Driver::Types::Path |
|
|
37
412
|
|
|
38
|
-
|
|
413
|
+
[^1]: An Integer smaller than -2 ** 63 or larger than 2 ** 63 will always be implicitly converted to String
|
|
414
|
+
[^2]: A Symbol passed as a parameter will always be implicitly converted to String. All Strings other than BINARY
|
|
415
|
+
encoded are converted to UTF-8 when stored in Neo4j
|
|
416
|
+
[^3]: A Ruby DateTime passed as a parameter will always be implicitly converted to Time
|
|
39
417
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Testing
|
|
418
|
+
### Advanced
|
|
43
419
|
|
|
44
|
-
|
|
420
|
+
#### Connection pooling
|
|
45
421
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
422
|
+
The driver handles connection pooling automatically. Configure the connection pool:
|
|
423
|
+
|
|
424
|
+
```ruby
|
|
425
|
+
config = {
|
|
426
|
+
max_connection_pool_size: 100,
|
|
427
|
+
max_connection_lifetime: 1.hour
|
|
428
|
+
}
|
|
52
429
|
|
|
53
|
-
|
|
54
|
-
```console
|
|
55
|
-
$ bin/setup
|
|
56
|
-
$ rspec spec
|
|
430
|
+
driver = Neo4j::Driver::GraphDatabase.driver('neo4j://localhost:7687', auth, **config)
|
|
57
431
|
```
|
|
58
432
|
|
|
59
|
-
|
|
433
|
+
#### Logging
|
|
60
434
|
|
|
61
|
-
|
|
435
|
+
Configure logging for the driver:
|
|
62
436
|
|
|
63
|
-
```
|
|
64
|
-
|
|
437
|
+
```ruby
|
|
438
|
+
config = {
|
|
439
|
+
logger: Logger.new(STDOUT).tap { |log| log.level = Logger::DEBUG }
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
driver = Neo4j::Driver::GraphDatabase.driver('neo4j://localhost:7687', auth, **config)
|
|
65
443
|
```
|
|
66
444
|
|
|
67
|
-
|
|
445
|
+
## For Driver Engineers
|
|
68
446
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
447
|
+
This gem includes 2 different implementations: a Java driver wrapper and a pure Ruby driver, so you will have to run
|
|
448
|
+
this command every time you switch the Ruby engine:
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
bin/setup
|
|
74
452
|
```
|
|
75
453
|
|
|
454
|
+
### Testing
|
|
455
|
+
|
|
456
|
+
There are two sets of tests for the driver. To run the specs placed in this repository, use a normal rspec command:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
rspec spec
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
To run the [Testkit](https://github.com/neo4j-drivers/testkit) that is used to test all Neo4j driver implementations,
|
|
463
|
+
use the following:
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
git clone git@github.com:neo4j-drivers/testkit.git
|
|
467
|
+
cd testkit
|
|
468
|
+
export TEST_DRIVER_NAME=ruby
|
|
469
|
+
export TEST_DRIVER_REPO=`realpath ../neo4j-ruby-driver`
|
|
470
|
+
export TEST_NEO4J_PASS=password
|
|
471
|
+
python3 main.py --tests UNIT_TESTS --configs 4.3-enterprise
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
Please refer to the [Testkit](https://github.com/neo4j-drivers/testkit) documentation to learn more about its features.
|
|
475
|
+
|
|
76
476
|
## Contributing
|
|
77
477
|
|
|
78
|
-
Suggestions, improvements, bug reports and pull requests are welcome on GitHub
|
|
478
|
+
Suggestions, improvements, bug reports and pull requests are welcome on GitHub
|
|
479
|
+
at https://github.com/neo4jrb/neo4j-ruby-driver.
|
|
79
480
|
|
|
80
481
|
## License
|
|
81
482
|
|
|
82
483
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
83
|
-
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module Neo4j
|
|
4
4
|
module Driver
|
|
5
|
-
module
|
|
6
|
-
def
|
|
5
|
+
module AutoCloseable
|
|
6
|
+
def auto_closeable(*methods)
|
|
7
7
|
prepend with_block_definer(methods)
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -13,15 +13,15 @@ module Neo4j
|
|
|
13
13
|
Module.new do
|
|
14
14
|
methods.each do |method|
|
|
15
15
|
define_method(method) do |*args, **kwargs, &block|
|
|
16
|
-
|
|
16
|
+
closeable = super(*args, **kwargs)
|
|
17
17
|
if block
|
|
18
18
|
begin
|
|
19
|
-
block.arity.zero? ?
|
|
19
|
+
block.arity.zero? ? closeable.instance_eval(&block) : block.call(closeable)
|
|
20
20
|
ensure
|
|
21
|
-
|
|
21
|
+
closeable&.close
|
|
22
22
|
end
|
|
23
23
|
else
|
|
24
|
-
|
|
24
|
+
closeable
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Neo4j
|
|
2
|
+
module Driver
|
|
3
|
+
module Internal
|
|
4
|
+
module Deprecator
|
|
5
|
+
def self.deprecator
|
|
6
|
+
@deprecator ||= ActiveSupport::Deprecation.new('6.0', 'neo4j-ruby-driver')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.log_warning(old_method, new_method, version)
|
|
10
|
+
deprecator.deprecation_warning(old_method, new_method)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module Neo4j::Driver
|
|
4
4
|
class GraphDatabase
|
|
5
5
|
class << self
|
|
6
|
-
extend
|
|
7
|
-
|
|
6
|
+
extend AutoCloseable
|
|
7
|
+
auto_closeable :driver, :routing_driver
|
|
8
8
|
|
|
9
9
|
def driver(uri, auth_token = nil, **config)
|
|
10
10
|
internal_driver(uri, auth_token, config)
|
|
@@ -3,7 +3,7 @@ module Neo4j::Driver
|
|
|
3
3
|
module Handlers
|
|
4
4
|
module Pulln
|
|
5
5
|
class AutoPullResponseHandler < BasicPullResponseHandler
|
|
6
|
-
delegate :signal, to: :@
|
|
6
|
+
delegate :signal, to: :@queue_notification
|
|
7
7
|
LONG_MAX_VALUE = 2 ** 63 - 1
|
|
8
8
|
|
|
9
9
|
def initialize(query, run_response_handler, connection, metadata_extractor, completion_listener, fetch_size)
|
|
@@ -19,7 +19,8 @@ module Neo4j::Driver
|
|
|
19
19
|
@low_record_watermark = fetch_size * 0.3
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
@
|
|
22
|
+
@queue_notification = ::Async::Notification.new
|
|
23
|
+
@records = ::Async::Queue.new(available: @queue_notification)
|
|
23
24
|
@auto_pull_enabled = true
|
|
24
25
|
|
|
25
26
|
install_record_and_summary_consumers
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module Neo4j::Driver
|
|
2
2
|
module Internal
|
|
3
3
|
class InternalDriver
|
|
4
|
-
extend
|
|
4
|
+
extend AutoCloseable
|
|
5
5
|
extend Synchronizable
|
|
6
6
|
attr_reader :session_factory, :metrics_provider
|
|
7
7
|
# delegate :verify_connectivity, to: :session_factory
|
|
8
8
|
delegate :metrics, :metrics_enabled?, to: :metrics_provider
|
|
9
|
-
|
|
9
|
+
auto_closeable :session
|
|
10
10
|
sync :close, :supports_multi_db?, :verify_connectivity, :session
|
|
11
11
|
|
|
12
12
|
def initialize(security_plan, session_factory, metrics_provider, logger)
|
|
@@ -25,6 +25,15 @@ module Neo4j::Driver
|
|
|
25
25
|
InternalAsyncSession.new(new_session(**session_config))
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def execute_query(query, auth_token = nil, config = {}, **parameters)
|
|
29
|
+
# TODO: auth_token not implemented yet
|
|
30
|
+
session(**config.slice(:bookmarks, :database, :impersonated_user, :default_access_mode, :fetch_size)) do |session|
|
|
31
|
+
session.run(query, parameters, config.slice(:timeout, :metadata)).then do
|
|
32
|
+
EagerResultValue.new(it.keys, it.to_a, it.consume)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
28
37
|
def encrypted?
|
|
29
38
|
assert_open!
|
|
30
39
|
@security_plan.requires_encryption?
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module Neo4j::Driver
|
|
2
2
|
module Internal
|
|
3
3
|
class InternalSession
|
|
4
|
-
extend
|
|
4
|
+
extend AutoCloseable
|
|
5
5
|
extend Synchronizable
|
|
6
6
|
# include Ext::RunOverride
|
|
7
7
|
delegate :open?, :last_bookmark, to: :@session
|
|
8
|
-
|
|
8
|
+
auto_closeable :begin_transaction
|
|
9
9
|
sync :close, :begin_transaction, :run, :transaction
|
|
10
10
|
|
|
11
11
|
def initialize(session)
|
|
@@ -38,15 +38,29 @@ module Neo4j::Driver
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def read_transaction(**config, &block)
|
|
41
|
+
Deprecator.log_warning(:read_transaction, :execute_read, '6.0')
|
|
41
42
|
transaction(AccessMode::READ, **config, &block)
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def write_transaction(**config, &block)
|
|
46
|
+
Deprecator.log_warning(:write_transaction, :execute_write, '6.0')
|
|
45
47
|
transaction(AccessMode::WRITE, **config, &block)
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
def execute_read(**config, &block)
|
|
51
|
+
delegating_transaction(AccessMode::READ, **config, &block)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def execute_write(**config, &block)
|
|
55
|
+
delegating_transaction(AccessMode::WRITE, **config, &block)
|
|
56
|
+
end
|
|
57
|
+
|
|
48
58
|
private
|
|
49
59
|
|
|
60
|
+
def delegating_transaction(mode, **config, &block)
|
|
61
|
+
transaction(mode, **config) { |tx| block.call(DelegatingTransaction.new(tx)) }
|
|
62
|
+
end
|
|
63
|
+
|
|
50
64
|
def transaction(mode, **config)
|
|
51
65
|
# use different code path compared to async so that work is executed in the caller thread
|
|
52
66
|
# caller thread will also be the one who sleeps between retries;
|
data/ruby/neo4j/driver.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'active_support/core_ext/array/grouping'
|
|
4
4
|
require 'active_support/core_ext/hash/keys'
|
|
5
|
+
require 'active_support/core_ext/object/blank'
|
|
5
6
|
require 'active_support/logger'
|
|
6
7
|
require 'async/io'
|
|
7
8
|
require 'async/io/stream'
|
|
@@ -14,6 +15,7 @@ module Neo4j
|
|
|
14
15
|
module Driver
|
|
15
16
|
Loader.load
|
|
16
17
|
|
|
18
|
+
EagerResult = Neo4j::Driver::Internal::EagerResultValue
|
|
17
19
|
Record = Neo4j::Driver::Internal::InternalRecord
|
|
18
20
|
Result = Neo4j::Driver::Internal::InternalResult
|
|
19
21
|
Transaction = Neo4j::Driver::Internal::InternalTransaction
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neo4j-ruby-driver
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.7.0.alpha.
|
|
4
|
+
version: 5.7.0.alpha.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Heinrich Klobuczek
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|
|
@@ -24,49 +24,55 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '7.1'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: csv
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: '3.0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: '3.0'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
|
-
name:
|
|
41
|
+
name: zeitwerk
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- - "
|
|
44
|
+
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version:
|
|
46
|
+
version: 2.1.10
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
|
-
- - "
|
|
51
|
+
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
53
|
+
version: 2.1.10
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: async
|
|
55
|
+
name: async
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - ">="
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
60
|
+
version: '2.13'
|
|
61
|
+
- - "<"
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '2.24'
|
|
61
64
|
type: :runtime
|
|
62
65
|
prerelease: false
|
|
63
66
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
67
|
requirements:
|
|
65
68
|
- - ">="
|
|
66
69
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '
|
|
70
|
+
version: '2.13'
|
|
71
|
+
- - "<"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '2.24'
|
|
68
74
|
- !ruby/object:Gem::Dependency
|
|
69
|
-
name:
|
|
75
|
+
name: async-io
|
|
70
76
|
requirement: !ruby/object:Gem::Requirement
|
|
71
77
|
requirements:
|
|
72
78
|
- - ">="
|
|
@@ -80,19 +86,19 @@ dependencies:
|
|
|
80
86
|
- !ruby/object:Gem::Version
|
|
81
87
|
version: '0'
|
|
82
88
|
- !ruby/object:Gem::Dependency
|
|
83
|
-
name:
|
|
89
|
+
name: connection_pool
|
|
84
90
|
requirement: !ruby/object:Gem::Requirement
|
|
85
91
|
requirements:
|
|
86
|
-
- - "
|
|
92
|
+
- - "<"
|
|
87
93
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: '
|
|
94
|
+
version: '3'
|
|
89
95
|
type: :runtime
|
|
90
96
|
prerelease: false
|
|
91
97
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
98
|
requirements:
|
|
93
|
-
- - "
|
|
99
|
+
- - "<"
|
|
94
100
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: '
|
|
101
|
+
version: '3'
|
|
96
102
|
- !ruby/object:Gem::Dependency
|
|
97
103
|
name: ffaker
|
|
98
104
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,21 +203,24 @@ dependencies:
|
|
|
197
203
|
requirements:
|
|
198
204
|
- - ">="
|
|
199
205
|
- !ruby/object:Gem::Version
|
|
200
|
-
version: '
|
|
206
|
+
version: '6.0'
|
|
201
207
|
- - "<"
|
|
202
208
|
- !ruby/object:Gem::Version
|
|
203
|
-
version: '
|
|
209
|
+
version: '8'
|
|
204
210
|
type: :development
|
|
205
211
|
prerelease: false
|
|
206
212
|
version_requirements: !ruby/object:Gem::Requirement
|
|
207
213
|
requirements:
|
|
208
214
|
- - ">="
|
|
209
215
|
- !ruby/object:Gem::Version
|
|
210
|
-
version: '
|
|
216
|
+
version: '6.0'
|
|
211
217
|
- - "<"
|
|
212
218
|
- !ruby/object:Gem::Version
|
|
213
|
-
version: '
|
|
214
|
-
description:
|
|
219
|
+
version: '8'
|
|
220
|
+
description: |2
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
==== To Install:
|
|
215
224
|
email:
|
|
216
225
|
- heinrich@mail.com
|
|
217
226
|
executables: []
|
|
@@ -224,7 +233,7 @@ files:
|
|
|
224
233
|
- README.md
|
|
225
234
|
- lib/neo4j-ruby-driver.rb
|
|
226
235
|
- lib/neo4j-ruby-driver_loader.rb
|
|
227
|
-
- lib/neo4j/driver/
|
|
236
|
+
- lib/neo4j/driver/auto_closeable.rb
|
|
228
237
|
- lib/neo4j/driver/exceptions/authentication_exception.rb
|
|
229
238
|
- lib/neo4j/driver/exceptions/authorization_expired_exception.rb
|
|
230
239
|
- lib/neo4j/driver/exceptions/certificate_exception.rb
|
|
@@ -252,6 +261,7 @@ files:
|
|
|
252
261
|
- lib/neo4j/driver/exceptions/value/unsizable.rb
|
|
253
262
|
- lib/neo4j/driver/exceptions/value/value_exception.rb
|
|
254
263
|
- lib/neo4j/driver/internal/bolt_server_address.rb
|
|
264
|
+
- lib/neo4j/driver/internal/deprecator.rb
|
|
255
265
|
- lib/neo4j/driver/internal/duration_normalizer.rb
|
|
256
266
|
- lib/neo4j/driver/internal/validator.rb
|
|
257
267
|
- lib/neo4j/driver/summary/query_type.rb
|
|
@@ -339,8 +349,10 @@ files:
|
|
|
339
349
|
- ruby/neo4j/driver/internal/database_name_util.rb
|
|
340
350
|
- ruby/neo4j/driver/internal/default_bookmark_holder.rb
|
|
341
351
|
- ruby/neo4j/driver/internal/default_domain_name_resolver.rb
|
|
352
|
+
- ruby/neo4j/driver/internal/delegating_transaction.rb
|
|
342
353
|
- ruby/neo4j/driver/internal/direct_connection_provider.rb
|
|
343
354
|
- ruby/neo4j/driver/internal/driver_factory.rb
|
|
355
|
+
- ruby/neo4j/driver/internal/eager_result_value.rb
|
|
344
356
|
- ruby/neo4j/driver/internal/handlers/begin_tx_response_handler.rb
|
|
345
357
|
- ruby/neo4j/driver/internal/handlers/channel_releasing_reset_response_handler.rb
|
|
346
358
|
- ruby/neo4j/driver/internal/handlers/commit_tx_response_handler.rb
|
|
@@ -524,7 +536,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
524
536
|
- !ruby/object:Gem::Version
|
|
525
537
|
version: '0'
|
|
526
538
|
requirements: []
|
|
527
|
-
rubygems_version: 3.6.
|
|
539
|
+
rubygems_version: 3.6.9
|
|
528
540
|
specification_version: 4
|
|
529
|
-
summary:
|
|
541
|
+
summary: "==== To Install:"
|
|
530
542
|
test_files: []
|