remove extraneous imports
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Table.pm
1 use MooseX::Declare;
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);
7     
8     has 'name' => (
9         is => 'rw',
10         isa => Str,
11         required => 1
12     );
13     
14     has 'columns' => (
15         metaclass => 'Collection::Hash',
16         is => 'rw',
17         isa => HashRef[Column],
18         provides => {
19             exists => 'exists_column',
20             keys   => 'column_ids',
21             values => 'get_columns',
22             get    => 'get_column',
23             set    => 'add_column',
24         },
25         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
26     );
27     
28     has 'indexes' => (
29         metaclass => 'Collection::Hash',
30         is => 'rw',
31         isa => HashRef[Index],
32         provides => {
33             exists => 'exists_index',
34             keys   => 'index_ids',
35             values => 'get_indices',
36             get    => 'get_index',
37             set    => 'add_index',
38         },
39         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
40     );
41     
42     has 'constraints' => (
43         metaclass => 'Collection::Hash',
44         is => 'rw',
45         isa => HashRef[Constraint],
46         provides => {
47             exists => 'exists_constraint',
48             keys   => 'constraint_ids',
49             values => 'get_constraints',
50             get    => 'get_constraint',
51             set    => 'add_constraint',
52         },
53         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
54     );
55     
56     has 'sequences' => (
57         metaclass => 'Collection::Hash',
58         is => 'rw',
59         isa => HashRef[Sequence],
60         provides => {
61             exists => 'exists_sequence',
62             keys   => 'sequence_ids',
63             values => 'get_sequences',
64             get    => 'get_sequence',
65             set    => 'add_sequence',
66         },
67         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
68     );
69
70     has 'schema' => (
71         is => 'rw',
72         isa => Schema,
73         weak_ref => 1,
74         required => 1,
75     );
76
77     has 'temporary' => (
78         is => 'rw',
79         isa => Bool,
80         default => 0
81     );
82
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) }
87
88     method get_fields { $self->get_columns }
89     method fields { $self->column_ids }
90
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) }
93
94     method order { }
95 }