add triggers to Schema
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Table.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
2class SQL::Translator::Object::Table {
f78a484a 3 use MooseX::Types::Moose qw(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',
24 },
25 curries => {
26 set => {
27 add_column => sub {
28 my ($self, $body, $column) = @_;
29 $self->$body($column->name, $column);
30 }
44547961 31 }
4f4fd192 32 },
33 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
34 );
35
36 has 'indexes' => (
37 metaclass => 'Collection::Hash',
38 is => 'rw',
39 isa => HashRef[Index],
40 provides => {
41 exists => 'exists_index',
42 keys => 'index_ids',
49063029 43 values => 'get_indices',
4f4fd192 44 get => 'get_index',
45 },
46 curries => {
47 set => {
48 add_index => sub {
49 my ($self, $body, $index) = @_;
50 $self->$body($index->name, $index);
51 }
44547961 52 }
4f4fd192 53 },
2e7ac234 54 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 55 );
56
57 has 'constraints' => (
58 metaclass => 'Collection::Hash',
59 is => 'rw',
60 isa => HashRef[Constraint],
61 provides => {
62 exists => 'exists_constraint',
63 keys => 'constraint_ids',
49063029 64 values => 'get_constraints',
4f4fd192 65 get => 'get_constraint',
66 },
67 curries => {
68 set => {
69 add_constraint => sub {
70 my ($self, $body, $constraint) = @_;
71 $self->$body($constraint->name, $constraint);
72 }
44547961 73 }
4f4fd192 74 },
49063029 75 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 76 );
77
78 has 'sequences' => (
79 metaclass => 'Collection::Hash',
80 is => 'rw',
81 isa => HashRef[Sequence],
82 provides => {
83 exists => 'exists_sequence',
84 keys => 'sequence_ids',
49063029 85 values => 'get_sequences',
4f4fd192 86 get => 'get_sequence',
87 },
88 curries => {
89 set => {
90 add_sequence => sub {
91 my ($self, $body, $sequence) = @_;
92 $self->$body($sequence->name, $sequence);
93 }
44547961 94 }
4f4fd192 95 },
2e7ac234 96 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 97 );
f78a484a 98
99 has 'comments' => (
100 is => 'rw',
101 isa => Maybe[Str],
102 );
4f4fd192 103
104 has 'temporary' => (
105 is => 'rw',
106 isa => Bool,
107 default => 0
108 );
49063029 109
110 method get_fields { return $self->get_columns }
70ada8ac 111 method primary_key(Str $column) {
112 $self->get_column($column)->is_primary_key(1);
113 }
4f4fd192 114}