More changes to getting the schema to a working state.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema.pm
CommitLineData
3c5de62a 1package SQL::Translator::Schema;
2
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>
7#
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.
11#
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.
16#
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
20# 02111-1307 USA
21# -------------------------------------------------------------------
22
23=pod
24
25=head1 NAME
26
27SQL::Translator::Schema - SQL::Translator schema object
28
29=head1 SYNOPSIS
30
31 use SQL::Translator::Schema;
32 my $schema = SQL::Translator::Schema->new;
33 my $foo_table = $schema->add_table( name => 'foo' );
34
35 $foo_table->add_field(
36 name => 'foo_id',
37 data_type => 'integer',
38 size => 11,
39 is_primary_key => 1,
40 );
41
42 $foo_table->add_field(
43 name => 'foo_name',
44 data_type => 'char',
45 size => 10,
46 );
47
48 $foo_table->add_index(
49 name => '',
50 fields => [ 'foo_name' ],
51 );
52
53 my $view = $schema->add_view(...);
54
55=head1 DESCSIPTION
56
57C<SQL::Translator::Schema> is the object that accepts, validates, and
58returns the database structure.
59
60=head1 METHODS
61
62=cut
63
64use strict;
65use Class::Base;
66use SQL::Translator::Schema::Table;
67use SQL::Translator::Schema::View;
68
69use base 'Class::Base';
70use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
71
72$VERSION = 1.00;
73
74# ----------------------------------------------------------------------
75sub init {
76
77=pod
78
79=head2 new
80
81Object constructor.
82
83 my $schema = SQL::Translator->new;
84
85=cut
86
87 my ( $self, $config ) = @_;
88 # empty for now
89 return $self;
90}
91
92# ----------------------------------------------------------------------
93sub add_constraint {
94
95=pod
96
97=head2 add_constraint
98
99Add a constraint object. Returns the new
100SQL::Translator::Schema::Constraint object.
101
102 my $constraint = $table->add_constraint( name => 'foo' );
103
104=cut
105
106 my $self = shift;
107 my $table = SQL::Translator::Schema::Constraint->new( @_ ) or return
108 SQL::Translator::Schema::Constraint->error;
109
110 $self->{'tables'}{ $table->name } = $table;
111 $self->{'tables'}{ $table->name }{'order'} = ++$TABLE_COUNT;
112
113 return $table;
114}
115
116# ----------------------------------------------------------------------
117sub add_table {
118
119=pod
120
121=head2 add_table
122
123Add a table object. Returns the new SQL::Translator::Schema::Table object.
124
125 my $table = $schema->add_table( name => 'foo' );
126
127=cut
128
129 my $self = shift;
130 my $table = SQL::Translator::Schema::Table->new( @_ ) or return
131 SQL::Translator::Schema::Table->error;
132
133 $self->{'tables'}{ $table->name } = $table;
134 $self->{'tables'}{ $table->name }{'order'} = ++$TABLE_COUNT;
135
136 return $table;
137}
138
139# ----------------------------------------------------------------------
140sub add_view {
141
142=pod
143
144=head2 add_view
145
146Add a view object. Returns the new SQL::Translator::Schema::View object.
147
148 my $view = $schema->add_view( name => 'foo' );
149
150=cut
151
152 my $self = shift;
153 my $view = SQL::Translator::Schema::View->new( @_ ) or return
154 SQL::Translator::Schema::View->error;
155
156 $self->{'views'}{ $view->name } = $view;
157 $self->{'views'}{ $view->name }{'order'} = ++$VIEW_COUNT;
158
159 return $view;
160}
161
1621;
163
164# ----------------------------------------------------------------------
165
166=pod
167
168=head1 AUTHOR
169
170Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
171
172=cut