Sha256: eb7068e7a9bc93d2d961314f33ef8144959ceb07e4727b401b3747ceb42e776b

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

require 'active_graph/core/instrumentable'
require 'active_graph/transaction'
require 'active_graph/core/query_builder'
require 'active_graph/core/record'

module ActiveGraph
  module Core
    module Querable
      extend ActiveSupport::Concern
      include Instrumentable

      class_methods do
        def query(*args)
          options = case args.size
                    when 3
                      args.pop
                    when 2
                      args.pop if args[0].is_a?(::ActiveGraph::Core::Query)
                    end || {}

          query_run(QueryBuilder.query(*args), options)
        end

        def setup_query!(query, options = {})
          return if options[:skip_instrumentation]
          ActiveSupport::Notifications.instrument('neo4j.core.cypher_query', query: query)
        end

        def query_run(query, options = {})
          setup_query!(query, skip_instrumentation: options[:skip_instrumentation])

          ActiveSupport::Notifications.instrument('neo4j.core.bolt.request') do
            transaction do |tx|
              tx.run(query.cypher, **query.parameters).tap { |result| result.wrap = options[:wrap] != false }
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activegraph-11.4.0 lib/active_graph/core/querable.rb
activegraph-11.3.1 lib/active_graph/core/querable.rb
activegraph-11.3.0 lib/active_graph/core/querable.rb
activegraph-11.2.0 lib/active_graph/core/querable.rb
activegraph-11.1.0 lib/active_graph/core/querable.rb
activegraph-11.1.0.beta.1 lib/active_graph/core/querable.rb
activegraph-11.1.0.alpha.4 lib/active_graph/core/querable.rb
activegraph-11.1.0.alpha.3 lib/active_graph/core/querable.rb
activegraph-11.1.0.alpha.2 lib/active_graph/core/querable.rb
activegraph-11.1.0.alpha.1 lib/active_graph/core/querable.rb