activegraph 10.0.0.pre.beta.4 → 10.0.0.pre.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_graph/core/label.rb +5 -28
- data/lib/active_graph/core/query.rb +1 -1
- data/lib/active_graph/migrations/schema.rb +4 -4
- data/lib/active_graph/node/has_n.rb +19 -28
- data/lib/active_graph/node/query/query_proxy.rb +2 -9
- data/lib/active_graph/node/unpersisted.rb +1 -1
- data/lib/active_graph/relationship/query.rb +4 -6
- data/lib/active_graph/shared.rb +0 -12
- data/lib/active_graph/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f768ee99674bbc10fb6c1094921b8f6f7840cfdd6c2d2ae442e4cc33d243690a
|
4
|
+
data.tar.gz: 46d381583be9bd03f45d8b6f684d2bc3ae0e394ebcbd2685d57cda834f354e24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd8b19f5894b9b5b528887aff9616f62d08818c90a03e1b9144850c1c832061f6af598a4d5ebf8a1d9e9751bfb6a1ba7bfa730df83a43070e0f95081a799347
|
7
|
+
data.tar.gz: 4c02f0e0ab88bffdafb794a892aacd46351118bb7dbe179a1fab56dc2febe9a6bee08d2d0c6850580c039b493e5eb76cc4a77b57a272c09d2f4a286f134d237b
|
@@ -21,8 +21,8 @@ module ActiveGraph
|
|
21
21
|
# Creates a neo4j constraint on a property
|
22
22
|
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
23
23
|
# @example
|
24
|
-
# label = ActiveGraph::Label.create(:person
|
25
|
-
# label.create_constraint(:name, {type: :unique}
|
24
|
+
# label = ActiveGraph::Label.create(:person)
|
25
|
+
# label.create_constraint(:name, {type: :unique})
|
26
26
|
#
|
27
27
|
def create_constraint(property, constraints)
|
28
28
|
cypher = case constraints[:type]
|
@@ -41,9 +41,9 @@ module ActiveGraph
|
|
41
41
|
# Drops a neo4j constraint on a property
|
42
42
|
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
43
43
|
# @example
|
44
|
-
# label = ActiveGraph::Label.create(:person
|
45
|
-
# label.create_constraint(:name, {type: :unique}
|
46
|
-
# label.drop_constraint(:name, {type: :unique}
|
44
|
+
# label = ActiveGraph::Label.create(:person)
|
45
|
+
# label.create_constraint(:name, {type: :unique})
|
46
|
+
# label.drop_constraint(:name, {type: :unique})
|
47
47
|
#
|
48
48
|
def drop_constraint(property, constraint)
|
49
49
|
cypher = case constraint[:type]
|
@@ -97,16 +97,6 @@ module ActiveGraph
|
|
97
97
|
|
98
98
|
private
|
99
99
|
|
100
|
-
# Store schema threads on the driver so that we can easily wait for all
|
101
|
-
# threads on a driver regardless of label
|
102
|
-
def schema_threads
|
103
|
-
self.class.schema_threads
|
104
|
-
end
|
105
|
-
|
106
|
-
def schema_threads=(array)
|
107
|
-
self.class.set_schema_threads(array)
|
108
|
-
end
|
109
|
-
|
110
100
|
class << self
|
111
101
|
def indexes
|
112
102
|
ActiveGraph::Base.indexes
|
@@ -130,19 +120,6 @@ module ActiveGraph
|
|
130
120
|
end
|
131
121
|
end
|
132
122
|
end
|
133
|
-
|
134
|
-
def wait_for_schema_changes
|
135
|
-
schema_threads.map(&:join)
|
136
|
-
set_schema_threads(driver, [])
|
137
|
-
end
|
138
|
-
|
139
|
-
def schema_threads
|
140
|
-
ActiveGraph::Transaction.instance_variable_get('@_schema_threads') || []
|
141
|
-
end
|
142
|
-
|
143
|
-
def set_schema_threads(array)
|
144
|
-
ActiveGraph::Transaction.instance_variable_set('@_schema_threads', array)
|
145
|
-
end
|
146
123
|
end
|
147
124
|
|
148
125
|
def schema_query(cypher)
|
@@ -9,8 +9,8 @@ module ActiveGraph
|
|
9
9
|
|
10
10
|
def synchronize_schema_data(schema_data, remove_missing)
|
11
11
|
queries = []
|
12
|
-
queries += drop_and_create_queries(fetch_constraint_descriptions
|
13
|
-
queries += drop_and_create_queries(fetch_index_descriptions
|
12
|
+
queries += drop_and_create_queries(fetch_constraint_descriptions, schema_data[:constraints], remove_missing)
|
13
|
+
queries += drop_and_create_queries(fetch_index_descriptions, schema_data[:indexes], remove_missing)
|
14
14
|
ActiveGraph::Base.queries do
|
15
15
|
queries.each { |query| append query }
|
16
16
|
end
|
@@ -18,11 +18,11 @@ module ActiveGraph
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def fetch_constraint_descriptions
|
21
|
+
def fetch_constraint_descriptions
|
22
22
|
ActiveGraph::Base.query('CALL db.constraints()').map(&:description)
|
23
23
|
end
|
24
24
|
|
25
|
-
def fetch_index_descriptions
|
25
|
+
def fetch_index_descriptions
|
26
26
|
result = ActiveGraph::Base.query('CALL db.indexes()')
|
27
27
|
if result.columns.include?(:description)
|
28
28
|
v3_indexes(result)
|
@@ -441,13 +441,7 @@ module ActiveGraph::Node
|
|
441
441
|
end
|
442
442
|
|
443
443
|
def define_has_many_setter(name)
|
444
|
-
|
445
|
-
association_proxy_cache.clear
|
446
|
-
|
447
|
-
clear_deferred_nodes_for_association(name)
|
448
|
-
|
449
|
-
ActiveGraph::Base.transaction { association_proxy(name).replace_with(other_nodes) }
|
450
|
-
end
|
444
|
+
define_setter(name, "#{name}=")
|
451
445
|
end
|
452
446
|
|
453
447
|
def define_has_many_id_methods(name)
|
@@ -455,16 +449,26 @@ module ActiveGraph::Node
|
|
455
449
|
association_proxy(name).result_ids
|
456
450
|
end
|
457
451
|
|
458
|
-
|
459
|
-
clear_deferred_nodes_for_association(name)
|
460
|
-
association_proxy(name).replace_with(Array(ids).reject(&:blank?))
|
461
|
-
end
|
452
|
+
define_setter(name, "#{name.to_s.singularize}_ids=")
|
462
453
|
|
463
454
|
define_method_unless_defined("#{name.to_s.singularize}_neo_ids") do
|
464
455
|
association_proxy(name).pluck(:neo_id)
|
465
456
|
end
|
466
457
|
end
|
467
458
|
|
459
|
+
def define_setter(name, setter_name)
|
460
|
+
define_method_unless_defined(setter_name) do |others|
|
461
|
+
association_proxy_cache.clear # TODO: Should probably just clear for this association...
|
462
|
+
clear_deferred_nodes_for_association(name)
|
463
|
+
others = Array(others).reject(&:blank?)
|
464
|
+
if persisted?
|
465
|
+
ActiveGraph::Base.transaction { association_proxy(name).replace_with(others) }
|
466
|
+
else
|
467
|
+
defer_create(name, others, clear: true)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
468
472
|
def define_method_unless_defined(method_name, &block)
|
469
473
|
define_method(method_name, block) unless method_defined?(method_name)
|
470
474
|
end
|
@@ -492,9 +496,7 @@ module ActiveGraph::Node
|
|
492
496
|
association_proxy(name).result_ids.first
|
493
497
|
end
|
494
498
|
|
495
|
-
|
496
|
-
association_proxy(name).replace_with(id)
|
497
|
-
end
|
499
|
+
define_setter(name, "#{name}_id=")
|
498
500
|
|
499
501
|
define_method_unless_defined("#{name}_neo_id") do
|
500
502
|
association_proxy(name).pluck(:neo_id).first
|
@@ -520,17 +522,7 @@ module ActiveGraph::Node
|
|
520
522
|
end
|
521
523
|
|
522
524
|
def define_has_one_setter(name)
|
523
|
-
|
524
|
-
if persisted?
|
525
|
-
other_node.save if other_node.respond_to?(:persisted?) && !other_node.persisted?
|
526
|
-
association_proxy_cache.clear # TODO: Should probably just clear for this association...
|
527
|
-
ActiveGraph::Base.transaction { association_proxy(name).replace_with(other_node) }
|
528
|
-
# handle_non_persisted_node(other_node)
|
529
|
-
else
|
530
|
-
defer_create(name, other_node, clear: true)
|
531
|
-
other_node
|
532
|
-
end
|
533
|
-
end
|
525
|
+
define_setter(name, "#{name}=")
|
534
526
|
end
|
535
527
|
|
536
528
|
def define_class_method(*args, &block)
|
@@ -545,8 +537,7 @@ module ActiveGraph::Node
|
|
545
537
|
query_proxy = previous_query_proxy || default_association_query_proxy
|
546
538
|
ActiveGraph::Node::Query::QueryProxy.new(association_target_class(name),
|
547
539
|
associations[name],
|
548
|
-
{
|
549
|
-
query_proxy: query_proxy,
|
540
|
+
{query_proxy: query_proxy,
|
550
541
|
context: "#{query_proxy.context || self.name}##{name}",
|
551
542
|
optional: query_proxy.optional?,
|
552
543
|
association_labels: options[:labels],
|
@@ -578,7 +569,7 @@ module ActiveGraph::Node
|
|
578
569
|
|
579
570
|
def default_association_query_proxy
|
580
571
|
ActiveGraph::Node::Query::QueryProxy.new("::#{self.name}".constantize, nil,
|
581
|
-
|
572
|
+
query_proxy: nil, context: self.name.to_s)
|
582
573
|
end
|
583
574
|
|
584
575
|
def build_association(macro, direction, name, options)
|
@@ -33,7 +33,6 @@ module ActiveGraph
|
|
33
33
|
# @option options [String, Symbol] :rel_var Same as above but pertaining to a relationship identifier
|
34
34
|
# @option options [Range, Integer, Symbol, Hash] :rel_length A Range, a Integer, a Hash or a Symbol to indicate the variable-length/fixed-length
|
35
35
|
# qualifier of the relationship. See http://neo4jrb.readthedocs.org/en/latest/Querying.html#variable-length-relationships.
|
36
|
-
# @option options [Neo4j::Driver] :driver The driver to be used for this query
|
37
36
|
# @option options [ActiveGraph::Node] :source_object The node instance at the start of the QueryProxy chain
|
38
37
|
# @option options [QueryProxy] :query_proxy An existing QueryProxy chain upon which this new object should be built
|
39
38
|
#
|
@@ -317,12 +316,6 @@ module ActiveGraph
|
|
317
316
|
"result_#{(association || model).try(:name)}#{index}".downcase.tr(':', '').to_sym
|
318
317
|
end
|
319
318
|
|
320
|
-
def _driver
|
321
|
-
(@driver || (@model && @model.neo4j_driver)).tap do |driver|
|
322
|
-
fail 'No driver found!' if driver.nil?
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
319
|
def _association_arrow(properties = {}, create = false)
|
327
320
|
@association && @association.arrow_cypher(@rel_var, properties, create, false, @rel_length)
|
328
321
|
end
|
@@ -357,9 +350,9 @@ module ActiveGraph
|
|
357
350
|
private
|
358
351
|
|
359
352
|
def instance_vars_from_options!(options)
|
360
|
-
@node_var, @
|
353
|
+
@node_var, @source_object, @starting_query, @optional,
|
361
354
|
@start_object, @query_proxy, @chain_level, @association_labels,
|
362
|
-
@rel_length = options.values_at(:node, :
|
355
|
+
@rel_length = options.values_at(:node, :source_object, :starting_query, :optional,
|
363
356
|
:start_object, :query_proxy, :chain_level, :association_labels, :rel_length)
|
364
357
|
end
|
365
358
|
|
@@ -10,7 +10,7 @@ module ActiveGraph
|
|
10
10
|
def defer_create(association_name, object, options = {})
|
11
11
|
clear_deferred_nodes_for_association(association_name) if options[:clear]
|
12
12
|
|
13
|
-
deferred_nodes_for_association(association_name)
|
13
|
+
deferred_nodes_for_association(association_name).concat(Array(object))
|
14
14
|
end
|
15
15
|
|
16
16
|
def deferred_nodes_for_association(association_name)
|
@@ -7,16 +7,14 @@ module ActiveGraph::Relationship
|
|
7
7
|
module ClassMethods
|
8
8
|
# Returns the object with the specified neo4j id.
|
9
9
|
# @param [String,Integer] id of node to find
|
10
|
-
|
11
|
-
def find(id, driver = self.neo4j_driver)
|
10
|
+
def find(id)
|
12
11
|
fail "Unknown argument #{id.class} in find method (expected String or Integer)" if !(id.is_a?(String) || id.is_a?(Integer))
|
13
|
-
find_by_id(id
|
12
|
+
find_by_id(id)
|
14
13
|
end
|
15
14
|
|
16
15
|
# Loads the relationship using its neo_id.
|
17
|
-
def find_by_id(key
|
18
|
-
|
19
|
-
query ||= ActiveGraph::Base.new_query(options)
|
16
|
+
def find_by_id(key)
|
17
|
+
query = ActiveGraph::Base.new_query
|
20
18
|
result = query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first
|
21
19
|
fail RecordNotFound.new("Couldn't find #{name} with 'id'=#{key.inspect}", name, key) if result.blank?
|
22
20
|
result.r
|
data/lib/active_graph/shared.rb
CHANGED
@@ -10,18 +10,6 @@ module ActiveGraph
|
|
10
10
|
include ActiveModel::Serializers::JSON
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
# TODO: Deprecate neo4j_driver_name(name)
|
14
|
-
|
15
|
-
# remove?
|
16
|
-
def neo4j_driver
|
17
|
-
ActiveGraph::Base.driver
|
18
|
-
end
|
19
|
-
|
20
|
-
# remove?
|
21
|
-
def current_transaction
|
22
|
-
ActiveGraph::Base.current_transaction
|
23
|
-
end
|
24
|
-
|
25
13
|
# This should be used everywhere. Should make it easy
|
26
14
|
# to support a driver-per-model system
|
27
15
|
def neo4j_query(*args)
|
data/lib/active_graph/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activegraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.0.0.pre.beta.
|
4
|
+
version: 10.0.0.pre.beta.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge, Brian Underwood, Chris Grigg, Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|