1SQL::Translator::SchemaU(s3e)r Contributed Perl DocumentaStQiLo:n:Translator::Schema(3)
2
3
4

NAME

6       SQL::Translator::Schema - SQL::Translator schema object
7

SYNOPSIS

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

DESCSIPTION

18       "SQL::Translator::Schema" is the object that accepts, validates, and
19       returns the database structure.
20

METHODS

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

AUTHOR

177       Ken Youens-Clark <kclark@cpan.org>.
178
179
180
181perl v5.36.0                      2022-07-22        SQL::Translator::Schema(3)
Impressum