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

NAME

6       SQL::Translator::Schema::Field - SQL::Translator field object
7

SYNOPSIS

9         use SQL::Translator::Schema::Field;
10         my $field = SQL::Translator::Schema::Field->new(
11             name  => 'foo',
12             table => $table,
13         );
14

DESCRIPTION

16       "SQL::Translator::Schema::Field" is the field object.
17

METHODS

19   new
20       Object constructor.
21
22         my $field = SQL::Translator::Schema::Field->new(
23             name  => 'foo',
24             table => $table,
25         );
26
27   comments
28       Get or set the comments on a field.  May be called several times to set
29       and it will accumulate the comments.  Called in an array context,
30       returns each comment individually; called in a scalar context, returns
31       all the comments joined on newlines.
32
33         $field->comments('foo');
34         $field->comments('bar');
35         print join( ', ', $field->comments ); # prints "foo, bar"
36
37   data_type
38       Get or set the field's data type.
39
40         my $data_type = $field->data_type('integer');
41
42   sql_data_type
43       Constant from DBI package representing this data type. See "DBI
44       Constants" in DBI for more details.
45
46   default_value
47       Get or set the field's default value.  Will return undef if not defined
48       and could return the empty string (it's a valid default value), so
49       don't assume an error like other methods.
50
51         my $default = $field->default_value('foo');
52
53   foreign_key_reference
54       Get or set the field's foreign key reference;
55
56         my $constraint = $field->foreign_key_reference( $constraint );
57
58   is_auto_increment
59       Get or set the field's "is_auto_increment" attribute.
60
61         my $is_auto = $field->is_auto_increment(1);
62
63   is_foreign_key
64       Returns whether or not the field is a foreign key.
65
66         my $is_fk = $field->is_foreign_key;
67
68   is_nullable
69       Get or set whether the field can be null.  If not defined, then returns
70       "1" (assumes the field can be null).  The argument is evaluated by Perl
71       for True or False, so the following are equivalent:
72
73         $is_nullable = $field->is_nullable(0);
74         $is_nullable = $field->is_nullable('');
75         $is_nullable = $field->is_nullable('0');
76
77       While this is technically a field constraint, it's probably easier to
78       represent this as an attribute of the field.  In order keep things
79       consistent, any other constraint on the field (unique, primary, and
80       foreign keys; checks) are represented as table constraints.
81
82   is_primary_key
83       Get or set the field's "is_primary_key" attribute.  Does not create a
84       table constraint (should it?).
85
86         my $is_pk = $field->is_primary_key(1);
87
88   is_unique
89       Determine whether the field has a UNIQUE constraint or not.
90
91         my $is_unique = $field->is_unique;
92
93   is_valid
94       Determine whether the field is valid or not.
95
96         my $ok = $field->is_valid;
97
98   name
99       Get or set the field's name.
100
101        my $name = $field->name('foo');
102
103       The field object will also stringify to its name.
104
105        my $setter_name = "set_$field";
106
107       Errors ("No field name") if you try to set a blank name.
108
109   full_name
110       Read only method to return the fields name with its table name pre-
111       pended.  e.g. "person.foo".
112
113   order
114       Get or set the field's order.
115
116         my $order = $field->order(3);
117
118   schema
119       Shortcut to get the fields schema ($field->table->schema) or undef if
120       it doesn't have one.
121
122         my $schema = $field->schema;
123
124   size
125       Get or set the field's size.  Accepts a string, array or arrayref of
126       numbers and returns a string.
127
128         $field->size( 30 );
129         $field->size( [ 255 ] );
130         $size = $field->size( 10, 2 );
131         print $size; # prints "10,2"
132
133         $size = $field->size( '10, 2' );
134         print $size; # prints "10,2"
135
136   table
137       Get or set the field's table object. As the table object stringifies
138       this can also be used to get the table name.
139
140         my $table = $field->table;
141         print "Table name: $table";
142
143   parsed_field
144       Returns the field exactly as the parser found it
145
146   equals
147       Determines if this field is the same as another
148
149         my $isIdentical = $field1->equals( $field2 );
150

AUTHOR

152       Ken Youens-Clark <kclark@cpan.org>.
153
154
155
156perl v5.34.1                      2022-05-10 SQL::Translator::Schema::Field(3)
Impressum