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