Module: Neo4j::ActiveNode::Labels::Index::ClassMethods

Extended by:
Forwardable
Defined in:
lib/neo4j/active_node/labels/index.rb

Instance Method Summary collapse

Instance Method Details

#constraint(property, constraints = {type: :unique}) ⇒ Object

Creates a neo4j constraint on this class for given property

Examples:

Person.constraint :name, type: :unique


33
34
35
36
37
38
# File 'lib/neo4j/active_node/labels/index.rb', line 33

def constraint(property, constraints = {type: :unique})
  Neo4j::Session.on_next_session_available do
    declared_properties.constraint_or_fail!(property, id_property_name)
    schema_create_operation(:constraint, property, constraints)
  end
end

#constraint?(property) ⇒ Boolean

Returns:



61
62
63
# File 'lib/neo4j/active_node/labels/index.rb', line 61

def constraint?(property)
  mapped_label.unique_constraints[:property_keys].include?([property])
end

#drop_constraint(property, constraint = {type: :unique}) ⇒ Object

Parameters:

  • property (Symbol)

    The name of the property constraint to be dropped

  • constraint (Hash) (defaults to: {type: :unique})

    The constraint type to be dropped.



50
51
52
53
54
55
# File 'lib/neo4j/active_node/labels/index.rb', line 50

def drop_constraint(property, constraint = {type: :unique})
  Neo4j::Session.on_next_session_available do
    declared_properties[property].unconstraint! if declared_properties[property]
    schema_drop_operation(:constraint, property, constraint)
  end
end

#drop_index(property, options = {}) ⇒ Object

Parameters:

  • property (Symbol)

    The name of the property index to be dropped



41
42
43
44
45
46
# File 'lib/neo4j/active_node/labels/index.rb', line 41

def drop_index(property, options = {})
  Neo4j::Session.on_next_session_available do
    declared_properties[property].unindex! if declared_properties[property]
    schema_drop_operation(:index, property, options)
  end
end

#index(property) ⇒ Object

Creates a Neo4j index on given property

This can also be done on the property directly, see Neo4j::ActiveNode::Property::ClassMethods#property.

Examples:

class Person
   include Neo4j::ActiveNode
   property :name
   index :name
 end

Parameters:

  • property (Symbol)

    the property we want a Neo4j index on



22
23
24
25
26
27
# File 'lib/neo4j/active_node/labels/index.rb', line 22

def index(property)
  Neo4j::Session.on_next_session_available do |_|
    declared_properties.index_or_fail!(property, id_property_name)
    schema_create_operation(:index, property)
  end
end

#index?(property) ⇒ Boolean

Returns:



57
58
59
# File 'lib/neo4j/active_node/labels/index.rb', line 57

def index?(property)
  mapped_label.indexes[:property_keys].include?([property])
end