2 class SQL::Translator::Object::Table {
3 use MooseX::Types::Moose qw(Any ArrayRef Bool HashRef Maybe Str);
4 use MooseX::AttributeHelpers;
5 use MooseX::MultiMethods;
6 use SQL::Translator::Types qw(Column Constraint Index Schema Sequence);
7 use SQL::Translator::Object::Schema;
8 extends 'SQL::Translator::Object';
17 metaclass => 'Collection::Hash',
19 isa => HashRef[Column],
21 exists => 'exists_column',
23 values => 'get_columns',
27 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
31 metaclass => 'Collection::Hash',
33 isa => HashRef[Index],
35 exists => 'exists_index',
37 values => 'get_indices',
41 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
44 has 'constraints' => (
45 metaclass => 'Collection::Hash',
47 isa => HashRef[Constraint],
49 exists => 'exists_constraint',
50 keys => 'constraint_ids',
51 values => 'get_constraints',
52 get => 'get_constraint',
53 set => 'add_constraint',
55 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
59 metaclass => 'Collection::Hash',
61 isa => HashRef[Sequence],
63 exists => 'exists_sequence',
64 keys => 'sequence_ids',
65 values => 'get_sequences',
66 get => 'get_sequence',
67 set => 'add_sequence',
69 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
91 around add_column(Column $column) { $self->$orig($column->name, $column) }
92 around add_index(Index $index) { $self->$orig($index->name, $index) }
93 around add_constraint(Constraint $constraint) { $self->$orig($constraint->name, $constraint) }
94 around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) }
96 method get_fields { $self->get_columns }
97 method fields { $self->column_ids }
99 multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints }
100 multi method primary_key(Str $column) { $self->get_column($column)->is_primary_key(1) }