Module: DynamicMigrations::Postgres::Connections
- Defined in:
- lib/dynamic_migrations/postgres/connections.rb
Class Method Summary collapse
- .connections ⇒ Object
- .create_connection(host, port, username, password, database) ⇒ Object
- .disconnect(connection) ⇒ Object
- .disconnect_all ⇒ Object
Class Method Details
.connections ⇒ Object
21 22 23 |
# File 'lib/dynamic_migrations/postgres/connections.rb', line 21 def self.connections @connections.keys end |
.create_connection(host, port, username, password, database) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dynamic_migrations/postgres/connections.rb', line 8 def self.create_connection host, port, username, password, database connection = PG.connect( host: host, port: port, user: username, password: password, dbname: database, sslmode: "prefer" ) @connections[connection] = true connection end |
.disconnect(connection) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/dynamic_migrations/postgres/connections.rb', line 25 def self.disconnect connection if @connections[connection] connection.close @connections.delete connection true else false end end |
.disconnect_all ⇒ Object
35 36 37 38 39 |
# File 'lib/dynamic_migrations/postgres/connections.rb', line 35 def self.disconnect_all @connections.keys.each do |connection| disconnect connection end end |