Class: LogBench::Log::QueryEntry
- Inherits:
-
Entry
- Object
- Entry
- LogBench::Log::QueryEntry
show all
- Defined in:
- lib/log_bench/log/query_entry.rb
Constant Summary
collapse
- SELECT =
"SELECT"
- INSERT =
"INSERT"
- UPDATE =
"UPDATE"
- DELETE =
"DELETE"
- TRANSACTION =
"TRANSACTION"
- BEGIN_TRANSACTION =
"BEGIN"
- COMMIT =
"COMMIT"
- ROLLBACK =
"ROLLBACK"
- SAVEPOINT =
"SAVEPOINT"
- SQL_OPERATIONS =
[SELECT, INSERT, UPDATE, DELETE, TRANSACTION, BEGIN_TRANSACTION, COMMIT, ROLLBACK, SAVEPOINT].freeze
Instance Attribute Summary
Attributes inherited from Entry
#content, #raw_line, #request_id, #timestamp, #timing, #type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Entry
#http_request?, parseable?, #related_log?
Constructor Details
#initialize(raw_line) ⇒ QueryEntry
Returns a new instance of QueryEntry.
17
18
19
20
|
# File 'lib/log_bench/log/query_entry.rb', line 17
def initialize(raw_line)
super
self.type = :sql
end
|
Class Method Details
.build(raw_line) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/log_bench/log/query_entry.rb', line 22
def self.build(raw_line)
return unless parseable?(raw_line)
entry = Entry.new(raw_line)
return unless entry.type == :sql
new(raw_line)
end
|
Instance Method Details
#begin? ⇒ Boolean
57
58
59
|
# File 'lib/log_bench/log/query_entry.rb', line 57
def begin?
operation == BEGIN_TRANSACTION
end
|
#commit? ⇒ Boolean
61
62
63
|
# File 'lib/log_bench/log/query_entry.rb', line 61
def commit?
operation == COMMIT
end
|
#delete? ⇒ Boolean
49
50
51
|
# File 'lib/log_bench/log/query_entry.rb', line 49
def delete?
operation == DELETE
end
|
#duration_ms ⇒ Object
31
32
33
34
35
|
# File 'lib/log_bench/log/query_entry.rb', line 31
def duration_ms
return 0.0 unless timing
timing.gsub(/[()ms]/, "").to_f
end
|
#insert? ⇒ Boolean
41
42
43
|
# File 'lib/log_bench/log/query_entry.rb', line 41
def insert?
operation == INSERT
end
|
#rollback? ⇒ Boolean
65
66
67
|
# File 'lib/log_bench/log/query_entry.rb', line 65
def rollback?
operation == ROLLBACK
end
|
#savepoint? ⇒ Boolean
69
70
71
|
# File 'lib/log_bench/log/query_entry.rb', line 69
def savepoint?
operation == SAVEPOINT
end
|
#select? ⇒ Boolean
37
38
39
|
# File 'lib/log_bench/log/query_entry.rb', line 37
def select?
operation == SELECT
end
|
#slow?(threshold_ms = 100) ⇒ Boolean
73
74
75
|
# File 'lib/log_bench/log/query_entry.rb', line 73
def slow?(threshold_ms = 100)
duration_ms > threshold_ms
end
|
#to_h ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/log_bench/log/query_entry.rb', line 77
def to_h
super.merge(
content: content,
timing: timing,
operation: operation,
duration_ms: duration_ms,
has_ansi: has_ansi_codes?(content)
)
end
|
#transaction? ⇒ Boolean
53
54
55
|
# File 'lib/log_bench/log/query_entry.rb', line 53
def transaction?
operation == TRANSACTION
end
|
#update? ⇒ Boolean
45
46
47
|
# File 'lib/log_bench/log/query_entry.rb', line 45
def update?
operation == UPDATE
end
|