Sha256: a4d65393f2d2ebd57fe35563b6fff39ddfabab76f97da29140f6507df7596295

Contents?: true

Size: 862 Bytes

Versions: 6

Compression:

Stored size: 862 Bytes

Contents

module Timber
  module Events
    # The SQL query event tracks sql queries to your database.
    #
    # @note This event should be installed automatically through integrations,
    #   such as the {Integrations::ActiveRecord::LogSubscriber} integration.
    class SQLQuery < Timber::Event
      attr_reader :sql, :time_ms, :message

      def initialize(attributes)
        @sql = attributes[:sql] || raise(ArgumentError.new(":sql is required"))
        @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required"))
        @time_ms = @time_ms.round(6)
        @message = attributes[:message] || raise(ArgumentError.new(":message is required"))
      end

      def to_hash
        {sql: sql, time_ms: time_ms}
      end
      alias to_h to_hash

      def as_json(_options = {})
        {:sql_query => to_hash}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
timber-2.0.24 lib/timber/events/sql_query.rb
timber-2.0.23 lib/timber/events/sql_query.rb
timber-2.0.22 lib/timber/events/sql_query.rb
timber-2.0.21 lib/timber/events/sql_query.rb
timber-2.0.20 lib/timber/events/sql_query.rb
timber-2.0.19 lib/timber/events/sql_query.rb