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