class Natural::Database

Attributes

identifier[R]

Public Class Methods

new(identifier) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 9
def initialize(identifier)
  @identifier = identifier
end

Public Instance Methods

create() click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 40
def create
  connection.exec(
    """
    CREATE DATABASE \"#{@identifier}\"
    """
  )
  self
end
create_table(table_identifier) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 20
def create_table(table_identifier)
  table(table_identifier).create
end
destroy() click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 49
def destroy
  connection.exec(
    """
    DROP DATABASE \"#{@identifier}\";
    """
  )
end
destroy_table(table_identifier) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 24
def destroy_table(table_identifier)
  table(table_identifier).destroy
end
exists?() click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 57
def exists?
  '1' == connection.exec(
    """
    SELECT 1 FROM pg_database WHERE pg_database.datname = \'#{@identifier}\';
    """
  ).values[0].try(:[], 0)
end
table(table_identifier) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 13
def table(table_identifier)
  table = Table.new(table_identifier)
  table.connection = connection.clone_with_database(self)
  table.database = self
  table
end
table_exists?(table_identifier) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 28
def table_exists?(table_identifier)
  table(table_identifier).exists?
end
tables(associated_db_user) click to toggle source
# File natural-backend/lib/database_manager/lib/database.rb, line 32
def tables(associated_db_user)
  connection.exec(
    """
    SELECT tablename FROM pg_catalog.pg_tables WHERE tableowner = \'#{associated_db_user}\';
    """
  )
end