Class: Profiler::Models::SqlQuery
- Inherits:
-
Object
- Object
- Profiler::Models::SqlQuery
- Defined in:
- lib/profiler/models/sql_query.rb
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#binds ⇒ Object
readonly
Returns the value of attribute binds.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Instance Method Summary collapse
- #cached? ⇒ Boolean
-
#initialize(sql:, duration:, binds: [], name: nil, connection: nil, backtrace: []) ⇒ SqlQuery
constructor
A new instance of SqlQuery.
- #slow?(threshold = 100) ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #transaction? ⇒ Boolean
Constructor Details
#initialize(sql:, duration:, binds: [], name: nil, connection: nil, backtrace: []) ⇒ SqlQuery
Returns a new instance of SqlQuery.
8 9 10 11 12 13 14 15 |
# File 'lib/profiler/models/sql_query.rb', line 8 def initialize(sql:, duration:, binds: [], name: nil, connection: nil, backtrace: []) @sql = sql @duration = duration @binds = binds @name = name @connection = connection @backtrace = backtrace end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def backtrace @backtrace end |
#binds ⇒ Object (readonly)
Returns the value of attribute binds.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def binds @binds end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def connection @connection end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def duration @duration end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def name @name end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
6 7 8 |
# File 'lib/profiler/models/sql_query.rb', line 6 def sql @sql end |
Instance Method Details
#cached? ⇒ Boolean
21 22 23 |
# File 'lib/profiler/models/sql_query.rb', line 21 def cached? @name == "CACHE" end |
#slow?(threshold = 100) ⇒ Boolean
17 18 19 |
# File 'lib/profiler/models/sql_query.rb', line 17 def slow?(threshold = 100) @duration > threshold end |
#to_h ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/profiler/models/sql_query.rb', line 29 def to_h { sql: @sql, duration: @duration, binds: @binds, name: @name, connection: @connection&.class&.name, backtrace: @backtrace.map(&:to_s), slow: slow?, cached: cached?, transaction: transaction? } end |
#to_json(*args) ⇒ Object
43 44 45 |
# File 'lib/profiler/models/sql_query.rb', line 43 def to_json(*args) to_h.to_json(*args) end |
#transaction? ⇒ Boolean
25 26 27 |
# File 'lib/profiler/models/sql_query.rb', line 25 def transaction? @sql =~ /^(BEGIN|COMMIT|ROLLBACK)/i end |