Class: ExchangeRate::DatabaseConnection
- Inherits:
-
Object
- Object
- ExchangeRate::DatabaseConnection
- Defined in:
- lib/exchange_rate/database_connection.rb
Overview
Database connection management for ::ExchangeRate.
Class Method Summary collapse
-
.apply_migrations(connection) ⇒ Object
Apply the schema definitions to the database.
-
.connection ⇒ Object
Establish a connection to the database, and ensure the schema is loaded.
-
.disconnect ⇒ Object
Closes any open connections to the database and removes the cached connection.
Class Method Details
.apply_migrations(connection) ⇒ Object
Apply the schema definitions to the database.
Returns nothing
32 33 34 35 |
# File 'lib/exchange_rate/database_connection.rb', line 32 def self.apply_migrations(connection) return if connection.nil? Sequel::Migrator.run(connection, 'lib/exchange_rate/db/migrate/') end |
.connection ⇒ Object
Establish a connection to the database, and ensure the schema is loaded. The connection is cached and kept open.
Returns nothing
16 17 18 19 |
# File 'lib/exchange_rate/database_connection.rb', line 16 def self.connection database_url = ExchangeRate.configuration.datastore_url @connection ||= Sequel.connect(database_url).tap { |connection| apply_migrations(connection) } end |
.disconnect ⇒ Object
Closes any open connections to the database and removes the cached connection.
23 24 25 26 |
# File 'lib/exchange_rate/database_connection.rb', line 23 def self.disconnect @connection&.disconnect @connection = nil end |