Class: Hyphy::SQLStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/hyphy/sql_statement.rb

Constant Summary collapse

DIGIT_MARKER =
'<digit>'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SQLStatement

Returns a new instance of SQLStatement.



15
16
17
18
19
20
21
22
23
# File 'lib/hyphy/sql_statement.rb', line 15

def initialize(opts={})
  @statement = opts[:statement]
  @start_time = opts[:start_time]
  @end_time = opts[:end_time]
  @orm_adapter = opts[:orm_adapter]
  @trace = opts[:trace] || []
  @binds = opts[:binds] || []
   = opts[:metadata] || {}
end

Instance Attribute Details

#benchmark_runsObject

Returns the value of attribute benchmark_runs.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def benchmark_runs
  @benchmark_runs
end

#benchmark_timeObject

Returns the value of attribute benchmark_time.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def benchmark_time
  @benchmark_time
end

#bindsObject

Returns the value of attribute binds.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def binds
  @binds
end

#end_timeObject

Returns the value of attribute end_time.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def end_time
  @end_time
end

#metadataObject

Returns the value of attribute metadata.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def 
  
end

#orm_adapterObject

Returns the value of attribute orm_adapter.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def orm_adapter
  @orm_adapter
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def start_time
  @start_time
end

#statementObject

Returns the value of attribute statement.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def statement
  @statement
end

#traceObject

Returns the value of attribute trace.



5
6
7
# File 'lib/hyphy/sql_statement.rb', line 5

def trace
  @trace
end

Instance Method Details

#application_traceObject



45
46
47
48
49
50
# File 'lib/hyphy/sql_statement.rb', line 45

def application_trace
  return @application_trace if @application_trace

  regex = Regexp.new("^#{Dir.pwd}")
  @application_trace ||= trace.select { |line| regex.match(line) }
end

#digitlessObject



41
42
43
# File 'lib/hyphy/sql_statement.rb', line 41

def digitless
  @digitless ||= stripped_statement.gsub(/\d+/, DIGIT_MARKER)
end

#durationObject



25
26
27
# File 'lib/hyphy/sql_statement.rb', line 25

def duration
  @duration ||= (end_time - start_time)
end

#insert?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/hyphy/sql_statement.rb', line 37

def insert?
  @insert ||= stripped_statement.upcase.match(/^INSERT/)
end

#select?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/hyphy/sql_statement.rb', line 33

def select?
  @select ||= stripped_statement.upcase.match(/^SELECT/)
end

#stripped_statementObject



29
30
31
# File 'lib/hyphy/sql_statement.rb', line 29

def stripped_statement
  @stripped_statement ||= statement.strip
end