Class: Pgchief::Command::DatabaseCreate
- Defined in:
- lib/pgchief/command/database_create.rb
Overview
Command object to create a database
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Pgchief::Command::Base
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
7 8 9 |
# File 'lib/pgchief/command/database_create.rb', line 7 def database @database end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pgchief/command/database_create.rb', line 9 def call @database = params.first raise Pgchief::Errors::DatabaseExistsError if db_exists? conn.exec("CREATE DATABASE #{database}") conn.exec("REVOKE CONNECT ON DATABASE #{database} FROM PUBLIC") "Database '#{database}' created successfully!" rescue PG::Error => e "Error: #{e.}" ensure conn.close end |