Sha256: bada6c5d7a004531ac214de40087be43c1de9193b43b8fc374397167d1b581d0

Contents?: true

Size: 1.6 KB

Versions: 20

Compression:

Stored size: 1.6 KB

Contents

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

        begin
          result = session.query("#{statement} /*#{comment}*/", bind_params)
          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
          error = Blazer::VARIABLE_MESSAGE if error.include?("Invalid input '$'")
        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

      # https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#cypher-expressions-string-literals
      def quoting
        :backslash_escape
      end

      def parameter_binding
        proc do |statement, variables|
          variables.each_key do |k|
            statement = statement.gsub("{#{k}}") { "$#{k} " }
          end
          [statement, variables]
        end
      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

20 entries across 20 versions & 3 rubygems

Version Path
blazer-3.1.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-3.0.4 lib/blazer/adapters/neo4j_adapter.rb
blazer_xlsx-3.0.8 lib/blazer/adapters/neo4j_adapter.rb
blazer_xlsx-3.0.7 lib/blazer/adapters/neo4j_adapter.rb
blazer_xlsx-3.0.6 lib/blazer/adapters/neo4j_adapter.rb
blazer_xlsx-3.0.5 lib/blazer/adapters/neo4j_adapter.rb
blazer-3.0.3 lib/blazer/adapters/neo4j_adapter.rb
blazer-3.0.2 lib/blazer/adapters/neo4j_adapter.rb
finery-3.0.3 lib/blazer/adapters/neo4j_adapter.rb
finery-3.0.2 lib/blazer/adapters/neo4j_adapter.rb
blazer-3.0.1 lib/blazer/adapters/neo4j_adapter.rb
finery-3.0.1 lib/blazer/adapters/neo4j_adapter.rb
finery-3.0.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-3.0.0 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.5 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.4 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.3 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.2 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.1 lib/blazer/adapters/neo4j_adapter.rb
blazer-2.6.0 lib/blazer/adapters/neo4j_adapter.rb