Class: QueryGuard::Core::Query
- Inherits:
-
Object
- Object
- QueryGuard::Core::Query
- Defined in:
- lib/query_guard/core/query.rb
Overview
Immutable representation of a single SQL query event. Captured from ActiveSupport::Notifications sql.active_record event.
Instance Attribute Summary collapse
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
-
#initialize(sql:, duration_ms:, name: nil, started_at: nil, finished_at: nil) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
-
#to_h ⇒ Object
Serialize to hash for reporting.
Constructor Details
#initialize(sql:, duration_ms:, name: nil, started_at: nil, finished_at: nil) ⇒ Query
Returns a new instance of Query.
10 11 12 13 14 15 16 |
# File 'lib/query_guard/core/query.rb', line 10 def initialize(sql:, duration_ms:, name: nil, started_at: nil, finished_at: nil) @sql = sql.freeze @duration_ms = duration_ms @name = name.to_s.freeze if name @started_at = started_at @finished_at = finished_at end |
Instance Attribute Details
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms.
8 9 10 |
# File 'lib/query_guard/core/query.rb', line 8 def duration_ms @duration_ms end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
8 9 10 |
# File 'lib/query_guard/core/query.rb', line 8 def finished_at @finished_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/query_guard/core/query.rb', line 8 def name @name end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
8 9 10 |
# File 'lib/query_guard/core/query.rb', line 8 def sql @sql end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
8 9 10 |
# File 'lib/query_guard/core/query.rb', line 8 def started_at @started_at end |
Instance Method Details
#inspect ⇒ Object
29 30 31 |
# File 'lib/query_guard/core/query.rb', line 29 def inspect "#<Query duration_ms=#{duration_ms} sql='#{truncate_sql(sql, 50)}'>" end |
#to_h ⇒ Object
Serialize to hash for reporting
19 20 21 22 23 24 25 26 27 |
# File 'lib/query_guard/core/query.rb', line 19 def to_h { sql: sql, duration_ms: duration_ms, name: name, started_at: started_at&.iso8601, finished_at: finished_at&.iso8601 } end |