Sha256: 8fbf5013483f2eb5fa4cb1943a65aa9ec1acd20c0d70aa83239c0231b283e452

Contents?: true

Size: 1.55 KB

Versions: 12

Compression:

Stored size: 1.55 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 || {}

          queries(options) { append(*args) }[0]
        end

        def queries(options = {}, &block)
          query_builder = QueryBuilder.new

          query_builder.instance_eval(&block)

          transaction do
            query_set(query_builder.queries, options)
          end
        end

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

        def query_set(queries, options = {})
          setup_queries!(queries, skip_instrumentation: options[:skip_instrumentation])

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

Version data entries

12 entries across 12 versions & 1 rubygems

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