Module: DbAgile::Contract::Schema::TableDriven

Included in:
Utils::Full
Defined in:
lib/dbagile/contract/schema/table_driven.rb

Overview

Table-driven adapter read-only methods about schemas.

Instance Method Summary collapse

Instance Method Details

#column_names(table_name, sort = false) ⇒ Array<Symbol>

Returns the list of column names for a given table.

Parameters:

  • table_name (Symbol)

    the name of a table

  • sort (Boolean) (defaults to: false)

    sort column by names?

Returns:

  • (Array<Symbol>)

    column names



55
56
57
# File 'lib/dbagile/contract/schema/table_driven.rb', line 55

def column_names(table_name, sort = false)
  Kernel.raise NotImplementedError
end

#has_column?(table_name, column_name) ⇒ Boolean

Returns true if a column exists, false otherwise.

A default implementation is provided that relies on column_names.

Parameters:

  • table_name (Symbol)

    the name of a table

  • column_name (Symbol)

    the name of a column

Returns:

  • (Boolean)

    true if the column exists on that table, false otherwise



30
31
32
# File 'lib/dbagile/contract/schema/table_driven.rb', line 30

def has_column?(table_name, column_name)
  column_names(table_name).include?(column_name)
end

#has_table?(table_name) ⇒ Boolean

Returns true if a given table exists in the database, false otherwise.

Parameters:

  • table_name (Symbol)

    name of a table

Returns:

  • (Boolean)

    true if the table exists, false otherwise



15
16
17
# File 'lib/dbagile/contract/schema/table_driven.rb', line 15

def has_table?(table_name)
  Kernel.raise NotImplementedError
end

#heading(table_name) ⇒ Hash<Symbol => Class>

Returns the heading of a given table.

Parameters:

  • table_name (Symbol)

    the name of a table

Returns:

  • (Hash<Symbol => Class>)

    table heading



42
43
44
# File 'lib/dbagile/contract/schema/table_driven.rb', line 42

def heading(table_name)
  Kernel.raise NotImplementedError
end

#is_key?(table_name, columns) ⇒ Boolean

Checks if an array of column names for a key for a given table.

Parameters:

  • table_name (Symbol)

    the name of a table

  • columns (Array<Symbol>)

    column names, in any order

Returns:

  • (Boolean)

    true if the table contains such a unique key, false otherwise



69
70
71
# File 'lib/dbagile/contract/schema/table_driven.rb', line 69

def is_key?(table_name, columns)
  keys(table_name).include?(columns)
end

#keys(table_name) ⇒ Array<Array<Symbol>>

Returns available keys for a given table as an array of column names.

Parameters:

  • table_name (Symbol)

    the name of a table

Returns:

  • (Array<Array<Symbol>>)

    keys of the table



82
83
84
# File 'lib/dbagile/contract/schema/table_driven.rb', line 82

def keys(table_name)
  Kernel.raise NotImplementedError
end