Alzabo (version 0.92)

Doc index

TOC | Top

NAME

Alzabo::Create::Table - Table objects for schema creation

TOC | Top

SYNOPSIS

  use Alzabo::Create::Table;
TOC | Top

DESCRIPTION

This class represents tables in the schema. It contains column, index, and foreign key objects.

TOC | Top

INHERITS FROM

Alzabo::Table

Note: all relevant documentation from the superclass has been merged into this document.

TOC | Top

METHODS

new

The constructor takes the following parameters:

It returns a new Alzabo::Create::Table object.

Throws: Alzabo::Exception::Params

TOC | Top

schema

Returns the Alzabo::Create::Schema object to which this table belongs.

TOC | Top

name

Returns the name of the table.

TOC | Top

set_name ($name)

Changes the name of the table.

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules

TOC | Top

column ($name)

Returns the Alzabo::Create::Column object that matches the name given.

An Alzabo::Exception::Params exception is throws if the table does not contain the column.

TOC | Top

columns (@optional_list_of_column_names)

If no arguments are given, returns a list of all Alzabo::Create::Column objects in the schema, or in a scalar context the number of such tables. If one or more arguments are given, returns a list of table objects with those names, in the same order given.

An Alzabo::Exception::Params exception is throws if the table does not contain one or more of the specified columns.

TOC | Top

has_column ($name)

Returns a voolean value indicating whether the column exists in the table.

TOC | Top

make_column

Creates a new Alzabo::Create::Column object and adds it to the table. This object is the function's return value.

In addition, if a "before" or "after" parameter is given, the move_column() method is called to move the new column.

This method takes all of the same parameters as the Alzabo::Create::Column->new() method except the "table" parameter, which is automatically supplied.

This method also accepts an additional parameter, "primary_key", indicating whether or not the column is part of the table's primary key.

Returns a new Alzabo::Create::Column object.

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules

TOC | Top

add_column

Adds a column to the table. If a "before" or "after" parameter is given then the move_column() method will be called to move the new column to the appropriate position.

It takes the following parameters:

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules

TOC | Top

delete_column (Alzabo::Create::Column object)

Deletes a column from the table.

Throws: Alzabo::Exception::Params

TOC | Top

move_column

This method takes the following parameters:

Throws: Alzabo::Exception::Params

TOC | Top

primary_key

In array context, return an ordered list of column objects that make up the primary key for the table. In scalar context, it returns the first element of that list.

TOC | Top

primary_key_size

The number of columns in the table's primary key.

TOC | Top

add_primary_key (Alzabo::Create::Column object)

Make the given column part of the table's primary key. The primary key is an ordered list of columns. The given column will be added to the end of this list.

Throws: Alzabo::Exception::Params

TOC | Top

delete_primary_key (Alzabo::Create::Column object)

Delete the given column from the primary key.

Throws: Alzabo::Exception::Params

TOC | Top

foreign_keys

Thie method takes two parameters:

It returns a list of Alzabo::Create::ForeignKey objects from the given column to the given table, if they exist. In scalar context, it returns the first item in the list. There is no guarantee as to what the first item will be.

An Alzabo::Exception::Params exception is throws if the table does not contain the specified column.

TOC | Top

foreign_keys_by_table (Alzabo::Create::Table object)

Returns a list of all the Alzabo::Create::ForeignKey objects to the given table. In scalar context, it returns the first item in the list. There is no guarantee as to what the first item will be.

TOC | Top

foreign_keys_by_column (Alzabo::Create::Column object)

Returns a list of all the Alzabo::Create::ForeignKey objects that the given column is a part of, if any. In scalar context, it returns the first item in the list. There is no guarantee as to what the first item will be.

An Alzabo::Exception::Params exception is throws if the table does not contain the specified column.

TOC | Top

all_foreign_keys

Returns a list of all the Alzabo::Create::ForeignKey objects for this table. In scalar context, it returns the first item in the list. There is no guarantee as to what the first item will be.

TOC | Top

make_foreign_key (see below)

Takes the same parameters as the Alzabo::Create::ForeignKey->new method except for the table parameter, which is automatically added. The foreign key object that is created is then added to the table.

If the foreign key being made is 1..1 or 1..n, then a unique index will be created on the columns involved in the "1" side of the foreign key, unless they are the table's primary key.

Returns a new Alzabo::Create::ForeignKey object.

Throws: Alzabo::Exception::Params

TOC | Top

add_foreign_key (Alzabo::Create::ForeignKey object)

Adds the given foreign key to the table.

Throws: Alzabo::Exception::Params

TOC | Top

delete_foreign_key (Alzabo::Create::ForeignKey object)

Deletes the given foreign key from the table

Throws: Alzabo::Exception::Params

TOC | Top

index ($index_id)

This method expects an index id as returned by the Alzabo::Create::Index->id method as its parameter.

The Alzabo::Create::Index object matching this id, if it exists in the table.

An Alzabo::Exception::Params exception is throws if the table does not contain the specified index.

TOC | Top

has_index ($index_id)

This method expects an index id as returned by the Alzabo::Create::Index->id method as its parameter.

Returns a boolean indicating whether the table has an index with the same id.

TOC | Top

indexes

Returns all the Alzabo::Create::Index objects for the table.

TOC | Top

make_index

Takes the same parameters as the Alzabo::Create::Index->new() method except for the "table" parameter, which is automatically added. The index object that is created is then added to the table.

Returns the new Alzabo::Create::Index object.

Throws: Alzabo::Exception::Params

TOC | Top

add_index (Alzabo::Create::Index object)

Adds the given index to the table.

Throws: Alzabo::Exception::Params

TOC | Top

delete_index (Alzabo::Create::Index object)

Deletes the specified index from the table.

Throws: Alzabo::Exception::Params

TOC | Top

attributes

A table's attributes are strings describing the table (for example, valid attributes in MySQL are thing like "TYPE = INNODB".

Returns a list of strings.

TOC | Top

has_attribute

This method can be used to test whether or not a table has a particular attribute. By default, the check is case-insensitive.

Returns a boolean value indicating whether the table has this particular attribute.

TOC | Top

set_attributes (@attributes)

Sets the tables's attributes. These are strings describing the table (for example, valid attributes in MySQL are "TYPE = INNODB" or "AUTO_INCREMENT = 100").

You can also set table constraints as attributes. Alzabo will generate correct SQL for both actual attributes and constraints.

TOC | Top

add_attribute ($attribute)

Add an attribute to the column's list of attributes.

TOC | Top

delete_attribute ($attribute)

Delete the given attribute from the column's list of attributes.

Alzabo::Exception::Params

TOC | Top

former_name

If the table's name has been changed since the last time the schema was instantiated, this method returns the table's previous name.

TOC | Top

comment

Returns the comment associated with the table object, if any.

TOC | Top

set_comment ($comment)

Set the comment for the table object.

TOC | Top

AUTHOR

Dave Rolsky, <autarch@urth.org>


Table of Contents

- NAME
- SYNOPSIS
- DESCRIPTION
- INHERITS FROM
- METHODS
      - new
                  - schema => Alzabo::Create::Schema object
                  - name => $name
                  - attributes => \@attributes
                  - comment => $comment
      - schema
      - name
      - set_name ($name)
      - column ($name)
      - columns (@optional_list_of_column_names)
      - has_column ($name)
      - make_column
      - add_column
                  - column => Alzabo::Create::Column object
                  - after => Alzabo::Create::Column object (optional)
                  - before => Alzabo::Create::Column object (optional)
      - delete_column (Alzabo::Create::Column object)
      - move_column
                  - column => Alzabo::Create::Column object
                  - before => Alzabo::Create::Column object
                  - after => Alzabo::Create::Column object
      - primary_key
      - primary_key_size
      - add_primary_key (Alzabo::Create::Column object)
      - delete_primary_key (Alzabo::Create::Column object)
      - foreign_keys
                  - column => Alzabo::Create::Column object
                  - table => Alzabo::Create::Table object
      - foreign_keys_by_table (Alzabo::Create::Table object)
      - foreign_keys_by_column (Alzabo::Create::Column object)
      - all_foreign_keys
      - make_foreign_key (see below)
      - add_foreign_key (Alzabo::Create::ForeignKey object)
      - delete_foreign_key (Alzabo::Create::ForeignKey object)
      - index ($index_id)
      - has_index ($index_id)
      - indexes
      - make_index
      - add_index (Alzabo::Create::Index object)
      - delete_index (Alzabo::Create::Index object)
      - attributes
      - has_attribute
                  - attribute => $attribute
                  - case_sensitive => 0 or 1 (defaults to 0)
      - set_attributes (@attributes)
      - add_attribute ($attribute)
      - delete_attribute ($attribute)
      - former_name
      - comment
      - set_comment ($comment)
- AUTHOR