neo4apis 0.0.2 → 0.0.3
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/neo4apis.rb +0 -2
- data/lib/neo4apis/base.rb +44 -21
- data/lib/neo4apis/query_buffer.rb +11 -2
- data/neo4apis.gemspec +1 -3
- metadata +3 -3
- data/lib/neo4apis/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6703750242a5bf7db9c935381dd13a2a02a3dd80
|
|
4
|
+
data.tar.gz: e2c20ffd72feac0aceaef04e20b543abbae9dd8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a468fa6fa75440aafde30ab50af48cffffb46f80df45830ae98005280e860034896c2464efa01c7841d1d4746fc06b7cf9e14ed971a031cddc61a2f8ca83368
|
|
7
|
+
data.tar.gz: 64f6bdcfb90480b494f141d2458e978556dc31d2671e4d056845b40f3e67570a601c804f072cd2f1529fc5267b5067ab61de17032c71458cea1384bb26ab2186
|
data/lib/neo4apis.rb
CHANGED
data/lib/neo4apis/base.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
module Neo4Apis
|
|
2
2
|
class Base
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
UUID_FIELDS = {}
|
|
5
4
|
NODE_PROXIES = {}
|
|
6
5
|
IMPORTERS = {}
|
|
7
6
|
|
|
8
7
|
attr_reader :options
|
|
9
8
|
|
|
10
9
|
def initialize(neo4j_session, options = {})
|
|
11
|
-
@buffer = QueryBuffer.new(neo4j_session)
|
|
10
|
+
@buffer = QueryBuffer.new(neo4j_session, options[:flush_size] || self.class.default_flush_size)
|
|
12
11
|
@options = options
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
UUID_FIELDS.each do |label, uuid_field|
|
|
14
|
+
@buffer << create_constraint_query(label, uuid_field)
|
|
15
|
+
end
|
|
16
|
+
@buffer.flush
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def add_node(label, props = {})
|
|
17
20
|
require_batch
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
raise ArgumentError, "No UUID specified for label `#{label}`" if not node_proxy
|
|
22
|
+
raise ArgumentError, "No UUID specified for label `#{label}`" if not UUID_FIELDS[label.to_sym]
|
|
21
23
|
|
|
22
|
-
node_proxy.new(
|
|
24
|
+
self.class.node_proxy(label).new(props).tap do |node_proxy|
|
|
23
25
|
@buffer << create_node_query(node_proxy)
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -38,7 +40,7 @@ module Neo4Apis
|
|
|
38
40
|
|
|
39
41
|
instance_eval &block
|
|
40
42
|
|
|
41
|
-
@buffer.
|
|
43
|
+
@buffer.close
|
|
42
44
|
ensure
|
|
43
45
|
@in_batch = false
|
|
44
46
|
end
|
|
@@ -47,49 +49,70 @@ module Neo4Apis
|
|
|
47
49
|
self.instance_exec object, &IMPORTERS[label.to_sym]
|
|
48
50
|
end
|
|
49
51
|
|
|
52
|
+
def self.prefix(prefix)
|
|
53
|
+
@prefix = prefix
|
|
54
|
+
end
|
|
55
|
+
|
|
50
56
|
def self.importer(label, &block)
|
|
51
57
|
IMPORTERS[label.to_sym] = block
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
def self.uuid(label, uuid_field)
|
|
55
|
-
|
|
61
|
+
UUID_FIELDS[label.to_sym] = uuid_field.to_sym
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.node_proxy(label)
|
|
65
|
+
uuid_field = UUID_FIELDS[label.to_sym]
|
|
66
|
+
|
|
67
|
+
NODE_PROXIES[label.to_sym] ||= node_proxy_from_uuid(label, uuid_field)
|
|
56
68
|
end
|
|
57
69
|
|
|
58
70
|
def self.node_proxy_from_uuid(label, uuid_field)
|
|
59
|
-
Struct.new(:
|
|
60
|
-
const_set(:UUID_FIELD, uuid_field)
|
|
71
|
+
Struct.new(:props) do
|
|
72
|
+
const_set(:UUID_FIELD, uuid_field.to_sym)
|
|
73
|
+
const_set(:LABEL, label.to_sym)
|
|
74
|
+
|
|
75
|
+
def uuid_field
|
|
76
|
+
self.class::UUID_FIELD
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def label
|
|
80
|
+
self.class::LABEL
|
|
81
|
+
end
|
|
61
82
|
|
|
62
83
|
def uuid_value
|
|
63
84
|
raise ArgumentError, "props does not have UUID field `#{uuid_field}` for #{self.inspect}" if not props.has_key?(uuid_field)
|
|
64
85
|
|
|
65
86
|
props[uuid_field]
|
|
66
87
|
end
|
|
67
|
-
|
|
68
|
-
def uuid_field
|
|
69
|
-
self.class::UUID_FIELD
|
|
70
|
-
end
|
|
71
88
|
end
|
|
72
89
|
end
|
|
73
90
|
|
|
91
|
+
def self.default_flush_size
|
|
92
|
+
500
|
|
93
|
+
end
|
|
94
|
+
|
|
74
95
|
private
|
|
75
96
|
|
|
76
97
|
def create_node_query(node_proxy)
|
|
77
98
|
Neo4j::Core::Query.new.
|
|
78
|
-
merge(node: {node_proxy.label => {node_proxy.uuid_field => node_proxy.uuid_value}}).
|
|
99
|
+
merge(node: {self.class.full_label(node_proxy.label) => {node_proxy.uuid_field => node_proxy.uuid_value}}).
|
|
79
100
|
on_create_set(node: node_proxy.props)
|
|
80
101
|
end
|
|
81
102
|
|
|
82
103
|
def create_relationship_query(type, source, target, props)
|
|
83
104
|
Neo4j::Core::Query.new.
|
|
84
|
-
match(source: {source.label => {source.uuid_field => source.uuid_value}}).
|
|
85
|
-
match(target: {target.label => {target.uuid_field => target.uuid_value}}).
|
|
105
|
+
match(source: {self.class.full_label(source.label) => {source.uuid_field => source.uuid_value}}).
|
|
106
|
+
match(target: {self.class.full_label(target.label) => {target.uuid_field => target.uuid_value}}).
|
|
86
107
|
merge("source-[:#{type}]->target")
|
|
87
108
|
end
|
|
88
109
|
|
|
89
|
-
def
|
|
90
|
-
|
|
110
|
+
def create_constraint_query(label, uuid_field)
|
|
111
|
+
Neo4j::Core::Query.new.create("CONSTRAINT ON (node:#{self.class.full_label(label)}) ASSERT node.#{uuid_field} IS UNIQUE")
|
|
112
|
+
end
|
|
91
113
|
|
|
92
|
-
|
|
114
|
+
def self.full_label(label)
|
|
115
|
+
"#{@prefix}#{label}".to_sym
|
|
93
116
|
end
|
|
94
117
|
|
|
95
118
|
def require_batch
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module Neo4Apis
|
|
2
2
|
class QueryBuffer < Array
|
|
3
3
|
|
|
4
|
-
def initialize(neo4j_session)
|
|
4
|
+
def initialize(neo4j_session, flush_size)
|
|
5
5
|
@neo4j_session = neo4j_session
|
|
6
|
+
@flush_size = flush_size
|
|
6
7
|
|
|
7
8
|
uri = URI.parse(@neo4j_session.resource_url)
|
|
8
9
|
|
|
@@ -15,17 +16,25 @@ module Neo4Apis
|
|
|
15
16
|
super()
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
def <<(query)
|
|
20
|
+
flush if size >= @flush_size
|
|
21
|
+
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
18
25
|
def flush
|
|
19
26
|
execute
|
|
20
27
|
|
|
21
28
|
clear
|
|
22
29
|
end
|
|
23
30
|
|
|
31
|
+
def close
|
|
32
|
+
flush
|
|
33
|
+
end
|
|
24
34
|
|
|
25
35
|
private
|
|
26
36
|
|
|
27
37
|
def execute
|
|
28
|
-
puts "request_body_data", request_body_data.inspect
|
|
29
38
|
@faraday_connection.post do |req|
|
|
30
39
|
req.url '/db/data/transaction/commit'
|
|
31
40
|
req.headers['Accept'] = 'application/json; charset=UTF-8'
|
data/neo4apis.gemspec
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
lib = File.expand_path('../lib/', __FILE__)
|
|
2
2
|
$:.unshift lib unless $:.include?(lib)
|
|
3
3
|
|
|
4
|
-
require 'neo4apis/version'
|
|
5
|
-
|
|
6
4
|
Gem::Specification.new do |s|
|
|
7
5
|
s.name = "neo4apis"
|
|
8
|
-
s.version =
|
|
6
|
+
s.version = '0.0.3'
|
|
9
7
|
s.required_ruby_version = ">= 1.9.1"
|
|
10
8
|
|
|
11
9
|
s.authors = "Brian Underwood"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neo4apis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Underwood
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-10-
|
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -50,7 +50,6 @@ files:
|
|
|
50
50
|
- lib/neo4apis.rb
|
|
51
51
|
- lib/neo4apis/base.rb
|
|
52
52
|
- lib/neo4apis/query_buffer.rb
|
|
53
|
-
- lib/neo4apis/version.rb
|
|
54
53
|
- neo4apis.gemspec
|
|
55
54
|
homepage: https://github.com/neo4jrb/neo4apis/
|
|
56
55
|
licenses:
|
|
@@ -77,3 +76,4 @@ signing_key:
|
|
|
77
76
|
specification_version: 4
|
|
78
77
|
summary: An API to import web API data to neo4j
|
|
79
78
|
test_files: []
|
|
79
|
+
has_rdoc:
|
data/lib/neo4apis/version.rb
DELETED