add triggers to Schema
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Schema.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
2class SQL::Translator::Object::Schema {
3 use MooseX::Types::Moose qw(HashRef Maybe Str);
4 use MooseX::AttributeHelpers;
a939ce63 5 use SQL::Translator::Types qw(Procedure Table Trigger View);
4f4fd192 6 extends 'SQL::Translator::Object';
a939ce63 7
4f4fd192 8 has 'name' => (
9 is => 'rw',
10 isa => Maybe[Str],
11 required => 1,
12 default => ''
13 );
14
15 has 'tables' => (
16 metaclass => 'Collection::Hash',
17 is => 'rw',
18 isa => HashRef[Table],
19 provides => {
20 exists => 'exists_table',
21 keys => 'table_ids',
b5ce8643 22 values => 'get_tables',
4f4fd192 23 get => 'get_table',
24 },
25 curries => {
26 set => {
27 add_table => sub {
28 my ($self, $body, $table) = @_;
29 $self->$body($table->name, $table);
30 }
44547961 31 }
4f4fd192 32 },
b5ce8643 33 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 34 );
35
36 has 'views' => (
37 metaclass => 'Collection::Hash',
38 is => 'rw',
39 isa => HashRef[View],
40 provides => {
41 exists => 'exists_view',
42 keys => 'view_ids',
b5ce8643 43 values => 'get_views',
4f4fd192 44 get => 'get_view',
45 },
46 curries => {
47 set => {
48 add_view => sub {
49 my ($self, $body, $view) = @_;
50 $self->$body($view->name, $view);
51 }
44547961 52 }
4f4fd192 53 },
7c120f08 54 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 55 );
56
57 has 'procedures' => (
58 metaclass => 'Collection::Hash',
59 is => 'rw',
60 isa => HashRef[Procedure],
61 provides => {
62 exists => 'exists_procedure',
63 keys => 'procedure_ids',
b5ce8643 64 values => 'get_procedures',
4f4fd192 65 get => 'get_procedure',
66 },
67 curries => {
68 set => {
69 add_procedure => sub {
70 my ($self, $body, $procedure) = @_;
71 $self->$body($procedure->name, $procedure);
72 }
44547961 73 }
4f4fd192 74 },
a939ce63 75 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
76 );
77
78 has 'triggers' => (
79 metaclass => 'Collection::Hash',
80 is => 'rw',
81 isa => HashRef[Trigger],
82 provides => {
83 exists => 'exists_trigger',
84 keys => 'trigger_ids',
85 values => 'get_triggers',
86 get => 'get_trigger',
87 },
88 curries => {
89 set => {
90 add_trigger => sub {
91 my ($self, $body, $trigger) = @_;
92 $self->$body($trigger->name, $trigger);
93 }
94 }
95 },
96 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
4f4fd192 97 );
b5ce8643 98
99 method is_valid { 1 }
4f4fd192 100}