class Neo4j::Core::Label
Attributes
name[R]
Public Class Methods
drop_indexes_for(session)
click to toggle source
# File lib/neo4j/core/label.rb 84 def self.drop_indexes_for(session) 85 indexes_for(session).each do |definition| 86 begin 87 session.query("DROP INDEX ON :`#{definition[:label]}`(#{definition[:properties][0]})") 88 rescue Neo4j::Server::CypherResponse::ResponseError 89 # This will error on each constraint. Ignore and continue. 90 next 91 end 92 end 93 end
drop_uniqueness_constraints_for(session)
click to toggle source
# File lib/neo4j/core/label.rb 117 def self.drop_uniqueness_constraints_for(session) 118 session.constraints.each do |definition| 119 session.query("DROP CONSTRAINT ON (n:`#{definition[:label]}`) ASSERT n.`#{definition[:properties][0]}` IS UNIQUE") 120 end 121 end
indexes_for(session)
click to toggle source
# File lib/neo4j/core/label.rb 69 def self.indexes_for(session) 70 session.indexes 71 end
new(name, session)
click to toggle source
# File lib/neo4j/core/label.rb 6 def initialize(name, session) 7 @name = name 8 @session = session 9 end
wait_for_schema_changes(session)
click to toggle source
# File lib/neo4j/core/label.rb 131 def self.wait_for_schema_changes(session) 132 schema_threads(session).map(&:join) 133 set_schema_threads(session, []) 134 end
Private Class Methods
schema_threads(session)
click to toggle source
# File lib/neo4j/core/label.rb 149 def schema_threads(session) 150 session.instance_variable_get('@_schema_threads') || [] 151 end
set_schema_threads(session, array)
click to toggle source
# File lib/neo4j/core/label.rb 153 def set_schema_threads(session, array) 154 session.instance_variable_set('@_schema_threads', array) 155 end
Public Instance Methods
constraint?(property)
click to toggle source
# File lib/neo4j/core/label.rb 123 def constraint?(property) 124 constraints.any? { |definition| definition[:properties] == [property.to_sym] } 125 end
constraints(_options = {})
click to toggle source
# File lib/neo4j/core/label.rb 99 def constraints(_options = {}) 100 @session.constraints.select do |definition| 101 definition[:label] == @name.to_sym 102 end 103 end
create_constraint(property, constraints)
click to toggle source
Creates a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html @example
label = Neo4j::Label.create(:person, session) label.create_constraint(:name, {type: :unique}, session)
# File lib/neo4j/core/label.rb 28 def create_constraint(property, constraints) 29 cypher = case constraints[:type] 30 when :unique, :uniqueness 31 "CREATE CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE" 32 else 33 fail "Not supported constraint #{constraints.inspect} for property #{property} (expected :type => :unique)" 34 end 35 schema_query(cypher) 36 end
create_index(property, options = {})
click to toggle source
# File lib/neo4j/core/label.rb 11 def create_index(property, options = {}) 12 validate_index_options!(options) 13 properties = property.is_a?(Array) ? property.join(',') : property 14 schema_query("CREATE INDEX ON :`#{@name}`(#{properties})") 15 end
create_uniqueness_constraint(property, options = {})
click to toggle source
# File lib/neo4j/core/label.rb 38 def create_uniqueness_constraint(property, options = {}) 39 create_constraint(property, options.merge(type: :unique)) 40 end
drop_constraint(property, constraint)
click to toggle source
Drops a neo4j constraint on a property See docs.neo4j.org/chunked/stable/query-constraints.html @example
label = Neo4j::Label.create(:person, session) label.create_constraint(:name, {type: :unique}, session) label.drop_constraint(:name, {type: :unique}, session)
# File lib/neo4j/core/label.rb 49 def drop_constraint(property, constraint) 50 cypher = case constraint[:type] 51 when :unique, :uniqueness 52 "DROP CONSTRAINT ON (n:`#{name}`) ASSERT n.`#{property}` IS UNIQUE" 53 else 54 fail "Not supported constraint #{constraint.inspect}" 55 end 56 schema_query(cypher) 57 end
drop_index(property, options = {})
click to toggle source
# File lib/neo4j/core/label.rb 17 def drop_index(property, options = {}) 18 validate_index_options!(options) 19 schema_query("DROP INDEX ON :`#{@name}`(#{property})") 20 end
drop_indexes()
click to toggle source
# File lib/neo4j/core/label.rb 73 def drop_indexes 74 indexes.each do |definition| 75 begin 76 @session.query("DROP INDEX ON :`#{definition[:label]}`(#{definition[:properties][0]})") 77 rescue Neo4j::Server::CypherResponse::ResponseError 78 # This will error on each constraint. Ignore and continue. 79 next 80 end 81 end 82 end
drop_uniqueness_constraint(property, options = {})
click to toggle source
# File lib/neo4j/core/label.rb 59 def drop_uniqueness_constraint(property, options = {}) 60 drop_constraint(property, options.merge(type: :unique)) 61 end
drop_uniqueness_constraints()
click to toggle source
# File lib/neo4j/core/label.rb 111 def drop_uniqueness_constraints 112 uniqueness_constraints.each do |definition| 113 @session.query("DROP CONSTRAINT ON (n:`#{definition[:label]}`) ASSERT n.`#{definition[:properties][0]}` IS UNIQUE") 114 end 115 end
index?(property)
click to toggle source
# File lib/neo4j/core/label.rb 95 def index?(property) 96 indexes.any? { |definition| definition[:properties] == [property.to_sym] } 97 end
indexes()
click to toggle source
# File lib/neo4j/core/label.rb 63 def indexes 64 @session.indexes.select do |definition| 65 definition[:label] == @name.to_sym 66 end 67 end
uniqueness_constraint?(property)
click to toggle source
# File lib/neo4j/core/label.rb 127 def uniqueness_constraint?(property) 128 uniqueness_constraints.include?([property]) 129 end
uniqueness_constraints(_options = {})
click to toggle source
# File lib/neo4j/core/label.rb 105 def uniqueness_constraints(_options = {}) 106 constraints.select do |definition| 107 definition[:type] == :uniqueness 108 end 109 end
Private Instance Methods
schema_query(cypher)
click to toggle source
# File lib/neo4j/core/label.rb 158 def schema_query(cypher) 159 @session.transaction { |tx| tx.query(cypher, {}) } 160 end
schema_threads()
click to toggle source
Store schema threads on the session so that we can easily wait for all threads on a session regardless of label
# File lib/neo4j/core/label.rb 140 def schema_threads 141 self.class.schema_threads(@session) 142 end
schema_threads=(array)
click to toggle source
# File lib/neo4j/core/label.rb 144 def schema_threads=(array) 145 self.class.set_schema_threads(@session, array) 146 end
validate_index_options!(options)
click to toggle source
# File lib/neo4j/core/label.rb 162 def validate_index_options!(options) 163 return unless options[:type] && options[:type] != :exact 164 fail "Type #{options[:type]} is not supported" 165 end