Class: Flaky::Database
- Inherits:
-
Object
- Object
- Flaky::Database
- Defined in:
- lib/flaky/database.rb
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Method Summary collapse
- #close ⇒ Object
- #connection ⇒ Object
-
#initialize(path = nil) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(path = nil) ⇒ Database
Returns a new instance of Database.
9 10 11 |
# File 'lib/flaky/database.rb', line 9 def initialize(path = nil) @path = path || Flaky.configuration.resolved_db_path end |
Instance Method Details
#close ⇒ Object
26 27 28 29 |
# File 'lib/flaky/database.rb', line 26 def close @connection&.close @connection = nil end |
#connection ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flaky/database.rb', line 13 def connection @connection ||= begin dir = File.dirname(@path) FileUtils.mkdir_p(dir) unless File.directory?(dir) db = SQLite3::Database.new(@path) db.results_as_hash = true db.execute("PRAGMA journal_mode=WAL") db.execute("PRAGMA foreign_keys=ON") migrate!(db) db end end |