Alzabo::RDBMSRules - Base class for Alzabo RDBMS rulesets


NAME

Alzabo::RDBMSRules - Base class for Alzabo RDBMS rulesets


SYNOPSIS

  use Alzabo::RDBMSRules;
  my $rules = Alzabo::RDBMSRules( rules => 'MySQL' );


DESCRIPTION

This class is the base class for all Alzabo::RDBMSRules modules. To instantiate a subclass call this class's new method. See the SUBCLASSING Alzabo::RDBMSRules section for information on how to make a ruleset for the RDBMS of your choice.


METHODS

available

A list of names representing the available Alzabo::RDBMSRules subclasses. Any one of these names would be appropriate as the rdbms parameter for the Alzabo::RDBMSRules->new method.

new

Parameters

Some subclasses may accept additional values.

Returns

A new Alzabo::RDBMSRules object of the appropriate subclass.

schema_sql (Alzabo::Create::Schema object)

Returns

A list of SQL statements.

index_sql (Alzabo::Create::Index object)

Returns

A list of SQL statements.

drop_table_sql (Alzabo::Create::Table object)

Returns

A list of SQL statements.

drop_index_sql (Alzabo::Create::Index object)

Returns

A list of SQL statements.

schema_sql_diff

Parameters

Given two schema objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

An array of SQL statements.

table_sql_diff

Parameters

Given two table objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

An array of SQL statements.

Virtual Methods

The following methods are not implemented in the Alzabo::RDBMSRules class itself and must be implemented in its subclasses.

column_types

Returns

A list of valid column type specifiers.

feature ($feature)

Given a string defining a feature, this method indicates whether or not the given RDBMS supports that feature. By default, this method always returns false unless overridden in the subclass.

Features that may be asked for:

validate_schema_name (Alzabo::Schema object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_table_name (Alzabo::Create::Table object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_column_name (Alzabo::Create::Column object)

Returns

A boolean value indicate whether the object's name is valid.

Throws

Alzabo::Exception::RDBMSRules

validate_column_type ($type_as_string)

Returns

A canonized version of the type.

Throws

Alzabo::Exception::RDBMSRules

validate_column_attribute

Parameters

This method is a bit different from the others in that it takes an existing column object and a potential attribute.

Returns

A boolean value indicating whether or not this attribute is acceptable for the column.

Throws

Alzabo::Exception::RDBMSRules

validate_primary_key (Alzabo::Create::Column object)

Returns

Returns a boolean value indicating whether or not the given column can be part of its table's primary key.

Throws

Alzabo::Exception::RDBMSRules

validate_sequenced_attribute (Alzabo::Create::Column object)

Given a column object, indicates whether or not the column can be sequenced.

Throws

Alzabo::Exception::RDBMSRules

validate_index (Alzabo::Create::Index object)

Returns

A boolean value indicating whether or not the index is valid.

Throws

Alzabo::Exception::RDBMSRules

table_sql (Alzabo::Create::Table object)

Returns

A list of SQL statements.

column_sql (Alzabo::Create::Column object)

Returns

A list of SQL statements.

foreign_key_sql (Alzabo::Create::ForeignKey object)

Returns

A list of SQL statements.

drop_column_sql (Alzabo::Create::Column object)

Returns

A list of SQL statements.

drop_foreign_key_sql (Alzabo::Create::ForeignKey object)

Returns

A list of SQL statements.

column_sql_add (Alzabo::Create::Column object)

Returns

A list of SQL statements.

column_sql_diff

Parameters

Given two column objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

index_sql_diff

Parameters

Given two index objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

foreign_key_sql_diff

Parameters

Given two foreign key objects, this method compares them and generates the SQL necessary to turn the 'old' one into the 'new' one.

Returns

A list of SQL statements.

alter_primary_key_sql

Parameters

Given two table objects, this method compares them and generates the SQL necessary to give change the primary key from the 'old' one's primary key to the 'new' one's primary key.

Returns

A list of SQL statements.

reverse_engineer (Alzabo::Create::Schema object)

Given a schema object (which presumably has no tables), this method uses the schema's Alzabo::Driver object to connect to an existing database and reverse engineer it into the appopriate Alzabo objects.


SUBCLASSING Alzabo::RDBMSRules

To create a subclass of Alzabo::RDBMSRules for your particular RDBMS is fairly simple.

Here's a sample header to the module using a fictional RDBMS called FooDB:

 package Alzabo::RDBMSRules::FooDB;
 use strict;
 use vars qw($VERSION);
 use Alzabo::RDBMSRules;
 use base qw(Alzabo::RDBMSRules);

The next step is to implement a new method and the methods listed under the section Virtual Methods. The new method should look a bit like this:

 1:  sub new
 2:  {
 3:      my $proto = shift;
 4:      my $class = ref $proto || $proto;
 5:      my %p = @_;
 6:
 7:      my $self = bless {}, $self;
 8:
 9:      return $self;
 10:  }

The hash %p contains any values passed to the Alzabo::RDBMSRules->new method by its caller.

Lines 1-7 should probably be copied verbatim into your own new method. Line 5 can be deleted if you don't need to look at the parameters.

The rest of your module should simply implement the methods listed under the Virtual Methods section of this documentation.

Look at the included Alzabo::RDBMSRules subclasses for examples. Feel free to contact me for further help if you get stuck. Please tell me what database you're attempting to implement, and include the code you've written so far.


AUTHOR

Dave Rolsky, <dave@urth.org>

 Alzabo::RDBMSRules - Base class for Alzabo RDBMS rulesets