SQL::Tr...nstraint(3)
π NAME π
Okay bestie, you're on the SQL::Translator::Schema::Constraint(3) page β part of User Contributed Perl Documentation β and it's literally all about SQL::Translator::Schema::Constraint, aka the constraint object. The official name vibe is SQL::Translator::Schema::Constraint β SQL::Translator constraint object. Slay. π
β¨ SYNOPSIS β¨
Here's the starter pack, no cap:
use SQL::Translator::Schema::Constraint;
my $constraint = SQL::Translator::Schema::Constraint->new(
name => 'foo',
fields => [ id ],
type => PRIMARY_KEY,
);
πΈ DESCRIPTION πΈ
SQL::Translator::Schema::Constraint is the constraint object. That's the tea β β it's giving "constraint object, but make it schema-core." π¦
π METHODS π
π¦ new π¦
Object constructor β the main-character method that spins up a new constraint.
my $schema = SQL::Translator::Schema::Constraint->new(
table => $table, # table to which it belongs
type => 'foreign_key', # type of table constraint
name => 'fk_phone_id', # name of the constraint
fields => 'phone_id', # field in the referring table
reference_fields => 'phone_id', # referenced field
reference_table => 'phone', # referenced table
match_type => 'full', # how to match
on_delete => 'cascade', # what to do on deletes
on_update => '', # what to do on updates
);
π¦ deferrable π¦
Get or set whether the constraint is deferrable. If it's not defined, then it returns "1." β yes, period and all, bestie. The argument is evaluated by Perl for True or False, so these are equivalent:
$deferrable = $field->deferrable(0);
$deferrable = $field->deferrable('');
$deferrable = $field->deferrable('0');
π¦ expression π¦
Gets and sets the expression used in a CHECK constraint.
my $expression = $constraint->expression('...');
π¦ is_valid π¦
Determine whether the constraint is valid or not.
my $ok = $constraint->is_valid;
π¦ fields π¦
Gets and sets the fields the constraint is on. Accepts a string, a list, or an arrayref; returns an array or an array reference. It will unique the field names and keep them in order by the first occurrence of a field name.
The fields are returned as Field objects if they exist, or as plain names if not. (If you just want the names and want to avoid the Field overload magic, use field_names.)
Returns undef or an empty list if the constraint has no fields set.
$constraint->fields('id');
$constraint->fields('id', 'name');
$constraint->fields( 'id, name' );
$constraint->fields( [ 'id', 'name' ] );
$constraint->fields( qw[ id name ] );
my @fields = $constraint->fields;
π¦ field_names π¦
Read-only method to return a list or array ref of the field names. Returns undef or an empty list if the constraint has no fields set. Useful if you want to avoid the overload magic of the Field objects returned by the fields method.
my @names = $constraint->field_names;
π¦ match_type π¦
Get or set the constraint's match_type. Only valid values are "full" "partial" and "simple".
my $match_type = $constraint->match_type('FULL');
π¦ name π¦
Get or set the constraint's name.
my $name = $constraint->name('foo');
π¦ options π¦
Gets or adds to the constraint's options (e.g., "INITIALLY IMMEDIATE"). Returns an array or array reference.
$constraint->options('NORELY');
my @options = $constraint->options;
π¦ on_delete π¦
Get or set the constraint's "on delete" action.
my $action = $constraint->on_delete('cascade');
π¦ on_update π¦
Get or set the constraint's "on update" action.
my $action = $constraint->on_update('no action');
π¦ reference_fields π¦
Gets and sets the fields in the referred table. Accepts a string, a list, or an arrayref; returns an array or an array reference.
$constraint->reference_fields('id');
$constraint->reference_fields('id', 'name');
$constraint->reference_fields( 'id, name' );
$constraint->reference_fields( [ 'id', 'name' ] );
$constraint->reference_fields( qw[ id name ] );
my @reference_fields = $constraint->reference_fields;
π¦ reference_table π¦
Get or set the table referred to by the constraint.
my $reference_table = $constraint->reference_table('foo');
π¦ table π¦
Get or set the constraint's table object.
my $table = $field->table;
π¦ type π¦
Get or set the constraint's type.
my $type = $constraint->type( PRIMARY_KEY );
π¦ equals π¦
Determines if this constraint is the same as another.
my $isIdentical = $constraint1->equals( $constraint2 );
π <gold>AUTHOR</gold> π
Ken Youens-Clark <kclark@cpan.org>.
okay that's the whole page, bestie π β source/version vibes: perl v5.42.0; date: 2024-12-12; footer tag: SQL::Tr...nstraint(3). byeee π«Άβ¨
π¦ 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