Module: DynamicMigrations::Postgres::Connections

Defined in:
lib/dynamic_migrations/postgres/connections.rb

Class Method Summary collapse

Class Method Details

.connectionsObject



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_allObject



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