activecypher 0.5.0 → 0.6.1
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/lib/active_cypher/base.rb +28 -8
- data/lib/active_cypher/bolt/driver.rb +6 -16
- data/lib/active_cypher/bolt/transaction.rb +9 -9
- data/lib/active_cypher/connection_adapters/abstract_adapter.rb +28 -0
- data/lib/active_cypher/connection_adapters/abstract_bolt_adapter.rb +1 -1
- data/lib/active_cypher/connection_adapters/memgraph_adapter.rb +44 -0
- data/lib/active_cypher/connection_adapters/neo4j_adapter.rb +26 -0
- data/lib/active_cypher/connection_adapters/registry.rb +96 -0
- data/lib/active_cypher/connection_handler.rb +18 -3
- data/lib/active_cypher/connection_pool.rb +5 -23
- data/lib/active_cypher/connection_url_resolver.rb +14 -3
- data/lib/active_cypher/fixtures/dsl_context.rb +41 -0
- data/lib/active_cypher/fixtures/evaluator.rb +37 -0
- data/lib/active_cypher/fixtures/node_builder.rb +53 -0
- data/lib/active_cypher/fixtures/parser.rb +23 -0
- data/lib/active_cypher/fixtures/registry.rb +43 -0
- data/lib/active_cypher/fixtures/rel_builder.rb +96 -0
- data/lib/active_cypher/fixtures.rb +177 -0
- data/lib/active_cypher/generators/templates/application_graph_node.rb +1 -0
- data/lib/active_cypher/model/callbacks.rb +5 -13
- data/lib/active_cypher/model/connection_handling.rb +37 -52
- data/lib/active_cypher/model/connection_owner.rb +31 -38
- data/lib/active_cypher/model/core.rb +1 -63
- data/lib/active_cypher/model/destruction.rb +16 -18
- data/lib/active_cypher/model/labelling.rb +45 -0
- data/lib/active_cypher/model/persistence.rb +46 -40
- data/lib/active_cypher/model/querying.rb +47 -27
- data/lib/active_cypher/railtie.rb +40 -5
- data/lib/active_cypher/relationship.rb +77 -17
- data/lib/active_cypher/version.rb +1 -1
- data/lib/activecypher.rb +4 -1
- data/lib/cyrel/functions.rb +3 -1
- data/lib/cyrel/logging.rb +43 -0
- data/lib/cyrel/query.rb +6 -1
- metadata +11 -2
- data/lib/active_cypher/connection_factory.rb +0 -130
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activecypher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
@@ -119,11 +119,18 @@ files:
|
|
119
119
|
- lib/active_cypher/connection_adapters/abstract_bolt_adapter.rb
|
120
120
|
- lib/active_cypher/connection_adapters/memgraph_adapter.rb
|
121
121
|
- lib/active_cypher/connection_adapters/neo4j_adapter.rb
|
122
|
-
- lib/active_cypher/
|
122
|
+
- lib/active_cypher/connection_adapters/registry.rb
|
123
123
|
- lib/active_cypher/connection_handler.rb
|
124
124
|
- lib/active_cypher/connection_pool.rb
|
125
125
|
- lib/active_cypher/connection_url_resolver.rb
|
126
126
|
- lib/active_cypher/cypher_config.rb
|
127
|
+
- lib/active_cypher/fixtures.rb
|
128
|
+
- lib/active_cypher/fixtures/dsl_context.rb
|
129
|
+
- lib/active_cypher/fixtures/evaluator.rb
|
130
|
+
- lib/active_cypher/fixtures/node_builder.rb
|
131
|
+
- lib/active_cypher/fixtures/parser.rb
|
132
|
+
- lib/active_cypher/fixtures/registry.rb
|
133
|
+
- lib/active_cypher/fixtures/rel_builder.rb
|
127
134
|
- lib/active_cypher/generators/install_generator.rb
|
128
135
|
- lib/active_cypher/generators/node_generator.rb
|
129
136
|
- lib/active_cypher/generators/relationship_generator.rb
|
@@ -143,6 +150,7 @@ files:
|
|
143
150
|
- lib/active_cypher/model/countable.rb
|
144
151
|
- lib/active_cypher/model/destruction.rb
|
145
152
|
- lib/active_cypher/model/inspectable.rb
|
153
|
+
- lib/active_cypher/model/labelling.rb
|
146
154
|
- lib/active_cypher/model/persistence.rb
|
147
155
|
- lib/active_cypher/model/querying.rb
|
148
156
|
- lib/active_cypher/railtie.rb
|
@@ -184,6 +192,7 @@ files:
|
|
184
192
|
- lib/cyrel/expression/pattern_comprehension.rb
|
185
193
|
- lib/cyrel/expression/property_access.rb
|
186
194
|
- lib/cyrel/functions.rb
|
195
|
+
- lib/cyrel/logging.rb
|
187
196
|
- lib/cyrel/node.rb
|
188
197
|
- lib/cyrel/parameterizable.rb
|
189
198
|
- lib/cyrel/pattern.rb
|
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveCypher
|
4
|
-
# ConnectionFactory provides a simple API for creating connections to Cypher databases
|
5
|
-
# using the ConnectionUrlResolver to parse database URLs.
|
6
|
-
#
|
7
|
-
# This factory simplifies the process of creating database connections by:
|
8
|
-
# 1. Parsing connection URLs with ConnectionUrlResolver
|
9
|
-
# 2. Creating the appropriate adapter based on the URL
|
10
|
-
# 3. Establishing and configuring the connection with the right security settings
|
11
|
-
#
|
12
|
-
# Example:
|
13
|
-
# factory = ConnectionFactory.new("neo4j://user:pass@localhost:7687")
|
14
|
-
# driver = factory.create_driver
|
15
|
-
#
|
16
|
-
# driver.with_session do |session|
|
17
|
-
# result = session.run("RETURN 'Connected!' AS message")
|
18
|
-
# puts result.first[:message]
|
19
|
-
# end
|
20
|
-
class ConnectionFactory
|
21
|
-
# Initialize with a database URL
|
22
|
-
# @param url [String] A database connection URL
|
23
|
-
# @param options [Hash] Additional options for the connection
|
24
|
-
def initialize(url, options = {})
|
25
|
-
@url = url
|
26
|
-
@options = options
|
27
|
-
@config = resolve_url(url)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Create a Bolt driver based on the parsed URL
|
31
|
-
# @param pool_size [Integer] Size of the connection pool
|
32
|
-
# @return [ActiveCypher::Bolt::Driver, nil] The configured driver or nil if URL is invalid
|
33
|
-
def create_driver(pool_size: 5)
|
34
|
-
return nil unless @config
|
35
|
-
|
36
|
-
# Create the adapter based on the resolved configuration
|
37
|
-
adapter = create_adapter
|
38
|
-
return nil unless adapter
|
39
|
-
|
40
|
-
# Create and configure the Bolt driver
|
41
|
-
uri = build_uri
|
42
|
-
auth_token = build_auth_token
|
43
|
-
|
44
|
-
ActiveCypher::Bolt::Driver.new(
|
45
|
-
uri: uri,
|
46
|
-
adapter: adapter,
|
47
|
-
auth_token: auth_token,
|
48
|
-
pool_size: pool_size
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Get the parsed configuration
|
53
|
-
# @return [Hash, nil] The parsed configuration or nil if URL is invalid
|
54
|
-
attr_reader :config
|
55
|
-
|
56
|
-
# Verify if the URL is valid and supported
|
57
|
-
# @return [Boolean] True if the URL is valid and supported
|
58
|
-
def valid?
|
59
|
-
!@config.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
# Resolve the URL into a configuration hash
|
65
|
-
def resolve_url(url)
|
66
|
-
resolver = ConnectionUrlResolver.new(url)
|
67
|
-
resolver.to_hash
|
68
|
-
end
|
69
|
-
|
70
|
-
# Create the appropriate adapter based on the parsed URL
|
71
|
-
def create_adapter
|
72
|
-
case @config[:adapter]
|
73
|
-
when 'neo4j'
|
74
|
-
create_neo4j_adapter
|
75
|
-
when 'memgraph'
|
76
|
-
create_memgraph_adapter
|
77
|
-
else
|
78
|
-
nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Create a Neo4j adapter
|
83
|
-
def create_neo4j_adapter
|
84
|
-
ConnectionAdapters::Neo4jAdapter.new({
|
85
|
-
uri: build_uri,
|
86
|
-
username: @config[:username],
|
87
|
-
password: @config[:password],
|
88
|
-
database: @config[:database]
|
89
|
-
})
|
90
|
-
end
|
91
|
-
|
92
|
-
# Create a Memgraph adapter
|
93
|
-
def create_memgraph_adapter
|
94
|
-
ConnectionAdapters::MemgraphAdapter.new({
|
95
|
-
uri: build_uri,
|
96
|
-
username: @config[:username],
|
97
|
-
password: @config[:password],
|
98
|
-
database: @config[:database]
|
99
|
-
})
|
100
|
-
rescue NameError
|
101
|
-
# Fall back to Neo4j adapter if Memgraph adapter is not available
|
102
|
-
ConnectionAdapters::Neo4jAdapter.new({
|
103
|
-
uri: build_uri,
|
104
|
-
username: @config[:username],
|
105
|
-
password: @config[:password],
|
106
|
-
database: @config[:database]
|
107
|
-
})
|
108
|
-
end
|
109
|
-
|
110
|
-
# Build the URI string with the appropriate scheme based on SSL settings
|
111
|
-
def build_uri
|
112
|
-
scheme = if @config[:ssl]
|
113
|
-
@config[:ssc] ? 'bolt+ssc' : 'bolt+s'
|
114
|
-
else
|
115
|
-
'bolt'
|
116
|
-
end
|
117
|
-
|
118
|
-
"#{scheme}://#{@config[:host]}:#{@config[:port]}"
|
119
|
-
end
|
120
|
-
|
121
|
-
# Build the authentication token for the Bolt driver
|
122
|
-
def build_auth_token
|
123
|
-
{
|
124
|
-
scheme: 'basic',
|
125
|
-
principal: @config[:username],
|
126
|
-
credentials: @config[:password]
|
127
|
-
}
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|