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

NAME

Fey::Schema - Represents a schema and contains tables and foreign keys

SYNOPSIS

  my $schema = Fey::Schema->new( name => 'MySchema' );

  $schema->add_table(...);

  $schema->add_foreign_key(...);

DESCRIPTION

This class represents a schema, which is a set of tables and foreign keys.

METHODS

This class provides the following methods:

Fey::Schema->new()

  my $schema = Fey::Schema->new( name => 'MySchema' );

This method constructs a new Fey::Schema object. It takes the following parameters:

  • name - required

    The name of the schema.

$schema->name()

Returns the name of the schema.

$schema->add_table($table)

Adds the specified table to the schema. The table must be a Fey::Table object. Adding the table to the schema sets the schema for the table, so that $table->schema() returns the correct object.

If the table is already part of the schema, an exception will be thrown.

$schema->remove_table($table)

Remove the specified table from the schema. Removing the table also removes any foreign keys which reference the table. Removing the table unsets the schema for the table.

The table can be specified either by name or by passing in a Fey::Table object.

$schema->table($name)

Returns the table with the specified name. If no such table exists, this method returns false.

$schema->tables()

$schema->tables(@names)

When this method is called with no arguments, it returns all of the tables in the schema. If given a list of names, it returns only the specified tables. If a name is given which doesn't match a table in the schema, then it is ignored.

$schema->add_foreign_key($fk)

Adds the specified to the schema. The foreign key must be a Fey::FK object.

If the foreign key references tables which are not in the schema, an exception will be thrown.

$schema->remove_foreign_key($fk)

Removes the specified foreign key from the schema. The foreign key must be a Fey::FK object.

$schema->foreign_keys_for_table($table)

Returns all the foreign keys which reference the specified table. The table can be specified as a name or a Fey::Table object.

$schema->foreign_keys_between_tables( $source_table, $target_table )

Returns all the foreign keys which reference both tables. The tables can be specified as names, Fey::Table objects, or Fey::Table::Alias objects. If you provide any aliases, the foreign keys returned will contain columns from those aliases, not the real tables. This provides support for joining an alias in a SQL statement.

AUTHOR

Dave Rolsky, <autarch@urth.org>

BUGS

See Fey for details on how to report bugs.

COPYRIGHT & LICENSE

Copyright 2006-2009 Dave Rolsky, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.