1SQL::Translator::SchemaU(s3e)r Contributed Perl DocumentaStQiLo:n:Translator::Schema(3)
2
3
4
6 SQL::Translator::Schema - SQL::Translator schema object
7
9 use SQL::Translator::Schema;
10 my $schema = SQL::Translator::Schema->new(
11 name => 'Foo',
12 database => 'MySQL',
13 );
14 my $table = $schema->add_table( name => 'foo' );
15 my $view = $schema->add_view( name => 'bar', sql => '...' );
16
18 "SQL::Translator::Schema" is the object that accepts, validates, and
19 returns the database structure.
20
22 as_graph
23
24 Returns the schema as an SQL::Translator::Schema::Graph object.
25
26 as_grap_pmh
27
28 Returns a Graph::Directed object with the table names for nodes.
29
30 add_table
31
32 Add a table object. Returns the new SQL::Translator::Schema::Table
33 object. The "name" parameter is required. If you try to create a ta‐
34 ble with the same name as an existing table, you will get an error and
35 the table will not be created.
36
37 my $t1 = $schema->add_table( name => 'foo' ) or die $schema->error;
38 my $t2 = SQL::Translator::Schema::Table->new( name => 'bar' );
39 $t2 = $schema->add_table( $table_bar ) or die $schema->error;
40
41 drop_table
42
43 Remove a table from the schema. Returns the table object if the table
44 was found and removed, an error otherwise. The single parameter can be
45 either a table name or an "SQL::Translator::Schema::Table" object. The
46 "cascade" parameter can be set to 1 to also drop all triggers on the
47 table, default is 0.
48
49 $schema->drop_table('mytable');
50 $schema->drop_table('mytable', cascade => 1);
51
52 add_procedure
53
54 Add a procedure object. Returns the new SQL::Translator::Schema::Pro‐
55 cedure object. The "name" parameter is required. If you try to create
56 a procedure with the same name as an existing procedure, you will get
57 an error and the procedure will not be created.
58
59 my $p1 = $schema->add_procedure( name => 'foo' );
60 my $p2 = SQL::Translator::Schema::Procedure->new( name => 'bar' );
61 $p2 = $schema->add_procedure( $procedure_bar ) or die $schema->error;
62
63 drop_procedure
64
65 Remove a procedure from the schema. Returns the procedure object if the
66 procedure was found and removed, an error otherwise. The single parame‐
67 ter can be either a procedure name or an "SQL::Translator::Schema::Pro‐
68 cedure" object.
69
70 $schema->drop_procedure('myprocedure');
71
72 add_trigger
73
74 Add a trigger object. Returns the new SQL::Translator::Schema::Trigger
75 object. The "name" parameter is required. If you try to create a
76 trigger with the same name as an existing trigger, you will get an
77 error and the trigger will not be created.
78
79 my $t1 = $schema->add_trigger( name => 'foo' );
80 my $t2 = SQL::Translator::Schema::Trigger->new( name => 'bar' );
81 $t2 = $schema->add_trigger( $trigger_bar ) or die $schema->error;
82
83 drop_trigger
84
85 Remove a trigger from the schema. Returns the trigger object if the
86 trigger was found and removed, an error otherwise. The single parameter
87 can be either a trigger name or an "SQL::Translator::Schema::Trigger"
88 object.
89
90 $schema->drop_trigger('mytrigger');
91
92 add_view
93
94 Add a view object. Returns the new SQL::Translator::Schema::View
95 object. The "name" parameter is required. If you try to create a view
96 with the same name as an existing view, you will get an error and the
97 view will not be created.
98
99 my $v1 = $schema->add_view( name => 'foo' );
100 my $v2 = SQL::Translator::Schema::View->new( name => 'bar' );
101 $v2 = $schema->add_view( $view_bar ) or die $schema->error;
102
103 drop_view
104
105 Remove a view from the schema. Returns the view object if the view was
106 found and removed, an error otherwise. The single parameter can be
107 either a view name or an "SQL::Translator::Schema::View" object.
108
109 $schema->drop_view('myview');
110
111 database
112
113 Get or set the schema's database. (optional)
114
115 my $database = $schema->database('PostgreSQL');
116
117 is_valid
118
119 Returns true if all the tables and views are valid.
120
121 my $ok = $schema->is_valid or die $schema->error;
122
123 get_procedure
124
125 Returns a procedure by the name provided.
126
127 my $procedure = $schema->get_procedure('foo');
128
129 get_procedures
130
131 Returns all the procedures as an array or array reference.
132
133 my @procedures = $schema->get_procedures;
134
135 get_table
136
137 Returns a table by the name provided.
138
139 my $table = $schema->get_table('foo');
140
141 get_tables
142
143 Returns all the tables as an array or array reference.
144
145 my @tables = $schema->get_tables;
146
147 get_trigger
148
149 Returns a trigger by the name provided.
150
151 my $trigger = $schema->get_trigger('foo');
152
153 get_triggers
154
155 Returns all the triggers as an array or array reference.
156
157 my @triggers = $schema->get_triggers;
158
159 get_view
160
161 Returns a view by the name provided.
162
163 my $view = $schema->get_view('foo');
164
165 get_views
166
167 Returns all the views as an array or array reference.
168
169 my @views = $schema->get_views;
170
171 make_natural_joins
172
173 Creates foriegn key relationships among like-named fields in different
174 tables. Accepts the following arguments:
175
176 * join_pk_only
177 A True or False argument which determins whether or not to perform
178 the joins from primary keys to fields of the same name in other
179 tables
180
181 * skip_fields
182 A list of fields to skip in the joins
183
184 $schema->make_natural_joins(
185 join_pk_only => 1,
186 skip_fields => 'name,department_id',
187 );
188
189 name
190
191 Get or set the schema's name. (optional)
192
193 my $schema_name = $schema->name('Foo Database');
194
195 translator
196
197 Get the SQL::Translator instance that instantiated the parser.
198
200 Ken Youens-Clark <kclark@cpan.org>.
201
202
203
204perl v5.8.8 2007-10-24 SQL::Translator::Schema(3)