Class: Insight::Database

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

Defined Under Namespace

Modules: RequestDataClient Classes: DataTable, RequestTable, Table

Class Method Summary collapse

Methods included from Logging

logger

Class Method Details

.database_pathObject



47
48
49
# File 'lib/insight/database.rb', line 47

def database_path
  @database_path
end

.database_path=(value) ⇒ Object



43
44
45
# File 'lib/insight/database.rb', line 43

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

.dbObject



51
52
53
# File 'lib/insight/database.rb', line 51

def db
  @db ||= open_database
end

.open_databaseObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/insight/database.rb', line 59

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

  return {}
end

.resetObject



55
56
57
# File 'lib/insight/database.rb', line 55

def reset
  @db = nil
end