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