Class: Litedb::Statement
- Inherits:
-
SQLite3::Statement
- Object
- SQLite3::Statement
- Litedb::Statement
- Includes:
- Litemetric::Measurable
- Defined in:
- lib/litestack/litedb.rb
Overview
the Litedb::Statement also inherits from SQLite3::Statement
Instance Attribute Summary collapse
-
#sql ⇒ Object
Returns the value of attribute sql.
Instance Method Summary collapse
- #detect_stmt_type ⇒ Object
-
#each ⇒ Object
overriding each to measure the query time (plus the processing time as well, sadly).
-
#execute(*bind_vars) ⇒ Object
overriding execute to measure the query time.
-
#initialize(db, sql) ⇒ Statement
constructor
A new instance of Statement.
- #metrics_identifier ⇒ Object
-
#stmt_type ⇒ Object
return the type of the statement.
Methods included from Litemetric::Measurable
#capture, #capture_snapshot, #collect_metrics, #create_snapshotter, #measure
Constructor Details
#initialize(db, sql) ⇒ Statement
Returns a new instance of Statement.
134 135 136 137 |
# File 'lib/litestack/litedb.rb', line 134 def initialize(db, sql) super(db, sql) collect_metrics if db.collecting_metrics? end |
Instance Attribute Details
#sql ⇒ Object
Returns the value of attribute sql.
132 133 134 |
# File 'lib/litestack/litedb.rb', line 132 def sql @sql end |
Instance Method Details
#detect_stmt_type ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/litestack/litedb.rb', line 148 def detect_stmt_type if @sql.start_with?("SEL", "WITH") "Read" elsif @sql.start_with?("CRE", "ALT", "DRO") "Schema change" elsif @sql.start_with?("PRA") "Pragma" else "Write" end end |
#each ⇒ Object
overriding each to measure the query time (plus the processing time as well, sadly)
161 162 163 164 165 |
# File 'lib/litestack/litedb.rb', line 161 def each measure(stmt_type, @sql) do super end end |
#execute(*bind_vars) ⇒ Object
overriding execute to measure the query time
168 169 170 171 172 173 174 |
# File 'lib/litestack/litedb.rb', line 168 def execute(*bind_vars) res = nil measure(stmt_type, @sql) do res = super(*bind_vars) end res end |
#metrics_identifier ⇒ Object
139 140 141 |
# File 'lib/litestack/litedb.rb', line 139 def metrics_identifier "Litedb" # overridden to match the parent class end |
#stmt_type ⇒ Object
return the type of the statement
144 145 146 |
# File 'lib/litestack/litedb.rb', line 144 def stmt_type @stmt_type ||= detect_stmt_type end |