Class: Proxy::ContainerGateway::Database
- Inherits:
-
Object
- Object
- Proxy::ContainerGateway::Database
- Defined in:
- lib/smart_proxy_container_gateway/database.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(options = {}) ⇒ Database
Returns a new instance of Database.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smart_proxy_container_gateway/database.rb', line 7 def initialize( = {}) if [:database_backend] == 'sqlite' @connection = Sequel.connect("sqlite://#{[:sqlite_db_path]}", timeout: [:sqlite_timeout]) @connection.run("PRAGMA foreign_keys = ON;") @connection.run("PRAGMA journal_mode = wal;") else unless [:postgresql_connection_string] raise ArgumentError, 'PostgreSQL connection string is required' end @connection = Sequel.connect([:postgresql_connection_string]) if File.exist?([:sqlite_db_path]) && (!@connection.table_exists?(:repositories) || @connection[:repositories].count.zero?) migrate_to_postgres(Sequel.sqlite([:sqlite_db_path]), @connection) File.delete([:sqlite_db_path]) end end migrate end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/smart_proxy_container_gateway/database.rb', line 5 def connection @connection end |