Sha256: 333e13e60353f2fb0e1ad8ea2b8a2e1a9854bdde5957f3c468f910615a8eb629

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

module Blazer
  module Adapters
    class Neo4jAdapter < BaseAdapter
      def run_statement(statement, comment)
        columns = []
        rows = []
        error = nil

        begin
          result = session.query("#{statement} /*#{comment}*/")
          columns = result.columns.map(&:to_s)
          rows = []
          result.each do |row|
            rows << columns.map do |c|
              v = row.send(c)
              v = v.properties if v.respond_to?(:properties)
              v
            end
          end
        rescue => e
          error = e.message
        end

        [columns, rows, error]
      end

      def tables
        result = session.query("CALL db.labels()")
        result.rows.map(&:first)
      end

      def preview_statement
        "MATCH (n:{table}) RETURN n LIMIT 10"
      end

      protected

      def session
        @session ||= begin
          require "neo4j/core/cypher_session/adaptors/http"
          http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new(settings["url"])
          Neo4j::Core::CypherSession.new(http_adaptor)
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
blazer-2.5.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.8 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.7 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.6 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.5 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.4 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.3 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.2 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.1 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.4.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.3.1 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.3.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.8 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.7 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.6 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.5 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.4 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.3 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.2 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.2.1 lib/blazer/adapters/neo4j_adapter.rb