Class: Rack::Insight::Database

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/rack/insight/database.rb

Defined Under Namespace

Modules: EigenClient, RequestDataClient Classes: DataTable, RequestTable, Table

Class Method Summary collapse

Methods included from Logging

logger, verbose, verbosity

Class Method Details

.database_pathObject



75
76
77
# File 'lib/rack/insight/database.rb', line 75

def database_path
  @database_path
end

.database_path=(value) ⇒ Object



71
72
73
# File 'lib/rack/insight/database.rb', line 71

def database_path=(value)
  @database_path = value || "rack-insight.sqlite"
end

.dbObject



79
80
81
# File 'lib/rack/insight/database.rb', line 79

def db
  @db ||= open_database
end

.open_databaseObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rack/insight/database.rb', line 87

def open_database
  @db = SQLite3::Database.new(database_path)
  @db.busy_timeout = 10000
  @db.execute("pragma foreign_keys = on")
  @db
rescue StandardError => ex
  msg = "Issue while loading SQLite DB:" + [ex.class, ex.message, ex.backtrace[0..4]].inspect
  logger.error{ msg }

  return {}
end

.resetObject



83
84
85
# File 'lib/rack/insight/database.rb', line 83

def reset
  @db = nil
end