Sha256: 5c615370bfad53370f155c867c0f7e602f39ccde34ffe82c60857998c335000f

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Architect4r
  module Core
    module CypherMethods
      extend ActiveSupport::Concern
      
      module InstanceMethods
        
        def execute_cypher(query)
          url = prepend_base_url("/ext/CypherPlugin/graphdb/execute_query")
          response = Typhoeus::Request.post(url, 
            :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/json' },
            :body => { 'query' => query }.to_json)
          
          # Check if there might be an error with the query
          if response.code == 400
            raise Architect4r::InvalidCypherQuery.new(query)
          elsif response.code == 500
            msg = JSON.parse(response.body)
            
            if msg['exception'].to_s.match /org.neo4j.graphdb.NotFoundException/
              nil
            else
              raise Architect4r::InvalidCypherQuery.new(query)
            end
          elsif response.code == 204
            nil
          else
            result_data = JSON.parse(response.body)
            
            # Convert the columnized result array to hashes within an array
            results = []
            
            result_data['data'].each_with_index do |row, ri|
              result_row = {}
              result_data['columns'].each_with_index do |column, ci|
                result_row[column] = convert_if_possible(row[ci])
              end
              results << result_row
            end
            results
          end
        end
        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
architect4r-0.3.2 lib/architect4r/core/cypher_methods.rb