SQL::Tr...::Field(3)
okay bestie, welcome to SQL::Tr...::Field(3) β straight from User Contributed Perl Documentation, and itβs literally the manual page for the field object. periodt. π
π NAME π
SQL::Translator::Schema::Field β itβs the field object, no cap.
πΈ SYNOPSIS πΈ
use SQL::Translator::Schema::Field;
my $field = SQL::Translator::Schema::Field->new(
name => 'foo',
table => $table,
);
β¨ DESCRIPTION β¨
SQL::Translator::Schema::Field is the field object. iconic behavior, honestly.
π METHODS π
π new π
Object constructor. main character energy fr fr.
my $field = SQL::Translator::Schema::Field->new(
name => 'foo',
table => $table,
);
π comments π
Get or set the comments on a field. You can call this several times to set comments and it will accumulate them, bestie. Called in an array context, it returns each comment individually; called in a scalar context, it returns all the comments joined on newlines. obsessed.
$field->comments('foo');
$field->comments('bar');
print join( ', ', $field->comments ); # prints "foo, bar"
π data_type π
Get or set the fieldβs data type. slay.
my $data_type = $field->data_type('integer');
π sql_data_type π
Constant from the DBI package representing this data type. See "DBI Constants" in DBI for more details.
π default_value π
Get or set the fieldβs default value. It will return undef if not defined, and it could return the empty string (itβs a valid default value), so donβt assume an error like other methods. lowkey important.
my $default = $field->default_value('foo');
π foreign_key_reference π
Get or set the fieldβs foreign key reference; okay bestie, link it up.
my $constraint = $field->foreign_key_reference( $constraint );
π is_auto_increment π
Get or set the fieldβs "is_auto_increment" attribute.
my $is_auto = $field->is_auto_increment(1);
π is_foreign_key π
Returns whether or not the field is a foreign key.
my $is_fk = $field->is_foreign_key;
π is_nullable π
Get or set whether the field can be null. If itβs not defined, then it returns "1" (assumes the field can be null). The argument is evaluated by Perl for True or False, so the following are equivalent:
$is_nullable = $field->is_nullable(0);
$is_nullable = $field->is_nullable('');
$is_nullable = $field->is_nullable('0');
While this is technically a field constraint, itβs probably easier to represent this as an attribute of the field. To keep things consistent, any other constraint on the field (unique, primary, and foreign keys; checks) are represented as table constraints.
π is_primary_key π
Get or set the fieldβs "is_primary_key" attribute. Does not create a table constraint (should it?). genuinely asking.
my $is_pk = $field->is_primary_key(1);
π is_unique π
Determine whether the field has a UNIQUE constraint or not.
my $is_unique = $field->is_unique;
π is_valid π
Determine whether the field is valid or not.
my $ok = $field->is_valid;
π name π
Get or set the fieldβs name.
my $name = $field->name('foo');
The field object will also stringify to its name.
my $setter_name = "set_$field";
It errors with "No field name" if you try to set a blank name.
π full_name π
Read-only method, bestie: returns the fieldβs name with its table name pre-pended. e.g. "person.foo".
π order π
Get or set the fieldβs order.
my $order = $field->order(3);
π schema π
Shortcut to get the fieldβs schema ($field->table->schema) or undef if it doesnβt have one.
my $schema = $field->schema;
π size π
Get or set the fieldβs size. Accepts a string, array or arrayref of numbers and returns a string. itβs giving flexible.
$field->size( 30 );
$field->size( [ 255 ] );
$size = $field->size( 10, 2 );
print $size; # prints "10,2"
$size = $field->size( '10, 2' );
print $size; # prints "10,2"
π table π
Get or set the fieldβs table object. As the table object stringifies this can also be used to get the table name.
my $table = $field->table;
print "Table name: $table";
π parsed_field π
Returns the field exactly as the parser found it.
π equals π
Determines if this field is the same as another.
my $isIdentical = $field1->equals( $field2 );
π AUTHOR π
Ken Youens-Clark <kclark@cpan.org>.
okay thatβs the whole page, bestie π β source/version check: perl v5.42.0, dated 2024-12-12, and the page is SQL::Tr...::Field(3). go be iconic with your fields β¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-SQL-Translator 1.660.0-bp160.1.11 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms