Class: Rack::DevInsight::SqlRecorder
- Inherits:
-
BaseRecorder
- Object
- BaseRecorder
- Rack::DevInsight::SqlRecorder
- Defined in:
- lib/rack/dev_insight/recorder/sql_recorder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #record(dialect:, statement:, binds: [], duration: 0.0) ⇒ Object
- #record_from_event(started:, finished:, statement:, binds:, cached:) ⇒ Object
- #record_sql(dialect:, statement:, binds: []) ⇒ Object
Class Method Details
.record(dialect:, statement:, binds: [], duration: 0.0) ⇒ nil
14 15 16 |
# File 'lib/rack/dev_insight/recorder/sql_recorder.rb', line 14 def record(dialect:, statement:, binds: [], duration: 0.0) new.record(dialect: dialect, statement: statement, binds: binds, duration: duration) end |
Instance Method Details
#record(dialect:, statement:, binds: [], duration: 0.0) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/dev_insight/recorder/sql_recorder.rb', line 19 def record(dialect:, statement:, binds: [], duration: 0.0) SqlDialects.validate!(dialect, ArgumentError) return if Context.current.nil? Context.current.result.add_sql( dialect: dialect, statement: statement, binds: format_binds(binds), backtrace: get_backtrace, duration: format('%.2f', duration).to_f, ) nil end |
#record_from_event(started:, finished:, statement:, binds:, cached:) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rack/dev_insight/recorder/sql_recorder.rb', line 50 def record_from_event(started:, finished:, statement:, binds:, cached:) return if Context.current.nil? return if DevInsight.config.detected_dialect.nil? return if DevInsight.config.skip_cached_sql && cached Context.current.result.add_sql( dialect: DevInsight.config.detected_dialect, statement: statement, binds: format_binds(binds), backtrace: get_backtrace, duration: format('%.2f', (finished - started) * 1000).to_f, ) nil end |
#record_sql(dialect:, statement:, binds: []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rack/dev_insight/recorder/sql_recorder.rb', line 33 def record_sql(dialect:, statement:, binds: []) return yield if Context.current.nil? start = Process.clock_gettime(Process::CLOCK_MONOTONIC) res = yield duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start Context.current.result.add_sql( dialect: dialect, statement: statement, binds: format_binds(binds), backtrace: get_backtrace, duration: format('%.2f', duration * 1000).to_f, ) res end |