redgraph 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fd53776ff217146cd6ca4924da40a43f5bf929fad03b73b79f32d371ea955e8
4
- data.tar.gz: 551afc973f8e732ad532e74395e6c73251f14d68db73f667a207b234bd64163b
3
+ metadata.gz: 8b51ea5b1c1c11aab62f08cfe08508130f65def1a3b527ddcaf9419140c4e12a
4
+ data.tar.gz: 6518c572f6a4c14c733653acf1282c9b8473a8737b028a5695f93f953766f0bd
5
5
  SHA512:
6
- metadata.gz: dd7f88ae09acb7f09b6c8de949d4f31bbc52b12e4b914f035de99c7cd9b409c14eac3e592f834cc968517b796fed0cf3a085f7eba4915e630b2e66c424ae9870
7
- data.tar.gz: 979aac39193d3150441ddf5baca14772a35c6cfd00f09df42752277aed3d955869822b2d97150209f1e71ad5ab95e566dc645d15d3e8262675dd858bd6fbb1dd
6
+ metadata.gz: 634966fdde2e4567654b9a2d3e77eb77b26b8d1c8def562deeef8015d0b798ef8c7a9dd993dd15eabeeac4e2cc32013b748649c3f599dcc524742edd67d0b252
7
+ data.tar.gz: 9dba064e18ded1c51b80eca7d17cf487e1748b31fcbc18be656d57dcbe70954c563f3e7ee7bcd6ed847e4d9e170b40c0a498007980642349f1a4aa1ba5f0c706
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.2.2] - 2022-05-15
2
+
3
+ - Nodes allow multiple labels
4
+ - Friendlier exception message when the RedisGraph module is missing
5
+
1
6
  ## [0.2.1]
2
7
 
3
8
  - Add NodeModel#destroy method
data/Gemfile.lock CHANGED
@@ -1,23 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redgraph (0.2.1)
4
+ redgraph (0.2.2)
5
5
  activesupport (>= 3.0.0)
6
6
  redis (~> 4)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.3.1)
11
+ activesupport (7.0.3)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
17
16
  coderay (1.1.3)
18
- concurrent-ruby (1.1.8)
17
+ concurrent-ruby (1.1.10)
19
18
  docile (1.3.5)
20
- i18n (1.8.10)
19
+ i18n (1.10.0)
21
20
  concurrent-ruby (~> 1.0)
22
21
  method_source (1.0.0)
23
22
  minitest (5.14.4)
@@ -25,7 +24,7 @@ GEM
25
24
  coderay (~> 1.1)
26
25
  method_source (~> 1.0)
27
26
  rake (13.0.3)
28
- redis (4.2.5)
27
+ redis (4.6.0)
29
28
  simplecov (0.21.2)
30
29
  docile (~> 1.1)
31
30
  simplecov-html (~> 0.11)
@@ -34,9 +33,9 @@ GEM
34
33
  simplecov_json_formatter (0.1.2)
35
34
  tzinfo (2.0.4)
36
35
  concurrent-ruby (~> 1.0)
37
- zeitwerk (2.4.2)
38
36
 
39
37
  PLATFORMS
38
+ arm64-darwin-21
40
39
  x86_64-darwin-20
41
40
 
42
41
  DEPENDENCIES
@@ -47,4 +46,4 @@ DEPENDENCIES
47
46
  simplecov (~> 0.21.2)
48
47
 
49
48
  BUNDLED WITH
50
- 2.2.15
49
+ 2.2.22
data/README.md CHANGED
@@ -36,13 +36,20 @@ Create a couple nodes:
36
36
 
37
37
  ```ruby
38
38
  actor = Redgraph::Node.new(label: 'actor', properties: {name: "Al Pacino"})
39
- => #<Redgraph::Node:0x00007f8d5f95cf88 @label="actor", @properties={:name=>"Al Pacino"}>
39
+ => #<Redgraph::Node:0x00007fce3baa0580 @id=nil, @labels=["actor"], @properties={"name"=>"Al Pacino"}>
40
40
  graph.add_node(actor)
41
- => #<Redgraph::Node:0x00007f8d5f95cf88 @id=0, @label="actor", @properties={:name=>"Al Pacino"}>
41
+ => #<Redgraph::Node:0x00007fce3baa0580 @id=0, @labels=["actor"], @properties={"name"=>"Al Pacino"}>
42
42
  film = Redgraph::Node.new(label: 'film', properties: {name: "Scarface"})
43
- => #<Redgraph::Node:0x00007f8d5f85ccc8 @label="film", @properties={:name=>"Scarface"}>
43
+ => #<Redgraph::Node:0x00007fce3e8c6c48 @id=nil, @labels=["film"], @properties={"name"=>"Scarface"}>
44
44
  graph.add_node(film)
45
- => #<Redgraph::Node:0x00007f8d5f85ccc8 @id=1, @label="film", @properties={:name=>"Scarface"}>
45
+ => #<Redgraph::Node:0x00007fce3e8c6c48 @id=1, @labels=["film"], @properties={"name"=>"Scarface"}>
46
+ ```
47
+
48
+ Nodes might have multiple labels, although they're not supported by RedisGraph yet (you can track the feature progress [here](https://github.com/RedisGraph/RedisGraph/pull/1561)):
49
+
50
+ ```ruby
51
+ item = Redgraph::Node.new(labels: ['film', 'drama'], properties: {name: "Casino"})
52
+ => #<Redgraph::Node:0x00007fce3bc73308 @id=nil, @labels=["film", "drama"], @properties={"name"=>"Casino"}>
46
53
  ```
47
54
 
48
55
  Create an edge between those nodes:
@@ -50,7 +57,7 @@ Create an edge between those nodes:
50
57
  ```ruby
51
58
  edge = Redgraph::Edge.new(src: actor, dest: film, type: 'ACTOR_IN', properties: {role: "Tony Montana"})
52
59
  => #<Redgraph::Edge:0x00007f8d5f9ae3d8 @dest=#<Redgraph::Node:0x00007f8d5f85ccc8 @id=1, @label="film", @properties={:name=>"Scarface"}>, @dest_id=1, @properties={:role=>"Tony Montana"}, @src=#<Redgraph::Node:0x00007f8d5f95cf88 @id=0, @label="actor", @properties={:name=>"Al Pacino"}>, @src_id=0, @type="ACTOR_IN">
53
- @graph.add_edge(edge)
60
+ graph.add_edge(edge)
54
61
  => #<Redgraph::Edge:0x00007f8d5f9ae3d8 @dest=#<Redgraph::Node:0x00007f8d5f85ccc8 @id=1, @label="film", @properties={:name=>"Scarface"}>, @dest_id=1, @id=0, @properties={:role=>"Tony Montana"}, @src=#<Redgraph::Node:0x00007f8d5f95cf88 @id=0, @label="actor", @properties={:name=>"Al Pacino"}>, @src_id=0, @type="ACTOR_IN">
55
62
  ```
56
63
 
@@ -64,52 +71,52 @@ graph.merge_node(film)
64
71
  Same with edges:
65
72
 
66
73
  ```ruby
67
- @graph.merge_edge(edge)
74
+ graph.merge_edge(edge)
68
75
  => #<Redgraph::Edge:0x00007f8d5f9ae3d8 @dest=#<Redgraph::Node:0x00007f8d5f85ccc8 @id=1, @label="film", @properties={:name=>"Scarface"}>, @dest_id=1, @id=0, @properties={:role=>"Tony Montana"}, @src=#<Redgraph::Node:0x00007f8d5f95cf88 @id=0, @label="actor", @properties={:name=>"Al Pacino"}>, @src_id=0, @type="ACTOR_IN">
69
76
  ```
70
77
 
71
78
  Find a node by id:
72
79
 
73
80
  ```ruby
74
- @graph.find_node_by_id(1)
81
+ graph.find_node_by_id(1)
75
82
  => #<Redgraph::Node:0x00007f8d5c2c6e88 @id=1, @label="film", @properties={"name"=>"Scarface"}>
76
83
  ```
77
84
 
78
85
  To get all nodes:
79
86
 
80
87
  ```ruby
81
- @graph.nodes
88
+ graph.nodes
82
89
  => [#<Redgraph::Node:0x00007f8d5c2ee0a0 @id=0, @label="actor", @properties={"name"=>"Al Pacino"}>, #<Redgraph::Node:0x00007f8d5c2edfd8 @id=1, @label="film", @properties={"name"=>"Scarface"}>]
83
90
  ```
84
91
 
85
92
  Optional filters that can be combined:
86
93
 
87
94
  ```ruby
88
- @graph.nodes(label: 'actor')
89
- @graph.nodes(properties: {name: "Al Pacino"})
90
- @graph.nodes(limit: 10, skip: 20)
95
+ graph.nodes(label: 'actor')
96
+ graph.nodes(properties: {name: "Al Pacino"})
97
+ graph.nodes(limit: 10, skip: 20)
91
98
  ```
92
99
 
93
100
  Counting nodes
94
101
 
95
102
  ```ruby
96
- @graph.count_nodes(label: 'actor')
103
+ graph.count_nodes(label: 'actor')
97
104
  => 1
98
105
  ```
99
106
 
100
107
  Getting edges:
101
108
 
102
109
  ```ruby
103
- @graph.edges
104
- @graph.edges(src: actor, dest: film)
105
- @graph.edges(kind: 'FRIEND_OF', limit: 10, skip: 20)
106
- @graph.count_edges
110
+ graph.edges
111
+ graph.edges(src: actor, dest: film)
112
+ graph.edges(kind: 'FRIEND_OF', limit: 10, skip: 20)
113
+ graph.count_edges
107
114
  ```
108
115
 
109
116
  Running custom queries
110
117
 
111
118
  ```ruby
112
- @graph.query("MATCH (src)-[edge:FRIEND_OF]->(dest) RETURN src, edge")
119
+ graph.query("MATCH (src)-[edge:FRIEND_OF]->(dest) RETURN src, edge")
113
120
  ```
114
121
 
115
122
  ### NodeModel
@@ -129,7 +136,7 @@ And this will give you stuff such as
129
136
  ```ruby
130
137
  Actor.count
131
138
  john = Actor.new(name: "John Travolta")
132
- john.add_to_graph # Will add the node to the graph
139
+ john.add_to_graph
133
140
  john.add_relation(type: "ACTED_IN", node: film, properties: {role: "Tony Manero"})
134
141
  john.reload
135
142
  john.destroy
@@ -159,6 +166,15 @@ You can also run `bin/console` for an interactive prompt that will allow you to
159
166
 
160
167
  To install this gem onto your local machine, run `bundle exec rake install`.
161
168
 
169
+ ### Installing RedisGraph
170
+
171
+ If you're using an Apple silicon mac you might want to use the docker image: I've had issues compiling the module (OpenMP problems). Just do a:
172
+
173
+ docker run -p 6380:6379 -it --rm redislabs/redisgraph
174
+ TEST_REDIS_URL=redis://localhost:6380/0 be rake test
175
+
176
+ I'm using port 6380 to not interphere with the other redis instance.
177
+
162
178
  ## Contributing
163
179
 
164
180
  Bug reports and pull requests are welcome on GitHub at https://github.com/pzac/redgraph.
@@ -19,7 +19,7 @@ module Redgraph
19
19
  @graph_name = graph_name
20
20
  @connection = Redis.new(redis_options)
21
21
  @module_version = module_version
22
- raise ServerError unless @module_version
22
+ raise ServerError, "Can't find RedisGraph module" unless @module_version
23
23
  end
24
24
 
25
25
  # Returns the version of the RedisGraph module
data/lib/redgraph/node.rb CHANGED
@@ -4,14 +4,19 @@ module Redgraph
4
4
  class Node
5
5
  include Util
6
6
 
7
- attr_accessor :id, :label, :properties
7
+ attr_accessor :id, :labels, :properties
8
8
 
9
- def initialize(label: nil, properties: nil, id: nil)
9
+ def initialize(label: nil, properties: nil, id: nil, labels: nil)
10
10
  @id = id
11
- @label = label
11
+ raise(Error, "You can either define a single label or a label array") if label && labels
12
+ @labels = labels || (label ? [label] : [])
12
13
  @properties = (properties || {}).with_indifferent_access
13
14
  end
14
15
 
16
+ def label
17
+ labels.first
18
+ end
19
+
15
20
  def persisted?
16
21
  id.present?
17
22
  end
@@ -21,7 +26,7 @@ module Redgraph
21
26
  end
22
27
 
23
28
  def to_query_string(item_alias: 'node')
24
- _label = ":#{label}" if label
29
+ _label = labels.map {|l| ":`#{l}`"}.join
25
30
  "(#{item_alias}#{_label} #{properties_to_string(properties)})"
26
31
  end
27
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redgraph
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
data/test/node_test.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class NodeTest < Minitest::Test
6
+ def test_single_labels
7
+ node = Redgraph::Node.new(label: "film")
8
+ assert_equal(["film"], node.labels)
9
+ assert_equal("film", node.label)
10
+ end
11
+
12
+ def test_multiple_labels
13
+ node = Redgraph::Node.new(labels: ["film", "drama"])
14
+ assert_equal(["film", "drama"], node.labels)
15
+ assert_equal("film", node.label)
16
+ end
17
+
18
+ def test_conflicting_labels
19
+ assert_raises(Redgraph::Error) do
20
+ node = Redgraph::Node.new(labels: ["film", "drama"], label: "film")
21
+ end
22
+ end
23
+ end
data/test/test_helper.rb CHANGED
@@ -16,7 +16,8 @@ require "minitest/autorun"
16
16
  require "pry"
17
17
 
18
18
  unless $REDIS_URL = ENV['TEST_REDIS_URL']
19
- puts "To run the tests you need to define the TEST_REDIS_URL environment variable"
19
+ puts "To run the tests you need to define the TEST_REDIS_URL environment variable. Ex:"
20
+ puts " TEST_REDIS_URL=redis://localhost:6379/0"
20
21
  exit(1)
21
22
  end
22
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Zaccagnini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -79,6 +79,7 @@ files:
79
79
  - test/node_model_labels_test.rb
80
80
  - test/node_model_persistence_test.rb
81
81
  - test/node_model_test.rb
82
+ - test/node_test.rb
82
83
  - test/redgraph_test.rb
83
84
  - test/test_helper.rb
84
85
  homepage: https://github.com/pzac/redgraph
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
- rubygems_version: 3.2.3
107
+ rubygems_version: 3.2.22
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: A simple RedisGraph client