neo4j-http 1.0.2 → 1.1.0

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: 3526e27e1765f572d398e295580e875cb589f02ced49dbf4963a52342400eff7
4
- data.tar.gz: 693b3f5ede2c474f268c097298340ffa38ef8455e901b89406bf8af32ecc3aed
3
+ metadata.gz: 5f8fbb77721438b9be5c5ccea0335ae4c8d0ae54332cbbfbb5d1bba4e99b25ca
4
+ data.tar.gz: 4c3e90c5df2d04a6925105e537f7197b4753dd3c39fd7421c10b253c73c5c50e
5
5
  SHA512:
6
- metadata.gz: 985b031ef8f0c77cd9f8705d72c462f69c95f0fea00302dba11c15857aaa8f4a3515b29a4cf04b90d5970724304cb1179a357391621178e2287958b95d12a1f6
7
- data.tar.gz: 4e8e6dab0c4bcfc83fb897d6f3eb42b4abef3df63ff170ff3e78e1263045089f96c8e1c6b46bd7e9f5e969d5b35fbdc4801a282293235a00bcf774a4a76b1999
6
+ metadata.gz: 13f5ad50bbe007ef8bc5a5b637c3b888ecc698dc17d9704436f23de17fa7ae40a8eddb3bb107b0171cfc6780b3b3a7f66a04a8abb434354cdcd0d9cc42b6a788
7
+ data.tar.gz: 227d3ca7d78a676e00ac33132fd95008a9f906f0f83422a6878fa07deaa275c76fec037f2756393dd0ca6358360384a89ea93715653399bdf7f3ac75b22cc4ad
@@ -5,7 +5,7 @@ module Neo4j
5
5
  class Client
6
6
  CYPHER_CLIENT_METHODS = %i[execute_cypher].freeze
7
7
  NODE_CLIENT_METHODS = %i[delete_node find_node_by find_nodes_by upsert_node].freeze
8
- RELATIONSHIP_CLIENT_METHODS = %i[delete_relationship upsert_relationship].freeze
8
+ RELATIONSHIP_CLIENT_METHODS = %i[delete_relationship upsert_relationship delete_relationship_on_primary_key].freeze
9
9
  CLIENT_METHODS = (CYPHER_CLIENT_METHODS + NODE_CLIENT_METHODS + RELATIONSHIP_CLIENT_METHODS).freeze
10
10
 
11
11
  class << self
@@ -4,8 +4,9 @@ module Neo4j
4
4
  module Http
5
5
  class Node < ObjectWrapper
6
6
  DEFAULT_PRIMARY_KEY_NAME = "uuid"
7
- def initialize(label:, graph_node_primary_key_name: DEFAULT_PRIMARY_KEY_NAME, **attributes)
7
+ def initialize(label:, primary_key_name: DEFAULT_PRIMARY_KEY_NAME, **attributes)
8
8
  super
9
+ @key_value = @attributes.delete(key_name)
9
10
  end
10
11
  end
11
12
  end
@@ -9,11 +9,10 @@ module Neo4j
9
9
  :label,
10
10
  :original_attributes
11
11
 
12
- def initialize(label:, graph_node_primary_key_name: nil, **attributes)
12
+ def initialize(label:, primary_key_name: nil, **attributes)
13
13
  @original_attributes = (attributes || {}).with_indifferent_access
14
14
  @attributes = original_attributes.dup.with_indifferent_access
15
- @key_name = graph_node_primary_key_name
16
- @key_value = @attributes.delete(key_name)
15
+ @key_name = primary_key_name
17
16
  @label = label
18
17
  end
19
18
 
@@ -3,6 +3,10 @@
3
3
  module Neo4j
4
4
  module Http
5
5
  class Relationship < ObjectWrapper
6
+ def initialize(label:, primary_key_name: nil, **attributes)
7
+ super
8
+ @key_value = @attributes.dig(key_name)
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -43,7 +43,7 @@ module Neo4j
43
43
  results&.first
44
44
  end
45
45
 
46
- def find_relationship(from:, relationship:, to:)
46
+ def find_relationships(from:, relationship:, to:)
47
47
  from_match_clause = build_match_selector(:from, from)
48
48
  to_match_clause = build_match_selector(:to, to)
49
49
  relationship_clause = build_match_selector(:relationship, relationship)
@@ -52,13 +52,17 @@ module Neo4j
52
52
  RETURN from, to, relationship
53
53
  CYPHER
54
54
 
55
- results = @cypher_client.execute_cypher(
55
+ @cypher_client.execute_cypher(
56
56
  cypher,
57
57
  from: from,
58
58
  to: to,
59
59
  relationship: relationship,
60
60
  access_mode: "READ"
61
61
  )
62
+ end
63
+
64
+ def find_relationship(from:, relationship:, to:)
65
+ results = find_relationships(from: from, to: to, relationship: relationship)
62
66
  results&.first
63
67
  end
64
68
 
@@ -72,6 +76,7 @@ module Neo4j
72
76
  from_selector = build_match_selector(:from, from)
73
77
  to_selector = build_match_selector(:to, to)
74
78
  relationship_selector = build_match_selector(:relationship, relationship)
79
+
75
80
  cypher = <<-CYPHER
76
81
  MATCH (#{from_selector}) - [#{relationship_selector}] - (#{to_selector})
77
82
  WITH from, to, relationship
@@ -82,6 +87,23 @@ module Neo4j
82
87
  results = @cypher_client.execute_cypher(cypher, from: from, to: to)
83
88
  results&.first
84
89
  end
90
+
91
+ def delete_relationship_on_primary_key(relationship:)
92
+ # protection against mass deletion of relationships
93
+ return if relationship.key_name.nil?
94
+
95
+ relationship_selector = build_match_selector(:relationship, relationship)
96
+
97
+ cypher = <<-CYPHER
98
+ MATCH () - [#{relationship_selector}] - ()
99
+ WITH relationship
100
+ DELETE relationship
101
+ RETURN relationship
102
+ CYPHER
103
+
104
+ results = @cypher_client.execute_cypher(cypher, relationship: relationship)
105
+ results&.first
106
+ end
85
107
  end
86
108
  end
87
109
  end
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Http
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stawarz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-19 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport