1SQL::Translator::SchemaU:s:eTrabCloen(t3r)ibuted Perl DoScQuLm:e:nTtraatnisolnator::Schema::Table(3)
2
3
4

NAME

6       SQL::Translator::Schema::Table - SQL::Translator table object
7

SYNOPSIS

9         use SQL::Translator::Schema::Table;
10         my $table = SQL::Translator::Schema::Table->new( name => 'foo' );
11

DESCRIPTION

13       "SQL::Translator::Schema::Table" is the table object.
14

METHODS

16   new
17       Object constructor.
18
19         my $table  =  SQL::Translator::Schema::Table->new(
20             schema => $schema,
21             name   => 'foo',
22         );
23
24   add_constraint
25       Add a constraint to the table.  Returns the newly created
26       "SQL::Translator::Schema::Constraint" object.
27
28         my $c1     = $table->add_constraint(
29             name   => 'pk',
30             type   => PRIMARY_KEY,
31             fields => [ 'foo_id' ],
32         );
33
34         my $c2 = SQL::Translator::Schema::Constraint->new( name => 'uniq' );
35         $c2    = $table->add_constraint( $constraint );
36
37   drop_constraint
38       Remove a constraint from the table. Returns the constraint object if
39       the index was found and removed, an error otherwise. The single
40       parameter can be either an index name or an
41       "SQL::Translator::Schema::Constraint" object.
42
43         $table->drop_constraint('myconstraint');
44
45   add_index
46       Add an index to the table.  Returns the newly created
47       "SQL::Translator::Schema::Index" object.
48
49         my $i1     = $table->add_index(
50             name   => 'name',
51             fields => [ 'name' ],
52             type   => 'normal',
53         );
54
55         my $i2 = SQL::Translator::Schema::Index->new( name => 'id' );
56         $i2    = $table->add_index( $index );
57
58   drop_index
59       Remove an index from the table. Returns the index object if the index
60       was found and removed, an error otherwise. The single parameter can be
61       either an index name of an "SQL::Translator::Schema::Index" object.
62
63         $table->drop_index('myindex');
64
65   add_field
66       Add an field to the table.  Returns the newly created
67       "SQL::Translator::Schema::Field" object.  The "name" parameter is
68       required.  If you try to create a field with the same name as an
69       existing field, you will get an error and the field will not be
70       created.
71
72         my $f1        =  $table->add_field(
73             name      => 'foo_id',
74             data_type => 'integer',
75             size      => 11,
76         );
77
78         my $f2     =  SQL::Translator::Schema::Field->new(
79             name   => 'name',
80             table  => $table,
81         );
82         $f2 = $table->add_field( $field2 ) or die $table->error;
83
84   drop_field
85       Remove a field from the table. Returns the field object if the field
86       was found and removed, an error otherwise. The single parameter can be
87       either a field name or an "SQL::Translator::Schema::Field" object.
88
89         $table->drop_field('myfield');
90
91   comments
92       Get or set the comments on a table.  May be called several times to set
93       and it will accumulate the comments.  Called in an array context,
94       returns each comment individually; called in a scalar context, returns
95       all the comments joined on newlines.
96
97         $table->comments('foo');
98         $table->comments('bar');
99         print join( ', ', $table->comments ); # prints "foo, bar"
100
101   get_constraints
102       Returns all the constraint objects as an array or array reference.
103
104         my @constraints = $table->get_constraints;
105
106   get_indices
107       Returns all the index objects as an array or array reference.
108
109         my @indices = $table->get_indices;
110
111   get_field
112       Returns a field by the name provided.
113
114         my $field = $table->get_field('foo');
115
116   get_fields
117       Returns all the field objects as an array or array reference.
118
119         my @fields = $table->get_fields;
120
121   is_valid
122       Determine whether the view is valid or not.
123
124         my $ok = $view->is_valid;
125
126   is_trivial_link
127       True if table has no data (non-key) fields and only uses single key
128       joins.
129
130   is_data
131       Returns true if the table has some non-key fields.
132
133   can_link
134       Determine whether the table can link two arg tables via many-to-many.
135
136         my $ok = $table->can_link($table1,$table2);
137
138   name
139       Get or set the table's name.
140
141       Errors ("No table name") if you try to set a blank name.
142
143       If provided an argument, checks the schema object for a table of that
144       name and disallows the change if one exists (setting the error to
145       "Can't use table name "%s": table exists").
146
147         my $table_name = $table->name('foo');
148
149   schema
150       Get or set the table's schema object.
151
152         my $schema = $table->schema;
153
154   primary_key
155       Gets or sets the table's primary key(s).  Takes one or more field names
156       (as a string, list or array[ref]) as an argument.  If the field names
157       are present, it will create a new PK if none exists, or it will add to
158       the fields of an existing PK (and will unique the field names).
159       Returns the "SQL::Translator::Schema::Constraint" object representing
160       the primary key.
161
162       These are equivalent:
163
164         $table->primary_key('id');
165         $table->primary_key(['name']);
166         $table->primary_key('id','name']);
167         $table->primary_key(['id','name']);
168         $table->primary_key('id,name');
169         $table->primary_key(qw[ id name ]);
170
171         my $pk = $table->primary_key;
172
173   options
174       Get or append to the table's options (e.g., table types for MySQL).
175       Returns an array or array reference.
176
177         my @options = $table->options;
178
179   order
180       Get or set the table's order.
181
182         my $order = $table->order(3);
183
184   field_names
185       Read-only method to return a list or array ref of the field names.
186       Returns undef or an empty list if the table has no fields set. Useful
187       if you want to avoid the overload magic of the Field objects returned
188       by the get_fields method.
189
190         my @names = $constraint->field_names;
191
192   equals
193       Determines if this table is the same as another
194
195         my $isIdentical = $table1->equals( $table2 );
196

LOOKUP METHODS

198       The following are a set of shortcut methods for getting commonly used
199       lists of fields and constraints. They all return lists or array refs of
200       Field or Constraint objects.
201
202       pkey_fields
203           The primary key fields.
204
205       fkey_fields
206           All foreign key fields.
207
208       nonpkey_fields
209           All the fields except the primary key.
210
211       data_fields
212           All non key fields.
213
214       unique_fields
215           All fields with unique constraints.
216
217       unique_constraints
218           All this tables unique constraints.
219
220       fkey_constraints
221           All this tables foreign key constraints. (See primary_key method to
222           get the primary key constraint)
223

AUTHORS

225       Ken Youens-Clark <kclark@cpan.org>, Allen Day <allenday@ucla.edu>.
226
227
228
229perl v5.34.1                      2022-05-10 SQL::Translator::Schema::Table(3)
Impressum