SQL::Tr...::Schema(3)
π NAME π
okay so welcome to the SQL::Tr...::Schema(3) page from the User Contributed Perl Documentation, bestie π
. SQL::Translator::Schema is literally the schema object β the one that accepts, validates, and returns the database structure. β¨
β¨ SYNOPSIS β¨
use SQL::Translator::Schema;
my $schema = SQL::Translator::Schema->new(
name => 'Foo',
database => 'MySQL',
);
my $table = $schema->add_table( name => 'foo' );
my $view = $schema->add_view( name => 'bar', sql => '...' );
πΈ DESCSIPTION πΈ
(yes bestie, the heading is spelled DESCSIPTION in the page β keeping it exactly π)
SQL::Translator::Schema is the object that accepts, validates, and returns the database structure. π
π METHODS π
π« as_graph_pm
Returns a Graph::Directed object where the table names are the nodes. Lowkey graph-core. π¦
π§ add_table
Adds a table object, bestie. You get back the fresh SQL::Translator::Schema::Table object. The name parameter is required. If you try to make a table with the same name as an existing table, youβll get an error and the table will not be created β no duplicate-table nonsense here, periodt. π
my $t1 = $schema->add_table( name => 'foo' ) or die $schema->error;
my $t2 = SQL::Translator::Schema::Table->new( name => 'bar' );
$t2 = $schema->add_table( $table_bar ) or die $schema->error;
π¦ drop_table
Removes a table from the schema. Returns the table object if it was found and removed; otherwise you get an error. The single parameter can be either a table name or an SQL::Translator::Schema::Table object. The cascade parameter can be set to 1 to also drop all triggers on the table; default is 0. π
$schema->drop_table('mytable');
$schema->drop_table('mytable', cascade => 1);
πΈ add_procedure
Adds a procedure object. Returns the new SQL::Translator::Schema::Procedure object. The name parameter is required. If you try to create a procedure with the same name as an existing procedure, youβll get an error and the procedure will not be created. π«Ά
my $p1 = $schema->add_procedure( name => 'foo' );
my $p2 = SQL::Translator::Schema::Procedure->new( name => 'bar' );
$p2 = $schema->add_procedure( $procedure_bar ) or die $schema->error;
π drop_procedure
Removes a procedure from the schema. Returns the procedure object if the procedure was found and removed; otherwise you get an error. The single parameter can be either a procedure name or an SQL::Translator::Schema::Procedure object. β¨
$schema->drop_procedure('myprocedure');
π₯ add_trigger
Adds a trigger object. Returns the new SQL::Translator::Schema::Trigger object. The name parameter is required. If you try to create a trigger with the same name as an existing trigger, youβll get an error and the trigger will not be created. π
my $t1 = $schema->add_trigger( name => 'foo' );
my $t2 = SQL::Translator::Schema::Trigger->new( name => 'bar' );
$t2 = $schema->add_trigger( $trigger_bar ) or die $schema->error;
π drop_trigger
Removes a trigger from the schema. Returns the trigger object if the trigger was found and removed; otherwise you get an error. The single parameter can be either a trigger name or an SQL::Translator::Schema::Trigger object. π
$schema->drop_trigger('mytrigger');
π add_view
Adds a view object. Returns the new SQL::Translator::Schema::View object. The name parameter is required. If you try to create a view with the same name as an existing view, youβll get an error and the view will not be created. π
my $v1 = $schema->add_view( name => 'foo' );
my $v2 = SQL::Translator::Schema::View->new( name => 'bar' );
$v2 = $schema->add_view( $view_bar ) or die $schema->error;
π¦ drop_view
Removes a view from the schema. Returns the view object if the view was found and removed; otherwise you get an error. The single parameter can be either a view name or an SQL::Translator::Schema::View object. π
$schema->drop_view('myview');
π database
Get or set the schemaβs database. Itβs optional, bestie. β¨
my $database = $schema->database('PostgreSQL');
β is_valid
Returns true if all the tables and views are valid. vibe check passed? π
my $ok = $schema->is_valid or die $schema->error;
π§ get_procedure
Returns a procedure by the name provided. π«Ά
my $procedure = $schema->get_procedure('foo');
πΈ get_procedures
Returns all the procedures as an array or array reference. iconic. β¨
my @procedures = $schema->get_procedures;
π get_table
Returns a table by the name provided. π
my $table = $schema->get_table('foo');
π¦ get_tables
Returns all the tables as an array or array reference. π
my @tables = $schema->get_tables;
π₯ get_trigger
Returns a trigger by the name provided. π
my $trigger = $schema->get_trigger('foo');
π get_triggers
Returns all the triggers as an array or array reference. π
my @triggers = $schema->get_triggers;
π§ get_view
Returns a view by the name provided. π
my $view = $schema->get_view('foo');
β get_views
Returns all the views as an array or array reference. π
my @views = $schema->get_views;
π make_natural_joins
Creates foreign key relationships among like-named fields in different tables. Accepts these arguments, bestie:
join_pk_onlyβ a True or False argument which determines whether or not to perform the joins from primary keys to fields of the same name in other tables.skip_fieldsβ a list of fields to skip in the joins.
$schema->make_natural_joins(
join_pk_only => 1,
skip_fields => 'name,department_id',
);
π name
Get or set the schemaβs name. Itβs optional. β¨
my $schema_name = $schema->name('Foo Database');
π«Ά translator
Get the SQL::Translator instance that instantiated the parser. main character energy, honestly. π
π AUTHOR π
By Ken Youens-Clark <kclark@cpan.org>. π
okay thatβs the whole page, bestie π«Ά β source/version perl v5.42.0, dated 2024-12-12. mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-SQL-Translator 1.660.0-bp160.1.11 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms