class Natural::Connection

Attributes

database[RW]
db_user[RW]

Public Instance Methods

clone_with_database(database) click to toggle source
# File natural-backend/lib/database_manager/lib/connection.rb, line 35
def clone_with_database(database)
  clone = self.class.new
  clone.db_user = self.db_user
  clone.database = database
  clone.establish_connection
  clone
end
close() click to toggle source
# File natural-backend/lib/database_manager/lib/connection.rb, line 6
def close
  @connection.close
end
establish_connection() click to toggle source
# File natural-backend/lib/database_manager/lib/connection.rb, line 10
def establish_connection
  options_hash = {
    user: @db_user.username,
    password: @db_user.password
  }

  if database.present?
    options_hash.merge!({dbname: database.identifier})
  end
  
  @connection = PG.connect(options_hash)

end
exec(*args, &block) click to toggle source
# File natural-backend/lib/database_manager/lib/connection.rb, line 31
def exec(*args, &block)
  @connection.exec(*args, &block)
end
load_rails_database_config() click to toggle source
# File natural-backend/lib/database_manager/lib/connection.rb, line 24
def load_rails_database_config
  config = Rails.configuration.database_configuration[Rails.env]

  @db_user = ::Natural::DatabaseUser.new(config['username'],
                                        config['password'])
end