lib/redgraph/node_model/class_methods.rb in redgraph-0.2.0 vs lib/redgraph/node_model/class_methods.rb in redgraph-0.2.1

- old
+ new

@@ -1,27 +1,28 @@ module Redgraph module NodeModel module ClassMethods # Returns an array of nodes. Options: # + # - label: filter by label # - properties: filter by properties # - order: node.name ASC, node.year DESC # - limit: number of items # - skip: items offset (useful for pagination) # - def all(properties: {}, limit: nil, skip: nil, order: nil) + def all(label: nil, properties: {}, limit: nil, skip: nil, order: nil) graph.nodes(label: label, properties: properties_plus_type(properties), limit: limit, skip: skip, order: nil).map do |node| reify_from_node(node) end end # Returns the number of nodes with the current label. Options: # # - properties: filter by properties # - def count(properties: nil) + def count(label: nil, properties: nil) graph.count_nodes(label: label, properties: properties_plus_type(properties)) end # Finds a node by id. Returns nil if not found # @@ -53,14 +54,20 @@ # if available - otherwise they stay NodeObjects. # # Returns an array of rows. # def query(cmd) + raise MissingGraphError unless graph + graph.query(cmd).map do |row| row.map do |item| item.is_a?(Node) ? reify_from_node(item) : item end end + end + + def create(properties) + new(**properties).add_to_graph end private def default_label