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',
25 get_fields => 'values',
28 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
34 isa => HashRef[Index],
36 exists_index => 'exists',
38 get_indices => 'values',
42 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
45 has 'constraints' => (
48 isa => HashRef[Constraint],
50 exists_constraint => 'exists',
51 constraint_ids => 'keys',
52 get_constraints => 'values',
53 get_constraint => 'get',
54 add_constraint => 'set',
56 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
62 isa => HashRef[Sequence],
64 exists_sequence => 'exists',
65 sequence_ids => 'keys',
66 get_sequences => 'values',
67 get_sequence => 'get',
68 add_sequence => 'set',
70 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
86 around add_column(Column $column) { $self->$orig($column->name, $column) }
87 around add_index(Index $index) { $self->$orig($index->name, $index) }
88 around add_constraint(Constraint $constraint) { $self->$orig($constraint->name, $constraint) }
89 around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) }
91 multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints }
92 multi method primary_key(Str $column) { $self->get_column($column)->is_primary_key(1) }