Sha256: 17e642e378e1d6798af4cf32baaa70a26167fc70b31df3b429d077eec4606aa4

Contents?: true

Size: 873 Bytes

Versions: 5

Compression:

Stored size: 873 Bytes

Contents

require 'sequel/database/logging'
require 'active_support/notifications'

module ROM
  module SQL
    module ActiveSupportInstrumentation
      if Sequel::MAJOR == 4 && Sequel::MINOR < 35
        def log_yield(sql, args = nil)
          ActiveSupport::Notifications.instrument(
            'sql.rom',
            sql: sql,
            name: instrumentation_name,
            binds: args
          ) { super }
        end
      else
        def log_connection_yield(sql, _conn, args = nil)
          ActiveSupport::Notifications.instrument(
            'sql.rom',
            sql: sql,
            name: instrumentation_name,
            binds: args
          ) { super }
        end
      end

      private

      def instrumentation_name
        "ROM[#{database_type}]"
      end
    end
  end
end

Sequel::Database.send(:prepend, ROM::SQL::ActiveSupportInstrumentation)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-sql-1.0.0.beta2 lib/rom/sql/extensions/active_support_notifications.rb
rom-sql-1.0.0.beta1 lib/rom/sql/extensions/active_support_notifications.rb
rom-sql-0.9.1 lib/rom/sql/extensions/active_support_notifications.rb
rom-sql-0.9.0 lib/rom/sql/extensions/active_support_notifications.rb
rom-sql-0.8.0 lib/rom/sql/support/active_support_notifications.rb