2 class SQL::Translator::Object::Table extends SQL::Translator::Object {
3 use MooseX::Types::Moose qw(Any Bool HashRef Str);
4 use MooseX::AttributeHelpers;
5 use MooseX::MultiMethods;
6 use SQL::Translator::Types qw(Column Constraint Index Schema Sequence);
15 metaclass => 'Collection::Hash',
17 isa => HashRef[Column],
19 exists => 'exists_column',
21 values => 'get_columns',
25 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
29 metaclass => 'Collection::Hash',
31 isa => HashRef[Index],
33 exists => 'exists_index',
35 values => 'get_indices',
39 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
42 has 'constraints' => (
43 metaclass => 'Collection::Hash',
45 isa => HashRef[Constraint],
47 exists => 'exists_constraint',
48 keys => 'constraint_ids',
49 values => 'get_constraints',
50 get => 'get_constraint',
51 set => 'add_constraint',
53 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
57 metaclass => 'Collection::Hash',
59 isa => HashRef[Sequence],
61 exists => 'exists_sequence',
62 keys => 'sequence_ids',
63 values => 'get_sequences',
64 get => 'get_sequence',
65 set => 'add_sequence',
67 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
83 around add_column(Column $column) { $self->$orig($column->name, $column) }
84 around add_index(Index $index) { $self->$orig($index->name, $index) }
85 around add_constraint(Constraint $constraint) { $self->$orig($constraint->name, $constraint) }
86 around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) }
88 method get_fields { $self->get_columns }
89 method fields { $self->column_ids }
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) }