The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SQL::Translator::Schema - SQL::Translator schema object

SYNOPSIS

  use SQL::Translator::Schema;
  my $schema = SQL::Translator::Schema->new;
  my $table  = $schema->add_table( name => 'foo' );
  my $view   = $schema->add_view( name => 'bar', sql => '...' );

DESCSIPTION

SQL::Translator::Schema is the object that accepts, validates, and returns the database structure.

METHODS

new

Object constructor.

  my $schema   =  SQL::Translator->new(
      name     => 'Foo',
      database => 'MySQL',
  );

add_table

Add a table object. Returns the new SQL::Translator::Schema::Table object. The "name" parameter is required. If you try to create a table with the same name as an existing table, you will get an error and the table will not be created.

  my $t1 = $schema->add_table( name => 'foo' ) or die $schema->error;
  my $t2 = SQL::Translator::Schema::Table->new( name => 'bar' );
  $t2    = $schema->add_table( $table_bar ) or die $schema->error;

add_view

Add a view object. Returns the new SQL::Translator::Schema::View object. The "name" parameter is required. If you try to create a view with the same name as an existing view, you will get an error and the view will not be created.

  my $v1 = $schema->add_view( name => 'foo' );
  my $v2 = SQL::Translator::Schema::View->new( name => 'bar' );
  $v2    = $schema->add_view( $view_bar ) or die $schema->error;

database

Get or set the schema's database. (optional)

  my $database = $schema->database('PostgreSQL');

is_valid

Returns true if all the tables and views are valid.

  my $ok = $schema->is_valid or die $schema->error;

get_table

Returns a table by the name provided.

  my $table = $schema->get_table('foo');

get_tables

Returns all the tables as an array or array reference.

  my @tables = $schema->get_tables;

get_view

Returns a view by the name provided.

  my $view = $schema->get_view('foo');

get_views

Returns all the views as an array or array reference.

  my @views = $schema->get_views;

make_natural_joins

Creates foriegn key relationships among like-named fields in different tables. Accepts the following arguments:

  • join_pk_only

    A True or False argument which determins whether or not to perform the joins from primary keys to fields of the same name in other tables

  • skip_fields

    A list of fields to skip in the joins

  $schema->make_natural_joins(
      join_pk_only => 1,
      skip_fields  => 'name,department_id',
  );

name

Get or set the schema's name. (optional)

  my $schema_name = $schema->name('Foo Database');

AUTHOR

Ken Y. Clark <kclark@cpan.org>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 329:

=back doesn't take any parameters, but you said =back 4