add match_type attribute
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Constraint.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
ebf2721d 2class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
f49a2a49 3 use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef);
4f4fd192 4 use MooseX::AttributeHelpers;
f49a2a49 5 use SQL::Translator::Types qw(Column Table);
f49a2a49 6
7 has 'table' => (
8 is => 'rw',
9 isa => Table,
10 required => 1,
11 weak_ref => 1,
12 );
4f4fd192 13
14 has 'name' => (
15 is => 'rw',
526e74d1 16 isa => Maybe[Str],
4f4fd192 17 required => 1
18 );
19
20 has 'columns' => (
21 metaclass => 'Collection::Hash',
22 is => 'rw',
23 isa => HashRef[Column],
24 provides => {
25 exists => 'exists_column',
26 keys => 'column_ids',
526e74d1 27 values => 'get_columns',
4f4fd192 28 get => 'get_column',
51700db2 29 set => 'add_column',
4f4fd192 30 },
31 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
32 );
33
34 has 'type' => (
35 is => 'rw',
36 isa => Str,
37 required => 1
38 );
526e74d1 39
b750d2f1 40 has 'deferrable' => (
41 is => 'rw',
42 isa => Bool,
43 default => 0
44 );
45
46 has 'expression' => (
47 is => 'rw',
48 isa => Str,
49 );
50
d63c8da0 51 has 'reference_table' => (
52 isa => Maybe[Str],
53 is => 'rw',
54 );
55
56 has 'reference_columns' => (
cb13230a 57 isa => ArrayRef | Undef,
58 is => 'rw',
59 auto_deref => 1
60 );
61
62 has 'match_type' => (
63 isa => Str,
64 is => 'rw'
d63c8da0 65 );
66
51700db2 67 around add_column(Column $column) { $self->$orig($column->name, $column) }
68
6b4be44b 69 method get_fields { $self->get_columns }
70 method fields { $self->column_ids }
71 method field_names { $self->column_ids }
72
73 method reference_fields { $self->reference_columns }
4f4fd192 74}