Class: Litedb::Statement

Inherits:
SQLite3::Statement
  • Object
show all
Includes:
Litemetric::Measurable
Defined in:
lib/litestack/litedb.rb

Overview

the Litedb::Statement also inherits from SQLite3::Statement

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sqlObject

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_typeObject



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

#eachObject

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_identifierObject



139
140
141
# File 'lib/litestack/litedb.rb', line 139

def metrics_identifier
  "Litedb" # overridden to match the parent class
end

#stmt_typeObject

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