Class: Redgraph::Graph
- Inherits:
-
Object
- Object
- Redgraph::Graph
- Includes:
- EdgeMethods, NodeMethods, Util
- Defined in:
- lib/redgraph/graph.rb,
lib/redgraph/graph/edge_methods.rb,
lib/redgraph/graph/node_methods.rb
Defined Under Namespace
Modules: EdgeMethods, NodeMethods
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#graph_name ⇒ Object
Returns the value of attribute graph_name.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes an existing graph.
-
#get_label(id) ⇒ String?
Label.
-
#get_property(id) ⇒ String?
Property.
-
#get_relationship_type(id) ⇒ String?
Relationship type.
-
#initialize(graph_name, redis_options = {}) ⇒ Graph
constructor
A new instance of Graph.
-
#labels ⇒ Array
Existing labels.
-
#list ⇒ Array
Existing graph names.
-
#module_version ⇒ Object
Returns the version of the RedisGraph module.
-
#properties ⇒ Array
Existing properties.
-
#query(cmd) ⇒ Object
You can run custom cypher queries.
-
#relationship_types ⇒ Array
Existing relationship types.
Methods included from Util
#escape_value, #properties_to_string
Methods included from EdgeMethods
#add_edge, #count_edges, #edges, #merge_edge
Methods included from NodeMethods
#add_node, #count_nodes, #destroy_node, #find_node_by_id, #merge_node, #nodes, #update_node
Constructor Details
#initialize(graph_name, redis_options = {}) ⇒ Graph
Returns a new instance of Graph.
18 19 20 21 22 23 |
# File 'lib/redgraph/graph.rb', line 18 def initialize(graph_name, = {}) @graph_name = graph_name @connection = Redis.new() @module_version = module_version raise ServerError, "Can't find RedisGraph module" unless @module_version end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
12 13 14 |
# File 'lib/redgraph/graph.rb', line 12 def connection @connection end |
#graph_name ⇒ Object
Returns the value of attribute graph_name.
12 13 14 |
# File 'lib/redgraph/graph.rb', line 12 def graph_name @graph_name end |
Instance Method Details
#delete ⇒ Object
Deletes an existing graph
35 36 37 38 39 40 41 |
# File 'lib/redgraph/graph.rb', line 35 def delete @connection.call("GRAPH.DELETE", graph_name) rescue Redis::CommandError => e # Catch exception if the graph was already deleted return nil if e. =~ /ERR Invalid graph operation on empty key/ raise e end |
#get_label(id) ⇒ String?
Returns label.
78 79 80 81 |
# File 'lib/redgraph/graph.rb', line 78 def get_label(id) @labels ||= labels @labels[id] || (@labels = labels)[id] end |
#get_property(id) ⇒ String?
Returns property.
86 87 88 89 |
# File 'lib/redgraph/graph.rb', line 86 def get_property(id) @properties ||= properties @properties[id] || (@properties = properties)[id] end |
#get_relationship_type(id) ⇒ String?
Returns relationship type.
94 95 96 97 |
# File 'lib/redgraph/graph.rb', line 94 def get_relationship_type(id) @relationship_types ||= relationship_types @relationship_types[id] || (@relationship_types = relationship_types)[id] end |
#labels ⇒ Array
Returns Existing labels.
51 52 53 54 |
# File 'lib/redgraph/graph.rb', line 51 def labels result = _query("CALL db.labels()") result.resultset.map(&:values).flatten end |
#list ⇒ Array
Returns Existing graph names.
45 46 47 |
# File 'lib/redgraph/graph.rb', line 45 def list @connection.call("GRAPH.LIST") end |
#module_version ⇒ Object
Returns the version of the RedisGraph module
27 28 29 30 31 |
# File 'lib/redgraph/graph.rb', line 27 def module_version modules = @connection.call("MODULE", "LIST") module_graph = modules.detect { |_, name, _, version| name == 'graph' } module_graph[3] if module_graph end |
#properties ⇒ Array
Returns Existing properties.
58 59 60 61 |
# File 'lib/redgraph/graph.rb', line 58 def properties result = _query("CALL db.propertyKeys()") result.resultset.map(&:values).flatten end |
#query(cmd) ⇒ Object
You can run custom cypher queries
71 72 73 |
# File 'lib/redgraph/graph.rb', line 71 def query(cmd) _query(cmd).rows end |
#relationship_types ⇒ Array
Returns Existing relationship types.
65 66 67 68 |
# File 'lib/redgraph/graph.rb', line 65 def relationship_types result = _query("CALL db.relationshipTypes()") result.resultset.map(&:values).flatten end |