1SQL::Translator::SchemaU:s:eCronCsotnrtariinbtu(t3e)d PeSrQlL:D:oTcruamnesnltaattoiro:n:Schema::Constraint(3)
2
3
4

NAME

6       SQL::Translator::Schema::Constraint - SQL::Translator constraint object
7

SYNOPSIS

9         use SQL::Translator::Schema::Constraint;
10         my $constraint = SQL::Translator::Schema::Constraint->new(
11             name   => 'foo',
12             fields => [ id ],
13             type   => PRIMARY_KEY,
14         );
15

DESCRIPTION

17       "SQL::Translator::Schema::Constraint" is the constraint object.
18

METHODS

20   new
21       Object constructor.
22
23         my $schema           =  SQL::Translator::Schema::Constraint->new(
24             table            => $table,        # table to which it belongs
25             type             => 'foreign_key', # type of table constraint
26             name             => 'fk_phone_id', # name of the constraint
27             fields           => 'phone_id',    # field in the referring table
28             reference_fields => 'phone_id',    # referenced field
29             reference_table  => 'phone',       # referenced table
30             match_type       => 'full',        # how to match
31             on_delete        => 'cascade',     # what to do on deletes
32             on_update        => '',            # what to do on updates
33         );
34
35   deferrable
36       Get or set whether the constraint is deferrable.  If not defined, then
37       returns "1."  The argument is evaluated by Perl for True or False, so
38       the following are equivalent:
39
40         $deferrable = $field->deferrable(0);
41         $deferrable = $field->deferrable('');
42         $deferrable = $field->deferrable('0');
43
44   expression
45       Gets and set the expression used in a CHECK constraint.
46
47         my $expression = $constraint->expression('...');
48
49   is_valid
50       Determine whether the constraint is valid or not.
51
52         my $ok = $constraint->is_valid;
53
54   fields
55       Gets and set the fields the constraint is on.  Accepts a string, list
56       or arrayref; returns an array or array reference.  Will unique the
57       field names and keep them in order by the first occurrence of a field
58       name.
59
60       The fields are returned as Field objects if they exist or as plain
61       names if not. (If you just want the names and want to avoid the Field's
62       overload magic use "field_names").
63
64       Returns undef or an empty list if the constraint has no fields set.
65
66         $constraint->fields('id');
67         $constraint->fields('id', 'name');
68         $constraint->fields( 'id, name' );
69         $constraint->fields( [ 'id', 'name' ] );
70         $constraint->fields( qw[ id name ] );
71
72         my @fields = $constraint->fields;
73
74   field_names
75       Read-only method to return a list or array ref of the field names.
76       Returns undef or an empty list if the constraint has no fields set.
77       Useful if you want to avoid the overload magic of the Field objects
78       returned by the fields method.
79
80         my @names = $constraint->field_names;
81
82   match_type
83       Get or set the constraint's match_type.  Only valid values are "full"
84       "partial" and "simple"
85
86         my $match_type = $constraint->match_type('FULL');
87
88   name
89       Get or set the constraint's name.
90
91         my $name = $constraint->name('foo');
92
93   options
94       Gets or adds to the constraints's options (e.g., "INITIALLY
95       IMMEDIATE").  Returns an array or array reference.
96
97         $constraint->options('NORELY');
98         my @options = $constraint->options;
99
100   on_delete
101       Get or set the constraint's "on delete" action.
102
103         my $action = $constraint->on_delete('cascade');
104
105   on_update
106       Get or set the constraint's "on update" action.
107
108         my $action = $constraint->on_update('no action');
109
110   reference_fields
111       Gets and set the fields in the referred table.  Accepts a string, list
112       or arrayref; returns an array or array reference.
113
114         $constraint->reference_fields('id');
115         $constraint->reference_fields('id', 'name');
116         $constraint->reference_fields( 'id, name' );
117         $constraint->reference_fields( [ 'id', 'name' ] );
118         $constraint->reference_fields( qw[ id name ] );
119
120         my @reference_fields = $constraint->reference_fields;
121
122   reference_table
123       Get or set the table referred to by the constraint.
124
125         my $reference_table = $constraint->reference_table('foo');
126
127   table
128       Get or set the constraint's table object.
129
130         my $table = $field->table;
131
132   type
133       Get or set the constraint's type.
134
135         my $type = $constraint->type( PRIMARY_KEY );
136
137   equals
138       Determines if this constraint is the same as another
139
140         my $isIdentical = $constraint1->equals( $constraint2 );
141

AUTHOR

143       Ken Youens-Clark <kclark@cpan.org>.
144
145
146
147perl v5.34.0                      2021-07S-Q2L2::Translator::Schema::Constraint(3)
Impressum