Sha256: de4b09792a80d88a286793a14c7e71d328da230bef61a60e9264d032f818cbec

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

module ActiveGraph
  module Core
    module Schema
      def version
        result = query('CALL dbms.components()', {}, skip_instrumentation: true)

        # BTW: community / enterprise could be retrieved via `result.first.edition`
        result.first[:versions][0]
      end

      def indexes
        result = query('CALL db.indexes()', {}, skip_instrumentation: true)

        result.map do |row|
          { type: row[:type].to_sym, label: label(result, row), properties: properties(row), state: row[:state].to_sym }
        end
      end

      def constraints
        result = query('CALL db.indexes()', {}, skip_instrumentation: true)

        result.select(&method(v4?(result) ? :v4_filter : :v3_filter)).map do |row|
          { type: :uniqueness, label: label(result, row), properties: properties(row) }
        end
      end

      private

      def v4_filter(row)
        row[:uniqueness] == 'UNIQUE'
      end

      def v3_filter(row)
        row[:type] == 'node_unique_property'
      end

      def label(result, row)
        if v34?(result)
          row[:label]
        else
          (v4?(result) ? row[:labelsOrTypes] : row[:tokenNames]).first
        end.to_sym
      end

      def v4?(result)
        return @v4 unless @v4.nil?
        @v4 = result.keys.include?(:labelsOrTypes)
      end

      def v34?(result)
        return @v34 unless @v34.nil?
        @v34 = result.keys.include?(:label)
      end

      def properties(row)
        row[:properties].map(&:to_sym)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activegraph-10.1.1 lib/active_graph/core/schema.rb
activegraph-10.1.0 lib/active_graph/core/schema.rb
activegraph-10.0.2 lib/active_graph/core/schema.rb
activegraph-10.0.1 lib/active_graph/core/schema.rb
activegraph-10.0.0 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.11 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.10 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.9 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.8 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.7 lib/active_graph/core/schema.rb
activegraph-10.0.0.pre.beta.6 lib/active_graph/core/schema.rb