1 package SQL::Translator::Schema;
3 # ----------------------------------------------------------------------
4 # $Id: Schema.pm,v 1.1 2003-05-01 04:24:59 kycl4rk Exp $
5 # ----------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
27 SQL::Translator::Schema - SQL::Translator schema object
31 use SQL::Translator::Schema;
32 my $schema = SQL::Translator::Schema->new;
33 my $foo_table = $schema->add_table( name => 'foo' );
35 $foo_table->add_field(
37 data_type => 'integer',
42 $foo_table->add_field(
48 $foo_table->add_index(
50 fields => [ 'foo_name' ],
53 my $view = $schema->add_view(...);
57 C<SQL::Translator::Schema> is the object that accepts, validates, and
58 returns the database structure.
66 use SQL::Translator::Schema::Table;
67 use SQL::Translator::Schema::View;
69 use base 'Class::Base';
70 use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
74 # ----------------------------------------------------------------------
83 my $schema = SQL::Translator->new;
87 my ( $self, $config ) = @_;
92 # ----------------------------------------------------------------------
99 Add a constraint object. Returns the new
100 SQL::Translator::Schema::Constraint object.
102 my $constraint = $table->add_constraint( name => 'foo' );
107 my $table = SQL::Translator::Schema::Constraint->new( @_ ) or return
108 SQL::Translator::Schema::Constraint->error;
110 $self->{'tables'}{ $table->name } = $table;
111 $self->{'tables'}{ $table->name }{'order'} = ++$TABLE_COUNT;
116 # ----------------------------------------------------------------------
123 Add a table object. Returns the new SQL::Translator::Schema::Table object.
125 my $table = $schema->add_table( name => 'foo' );
130 my $table = SQL::Translator::Schema::Table->new( @_ ) or return
131 SQL::Translator::Schema::Table->error;
133 $self->{'tables'}{ $table->name } = $table;
134 $self->{'tables'}{ $table->name }{'order'} = ++$TABLE_COUNT;
139 # ----------------------------------------------------------------------
146 Add a view object. Returns the new SQL::Translator::Schema::View object.
148 my $view = $schema->add_view( name => 'foo' );
153 my $view = SQL::Translator::Schema::View->new( @_ ) or return
154 SQL::Translator::Schema::View->error;
156 $self->{'views'}{ $view->name } = $view;
157 $self->{'views'}{ $view->name }{'order'} = ++$VIEW_COUNT;
164 # ----------------------------------------------------------------------
170 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>