neo4j-core 6.0.4 → 6.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j/core/label.rb +127 -0
- data/neo4j-core.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6da77aea23bd02b9be16de12f73ae5152035b11
|
4
|
+
data.tar.gz: f724c34ca0736fd6718687329097c8ade8c28c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 591c73f031b2645e33bad385124397ba6710f3540d0ad31682e7679e50e6e7809c0e6fd2874d0bf1b8799589309535b574ca741922a3fc2778d9bb5b544e0b40
|
7
|
+
data.tar.gz: bc1869acd81835775d2f7e6207279388ed0c8626b73355860e33e89fc02cb9041d778de608781e1c7bfd10a8a6c0ff1867524d9eb4b8dca52a08dac3c9a4513f
|
data/lib/neo4j-core/version.rb
CHANGED
@@ -0,0 +1,127 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Core
|
3
|
+
class Label
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name, session)
|
7
|
+
@name = name
|
8
|
+
@session = session
|
9
|
+
schema_threads = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_index(property, options = {})
|
13
|
+
puts "create_index(#{property.inspect}, #{options.inspect})"
|
14
|
+
validate_index_options!(options)
|
15
|
+
properties = property.is_a?(Array) ? property.join(',') : property
|
16
|
+
schema_query("CREATE INDEX ON :`#{@name}`(#{properties})")
|
17
|
+
end
|
18
|
+
|
19
|
+
def drop_index(property, options = {})
|
20
|
+
puts "drop_index(#{property.inspect}, #{options.inspect})"
|
21
|
+
validate_index_options!(options)
|
22
|
+
schema_query("DROP INDEX ON :`#{@name}`(#{property})")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a neo4j constraint on a property
|
26
|
+
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
27
|
+
# @example
|
28
|
+
# label = Neo4j::Label.create(:person, session)
|
29
|
+
# label.create_constraint(:name, {type: :unique}, session)
|
30
|
+
#
|
31
|
+
def create_constraint(property, constraints)
|
32
|
+
puts "create_constraint(#{property.inspect}, #{constraints.inspect})"
|
33
|
+
cypher = case constraints[:type]
|
34
|
+
when :unique
|
35
|
+
"CREATE CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE"
|
36
|
+
else
|
37
|
+
fail "Not supported constrain #{constraints.inspect} for property #{property} (expected :type => :unique)"
|
38
|
+
end
|
39
|
+
schema_query(cypher)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Drops a neo4j constraint on a property
|
43
|
+
# See http://docs.neo4j.org/chunked/stable/query-constraints.html
|
44
|
+
# @example
|
45
|
+
# label = Neo4j::Label.create(:person, session)
|
46
|
+
# label.create_constraint(:name, {type: :unique}, session)
|
47
|
+
# label.drop_constraint(:name, {type: :unique}, session)
|
48
|
+
#
|
49
|
+
def drop_constraint(property, constraint)
|
50
|
+
puts "drop_constraint(#{property.inspect}, #{constraint.inspect})"
|
51
|
+
cypher = case constraint[:type]
|
52
|
+
when :unique
|
53
|
+
"DROP CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE"
|
54
|
+
else
|
55
|
+
fail "Not supported constrain #{constraint.inspect}"
|
56
|
+
end
|
57
|
+
schema_query(cypher)
|
58
|
+
end
|
59
|
+
|
60
|
+
def indexes
|
61
|
+
@session.indexes_for_label(@name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def index?(property)
|
65
|
+
indexes.include?(property)
|
66
|
+
end
|
67
|
+
|
68
|
+
def uniqueness_constraints
|
69
|
+
@session.uniqueness_constraints_for_label(@name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def uniqueness_constraint?(property)
|
73
|
+
uniqueness_constraints.include?(property)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.wait_for_schema_changes(session)
|
77
|
+
schema_threads(session).map(&:join)
|
78
|
+
set_schema_threads(session, [])
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# Store schema threads on the session so that we can easily wait for all
|
84
|
+
# threads on a session regardless of label
|
85
|
+
def schema_threads
|
86
|
+
self.class.schema_threads(@session)
|
87
|
+
end
|
88
|
+
|
89
|
+
def schema_threads=(array)
|
90
|
+
self.class.set_schema_threads(@session, array)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.schema_threads(session)
|
94
|
+
session.instance_variable_get('@_schema_threads') || []
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.set_schema_threads(session, array)
|
98
|
+
session.instance_variable_set('@_schema_threads', array)
|
99
|
+
end
|
100
|
+
|
101
|
+
# If there is a transaction going on, this could block
|
102
|
+
# So we run in a thread and it will go through at the next opportunity
|
103
|
+
def schema_query(cypher)
|
104
|
+
Thread.new do
|
105
|
+
begin
|
106
|
+
puts 'Starting transaction for schema query...'
|
107
|
+
@session.transaction do |tx|
|
108
|
+
puts 'Executing schema query...'
|
109
|
+
tx.query(cypher)
|
110
|
+
puts 'Executed schema query...'
|
111
|
+
end
|
112
|
+
rescue Exception => e
|
113
|
+
puts e.message
|
114
|
+
puts e.backtrace
|
115
|
+
end
|
116
|
+
end.tap do |thread|
|
117
|
+
schema_threads << thread
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def validate_index_options!(options)
|
122
|
+
return unless options[:type] && options[:type] != :exact
|
123
|
+
fail "Type #{options[:type]} is not supported"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/neo4j-core.gemspec
CHANGED
@@ -33,7 +33,7 @@ Neo4j-core provides classes and methods to work with the graph database Neo4j.
|
|
33
33
|
s.add_dependency('activesupport') # For ActiveSupport::Notifications
|
34
34
|
s.add_dependency('multi_json')
|
35
35
|
s.add_dependency('faraday_middleware-multi_json')
|
36
|
-
s.add_dependency('neo4j-rake_tasks', '
|
36
|
+
s.add_dependency('neo4j-rake_tasks', '>= 0.3.0')
|
37
37
|
|
38
38
|
s.add_development_dependency('pry')
|
39
39
|
s.add_development_dependency('yard')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge, Chris Grigg, Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -140,14 +140,14 @@ dependencies:
|
|
140
140
|
name: neo4j-rake_tasks
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: 0.3.0
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 0.3.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- lib/neo4j/core/cypher_session/responses/http.rb
|
286
286
|
- lib/neo4j/core/cypher_session/result.rb
|
287
287
|
- lib/neo4j/core/instrumentable.rb
|
288
|
+
- lib/neo4j/core/label.rb
|
288
289
|
- lib/neo4j/core/node.rb
|
289
290
|
- lib/neo4j/core/path.rb
|
290
291
|
- lib/neo4j/core/relationship.rb
|