Class: RspecProfiling::Collectors::SQL

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_profiling/collectors/sql.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSQL

Returns a new instance of SQL.



19
20
21
22
# File 'lib/rspec_profiling/collectors/sql.rb', line 19

def initialize
  RspecProfiling.config.db_path ||= 'tmp/rspec_profiling'
  establish_connection
end

Class Method Details

.installObject



7
8
9
# File 'lib/rspec_profiling/collectors/sql.rb', line 7

def self.install
  new.install
end

.resetObject



15
16
17
# File 'lib/rspec_profiling/collectors/sql.rb', line 15

def self.reset
  new.results.destroy_all
end

.uninstallObject



11
12
13
# File 'lib/rspec_profiling/collectors/sql.rb', line 11

def self.uninstall
  new.uninstall
end

Instance Method Details

#insert(attributes) ⇒ Object



49
50
51
# File 'lib/rspec_profiling/collectors/sql.rb', line 49

def insert(attributes)
  results.create!(attributes.except(:created_at, :events, :event_counts, :event_times, :event_events))
end

#installObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rspec_profiling/collectors/sql.rb', line 24

def install
  return if prepared?

  connection.create_table(table) do |t|
    t.string    :branch, index: true
    t.string    :commit_hash, index: true
    t.datetime  :date, index: true
    t.text      :file, index: true
    t.integer   :line_number, index: true
    t.text      :description
    t.decimal   :time, index: true
    t.string    :status, index: true
    t.text      :exception
    t.integer   :query_count, index: true
    t.decimal   :query_time, index:true
    t.integer   :request_count, index: true
    t.decimal   :request_time, index: true
    t.timestamps null: true
  end
end

#resultsObject



53
54
55
56
57
58
59
60
61
# File 'lib/rspec_profiling/collectors/sql.rb', line 53

def results
  @results ||= begin
    establish_connection

    Result.table_name = table
    Result.attr_protected if Result.respond_to?(:attr_protected)
    Result
  end
end

#uninstallObject



45
46
47
# File 'lib/rspec_profiling/collectors/sql.rb', line 45

def uninstall
  connection.drop_table(table)
end