1SQL::Translator::SchemaU:s:eTrabCloen(t3r)ibuted Perl DoScQuLm:e:nTtraatnisolnator::Schema::Table(3)
2
3
4
6 SQL::Translator::Schema::Table - SQL::Translator table object
7
9 use SQL::Translator::Schema::Table;
10 my $table = SQL::Translator::Schema::Table->new( name => 'foo' );
11
13 "SQL::Translator::Schema::Table" is the table object.
14
16 new
17
18 Object constructor.
19
20 my $table = SQL::Translator::Schema::Table->new(
21 schema => $schema,
22 name => 'foo',
23 );
24
25 add_constraint
26
27 Add a constraint to the table. Returns the newly created "SQL::Trans‐
28 lator::Schema::Constraint" object.
29
30 my $c1 = $table->add_constraint(
31 name => 'pk',
32 type => PRIMARY_KEY,
33 fields => [ 'foo_id' ],
34 );
35
36 my $c2 = SQL::Translator::Schema::Constraint->new( name => 'uniq' );
37 $c2 = $table->add_constraint( $constraint );
38
39 drop_constraint
40
41 Remove a constraint from the table. Returns the constraint object if
42 the index was found and removed, an error otherwise. The single parame‐
43 ter can be either an index name or an "SQL::Translator::Schema::Con‐
44 straint" object.
45
46 $table->drop_constraint('myconstraint');
47
48 add_index
49
50 Add an index to the table. Returns the newly created "SQL::Transla‐
51 tor::Schema::Index" object.
52
53 my $i1 = $table->add_index(
54 name => 'name',
55 fields => [ 'name' ],
56 type => 'normal',
57 );
58
59 my $i2 = SQL::Translator::Schema::Index->new( name => 'id' );
60 $i2 = $table->add_index( $index );
61
62 drop_index
63
64 Remove an index from the table. Returns the index object if the index
65 was found and removed, an error otherwise. The single parameter can be
66 either an index name of an "SQL::Translator::Schema::Index" object.
67
68 $table->drop_index('myindex');
69
70 add_field
71
72 Add an field to the table. Returns the newly created "SQL::Transla‐
73 tor::Schema::Field" object. The "name" parameter is required. If you
74 try to create a field with the same name as an existing field, you will
75 get an error and the field will not be created.
76
77 my $f1 = $table->add_field(
78 name => 'foo_id',
79 data_type => 'integer',
80 size => 11,
81 );
82
83 my $f2 = SQL::Translator::Schema::Field->new(
84 name => 'name',
85 table => $table,
86 );
87 $f2 = $table->add_field( $field2 ) or die $table->error;
88
89 drop_field
90
91 Remove a field from the table. Returns the field object if the field
92 was found and removed, an error otherwise. The single parameter can be
93 either a field name or an "SQL::Translator::Schema::Field" object.
94
95 $table->drop_field('myfield');
96
97 comments
98
99 Get or set the comments on a table. May be called several times to set
100 and it will accumulate the comments. Called in an array context,
101 returns each comment individually; called in a scalar context, returns
102 all the comments joined on newlines.
103
104 $table->comments('foo');
105 $table->comments('bar');
106 print join( ', ', $table->comments ); # prints "foo, bar"
107
108 get_constraints
109
110 Returns all the constraint objects as an array or array reference.
111
112 my @constraints = $table->get_constraints;
113
114 get_indices
115
116 Returns all the index objects as an array or array reference.
117
118 my @indices = $table->get_indices;
119
120 get_field
121
122 Returns a field by the name provided.
123
124 my $field = $table->get_field('foo');
125
126 get_fields
127
128 Returns all the field objects as an array or array reference.
129
130 my @fields = $table->get_fields;
131
132 is_valid
133
134 Determine whether the view is valid or not.
135
136 my $ok = $view->is_valid;
137
138 is_trivial_link
139
140 True if table has no data (non-key) fields and only uses single key
141 joins.
142
143 is_data
144
145 Returns true if the table has some non-key fields.
146
147 can_link
148
149 Determine whether the table can link two arg tables via many-to-many.
150
151 my $ok = $table->can_link($table1,$table2);
152
153 name
154
155 Get or set the table's name.
156
157 Errors ("No table name") if you try to set a blank name.
158
159 If provided an argument, checks the schema object for a table of that
160 name and disallows the change if one exists (setting the error to
161 "Can't use table name "%s": table exists").
162
163 my $table_name = $table->name('foo');
164
165 schema
166
167 Get or set the table's schema object.
168
169 my $schema = $table->schema;
170
171 primary_key
172
173 Gets or sets the table's primary key(s). Takes one or more field names
174 (as a string, list or array[ref]) as an argument. If the field names
175 are present, it will create a new PK if none exists, or it will add to
176 the fields of an existing PK (and will unique the field names).
177 Returns the "SQL::Translator::Schema::Constraint" object representing
178 the primary key.
179
180 These are eqivalent:
181
182 $table->primary_key('id');
183 $table->primary_key(['name']);
184 $table->primary_key('id','name']);
185 $table->primary_key(['id','name']);
186 $table->primary_key('id,name');
187 $table->primary_key(qw[ id name ]);
188
189 my $pk = $table->primary_key;
190
191 options
192
193 Get or set the table's options (e.g., table types for MySQL). Returns
194 an array or array reference.
195
196 my @options = $table->options;
197
198 order
199
200 Get or set the table's order.
201
202 my $order = $table->order(3);
203
204 field_names
205
206 Read-only method to return a list or array ref of the field names.
207 Returns undef or an empty list if the table has no fields set. Usefull
208 if you want to avoid the overload magic of the Field objects returned
209 by the get_fields method.
210
211 my @names = $constraint->field_names;
212
213 equals
214
215 Determines if this table is the same as another
216
217 my $isIdentical = $table1->equals( $table2 );
218
220 The following are a set of shortcut methods for getting commonly used
221 lists of fields and constraints. They all return lists or array refs of
222 Field or Constraint objects.
223
224 pkey_fields
225 The primary key fields.
226
227 fkey_fields
228 All foreign key fields.
229
230 nonpkey_fields
231 All the fields except the primary key.
232
233 data_fields
234 All non key fields.
235
236 unique_fields
237 All fields with unique constraints.
238
239 unique_constraints
240 All this tables unique constraints.
241
242 fkey_constraints
243 All this tables foreign key constraints. (See primary_key method to
244 get the primary key constraint)
245
247 Ken Y. Clark <kclark@cpan.org>, Allen Day <allenday@ucla.edu>.
248
249
250
251perl v5.8.8 2007-10-24 SQL::Translator::Schema::Table(3)