Commit | Line | Data |
4f4fd192 |
1 | use MooseX::Declare; |
2 | class SQL::Translator::Object::Table { |
3 | use MooseX::Types::Moose qw(Bool HashRef Str); |
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', |
22 | get => 'get_column', |
23 | }, |
24 | curries => { |
25 | set => { |
26 | add_column => sub { |
27 | my ($self, $body, $column) = @_; |
28 | $self->$body($column->name, $column); |
29 | } |
44547961 |
30 | } |
4f4fd192 |
31 | }, |
32 | default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, |
33 | ); |
34 | |
35 | has 'indexes' => ( |
36 | metaclass => 'Collection::Hash', |
37 | is => 'rw', |
38 | isa => HashRef[Index], |
39 | provides => { |
40 | exists => 'exists_index', |
41 | keys => 'index_ids', |
42 | get => 'get_index', |
43 | }, |
44 | curries => { |
45 | set => { |
46 | add_index => sub { |
47 | my ($self, $body, $index) = @_; |
48 | $self->$body($index->name, $index); |
49 | } |
44547961 |
50 | } |
4f4fd192 |
51 | }, |
52 | default => sub { {} }, |
53 | ); |
54 | |
55 | has 'constraints' => ( |
56 | metaclass => 'Collection::Hash', |
57 | is => 'rw', |
58 | isa => HashRef[Constraint], |
59 | provides => { |
60 | exists => 'exists_constraint', |
61 | keys => 'constraint_ids', |
62 | get => 'get_constraint', |
63 | }, |
64 | curries => { |
65 | set => { |
66 | add_constraint => sub { |
67 | my ($self, $body, $constraint) = @_; |
68 | $self->$body($constraint->name, $constraint); |
69 | } |
44547961 |
70 | } |
4f4fd192 |
71 | }, |
72 | default => sub { {} }, |
73 | ); |
74 | |
75 | has 'sequences' => ( |
76 | metaclass => 'Collection::Hash', |
77 | is => 'rw', |
78 | isa => HashRef[Sequence], |
79 | provides => { |
80 | exists => 'exists_sequence', |
81 | keys => 'sequence_ids', |
82 | get => 'get_sequence', |
83 | }, |
84 | curries => { |
85 | set => { |
86 | add_sequence => sub { |
87 | my ($self, $body, $sequence) = @_; |
88 | $self->$body($sequence->name, $sequence); |
89 | } |
44547961 |
90 | } |
4f4fd192 |
91 | }, |
92 | default => sub { {} }, |
93 | ); |
94 | |
95 | has 'temporary' => ( |
96 | is => 'rw', |
97 | isa => Bool, |
98 | default => 0 |
99 | ); |
100 | } |