Sha256: 1092fd1ef4200ab7b8f595f301cf32fb3ba9124d8cd0a4ef4d0df15e8ee36623

Contents?: true

Size: 1.48 KB

Versions: 87

Compression:

Stored size: 1.48 KB

Contents

module Neo4j
  class Label
    class << self
      def constraints(session = Neo4j::Session.current)
        session.connection.get(CONSTRAINT_PATH).body
      end

      def constraint?(label_name, property, session = Neo4j::Session.current)
        label_constraints = session.connection.get("#{CONSTRAINT_PATH}/#{label_name}").body
        !label_constraints.select { |c| c[:label] == label_name.to_s && c[:property_keys].first == property.to_s }.empty?
      end

      def indexes(session = Neo4j::Session.current)
        session.connection.get(INDEX_PATH).body
      end

      def index?(label_name, property, session = Neo4j::Session.current)
        label_indexes = session.connection.get("#{INDEX_PATH}/#{label_name}").body
        !label_indexes.select { |i| i[:label] == label_name.to_s && i[:property_keys].first == property.to_s }.empty?
      end

      def drop_all_indexes(session = Neo4j::Session.current)
        indexes.each do |i|
          begin
            session._query_or_fail("DROP INDEX ON :`#{i[:label]}`(#{i[:property_keys].first})")
          rescue Neo4j::Server::CypherResponse::ResponseError
            # This will error on each constraint. Ignore and continue.
            next
          end
        end
      end

      def drop_all_constraints(session = Neo4j::Session.current)
        constraints.each do |c|
          session._query_or_fail("DROP CONSTRAINT ON (n:`#{c[:label]}`) ASSERT n.`#{c[:property_keys].first}` IS UNIQUE")
        end
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
neo4j-core-8.1.4 lib/neo4j-server/label.rb
neo4j-core-8.1.3 lib/neo4j-server/label.rb
neo4j-core-8.1.2 lib/neo4j-server/label.rb
neo4j-core-8.1.1 lib/neo4j-server/label.rb
neo4j-core-8.1.0 lib/neo4j-server/label.rb
neo4j-core-8.0.4 lib/neo4j-server/label.rb
neo4j-core-8.0.3 lib/neo4j-server/label.rb
neo4j-core-8.0.2 lib/neo4j-server/label.rb
neo4j-core-8.0.1 lib/neo4j-server/label.rb
neo4j-core-7.2.4 lib/neo4j-server/label.rb
neo4j-core-8.0.0 lib/neo4j-server/label.rb
neo4j-core-7.2.3 lib/neo4j-server/label.rb
neo4j-core-7.2.2 lib/neo4j-server/label.rb
neo4j-core-7.2.1 lib/neo4j-server/label.rb
neo4j-core-7.2.0 lib/neo4j-server/label.rb
neo4j-core-7.1.2 lib/neo4j-server/label.rb
neo4j-core-7.0.9 lib/neo4j-server/label.rb
neo4j-core-7.1.1 lib/neo4j-server/label.rb
neo4j-core-7.1.0 lib/neo4j-server/label.rb
neo4j-core-7.0.8 lib/neo4j-server/label.rb