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.



130
131
132
133
# File 'lib/litestack/litedb.rb', line 130

def initialize(db, sql)
  super(db, sql)
  collect_metrics if db.collecting_metrics?
end

Instance Attribute Details

#sqlObject

Returns the value of attribute sql.



128
129
130
# File 'lib/litestack/litedb.rb', line 128

def sql
  @sql
end

Instance Method Details

#detect_stmt_typeObject



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/litestack/litedb.rb', line 144

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)



157
158
159
160
161
# File 'lib/litestack/litedb.rb', line 157

def each
  measure(stmt_type, @sql) do
    super
  end
end

#execute(*bind_vars) ⇒ Object

overriding execute to measure the query time



164
165
166
167
168
169
170
# File 'lib/litestack/litedb.rb', line 164

def execute(*bind_vars)
  res = nil
  measure(stmt_type, @sql) do
    res = super(*bind_vars)
  end
  res
end

#metrics_identifierObject



135
136
137
# File 'lib/litestack/litedb.rb', line 135

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

#stmt_typeObject

return the type of the statement



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

def stmt_type
  @stmt_type ||= detect_stmt_type
end