Dave Rolsky > Fey-0.40 > Fey::Schema

Download:
Fey-0.40.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  3
Open  2
View/Report Bugs
Module Version: 0.40   Source  

NAME ^

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

VERSION ^

version 0.40

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:

$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. Tables are returned in the order with which they were added to 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.

BUGS ^

See Fey for details on how to report bugs.

AUTHOR ^

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2011 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: