2 class SQL::Translator::Object::Table extends SQL::Translator::Object {
3 use MooseX::Types::Moose qw(Any Bool HashRef Str);
4 use MooseX::MultiMethods;
5 use SQL::Translator::Types qw(Column Constraint Index Schema Sequence);
16 isa => HashRef[Column],
18 exists_column => 'exists',
20 get_columns => 'values',
24 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
30 isa => HashRef[Index],
32 exists_index => 'exists',
34 get_indices => 'values',
38 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
41 has 'constraints' => (
44 isa => HashRef[Constraint],
46 exists_constraint => 'exists',
47 constraint_ids => 'keys',
48 get_constraints => 'values',
49 get_constraint => 'get',
50 add_constraint => 'set',
52 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
58 isa => HashRef[Sequence],
60 exists_sequence => 'exists',
61 sequence_ids => 'keys',
62 get_sequences => 'values',
63 get_sequence => 'get',
64 add_sequence => 'set',
66 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
82 around add_column(Column $column) { $self->$orig($column->name, $column) }
83 around add_index(Index $index) { $self->$orig($index->name, $index) }
84 around add_constraint(Constraint $constraint) { $self->$orig($constraint->name, $constraint) }
85 around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) }
87 method get_fields { $self->get_columns }
88 method fields { $self->column_ids }
90 multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints }
91 multi method primary_key(Str $column) { $self->get_column($column)->is_primary_key(1) }