module Neo4j::ActiveNode::Labels::Index::ClassMethods
Public Instance Methods
constraint(property, constraints = {type: :unique})
click to toggle source
Creates a neo4j constraint on this class for given property
@example
Person.constraint :name, type: :unique
# File lib/neo4j/active_node/labels/index.rb 33 def constraint(property, constraints = {type: :unique}) 34 Neo4j::Session.on_next_session_available do 35 declared_properties.constraint_or_fail!(property, id_property_name) 36 schema_create_operation(:constraint, property, constraints) 37 end 38 end
constraint?(property)
click to toggle source
# File lib/neo4j/active_node/labels/index.rb 61 def constraint?(property) 62 mapped_label.unique_constraints[:property_keys].include?([property]) 63 end
drop_constraint(property, constraint = {type: :unique})
click to toggle source
@param [Symbol] property The name of the property constraint to be dropped @param [Hash] constraint The constraint type to be dropped.
# File lib/neo4j/active_node/labels/index.rb 50 def drop_constraint(property, constraint = {type: :unique}) 51 Neo4j::Session.on_next_session_available do 52 declared_properties[property].unconstraint! if declared_properties[property] 53 schema_drop_operation(:constraint, property, constraint) 54 end 55 end
drop_index(property, options = {})
click to toggle source
@param [Symbol] property The name of the property index to be dropped
# File lib/neo4j/active_node/labels/index.rb 41 def drop_index(property, options = {}) 42 Neo4j::Session.on_next_session_available do 43 declared_properties[property].unindex! if declared_properties[property] 44 schema_drop_operation(:index, property, options) 45 end 46 end
index(property)
click to toggle source
Creates a Neo4j index on given property
This can also be done on the property directly, see Neo4j::ActiveNode::Property::ClassMethods#property.
@param [Symbol] property the property we want a Neo4j index on
@example
class Person include Neo4j::ActiveNode property :name index :name end
# File lib/neo4j/active_node/labels/index.rb 22 def index(property) 23 Neo4j::Session.on_next_session_available do |_| 24 declared_properties.index_or_fail!(property, id_property_name) 25 schema_create_operation(:index, property) 26 end 27 end
index?(property)
click to toggle source
# File lib/neo4j/active_node/labels/index.rb 57 def index?(property) 58 mapped_label.indexes[:property_keys].include?([property]) 59 end
Private Instance Methods
new_schema_class(type, property, options)
click to toggle source
# File lib/neo4j/active_node/labels/index.rb 75 def new_schema_class(type, property, options) 76 case type 77 when :index 78 Neo4j::Schema::ExactIndexOperation 79 when :constraint 80 Neo4j::Schema::UniqueConstraintOperation 81 else 82 fail "Unknown Schema Operation class #{type}" 83 end.new(mapped_label_name, property, options) 84 end
schema_create_operation(type, property, options = {})
click to toggle source
# File lib/neo4j/active_node/labels/index.rb 67 def schema_create_operation(type, property, options = {}) 68 new_schema_class(type, property, options).create! 69 end
schema_drop_operation(type, property, options = {})
click to toggle source
# File lib/neo4j/active_node/labels/index.rb 71 def schema_drop_operation(type, property, options = {}) 72 new_schema_class(type, property, options).drop! 73 end