Class: Pgchief::Command::DatabaseDrop

Inherits:
Base
  • Object
show all
Defined in:
lib/pgchief/command/database_drop.rb

Overview

Command object to drop a database

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #params

Instance Method Summary collapse

Methods inherited from Base

call, #initialize

Constructor Details

This class inherits a constructor from Pgchief::Command::Base

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



7
8
9
# File 'lib/pgchief/command/database_drop.rb', line 7

def database
  @database
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pgchief/command/database_drop.rb', line 9

def call
  @database = params.first

  return "Database '#{database}' does not exist." unless db_exists?

  conn.exec("DROP DATABASE #{database}")
  "Database '#{database}' dropped successfully!"
rescue PG::Error => e
  "Error: #{e.message}"
ensure
  conn.close
end