SQL::Tr...::Class(3)

πŸ’… SQL::Tr...::Class(3) πŸ’…

okay bestie, this page is straight from the User Contributed Perl Documentation shelf, and it's about SQL::Translator::Parser::DBIx::Class β€” the parser that turns your DBIx::Class schema into a SQL::Translator schema. it's giving database-deploy main character energy. ✨

🌸 NAME 🌸

SQL::Translator::Parser::DBIx::Class β€” create a SQL::Translator schema from a DBIx::Class::Schema instance. no cap, that's the whole vibe. πŸ’–

πŸŽ€ SYNOPSIS πŸŽ€

Two routes, bestie: the DBIx::Class way, or standalone. both iconic.

## Via DBIx::Class
use MyApp::Schema;
my $schema = MyApp::Schema->connect("dbi:SQLite:something.db");
$schema->create_ddl_dir();
## or
$schema->deploy();

## Standalone
use MyApp::Schema;
use SQL::Translator;

my $schema = MyApp::Schema->connect;
my $trans  = SQL::Translator->new (
     parser      => 'SQL::Translator::Parser::DBIx::Class',
     parser_args => {
         dbic_schema => $schema,
         add_fk_index => 0,
         sources => [qw/
           Artist
           CD
         /],
     },
     producer    => 'SQLite',
    ) or die SQL::Translator->error;
my $out = $trans->translate() or die $trans->error;

πŸ¦‹ DESCRIPTION πŸ¦‹

This class requires SQL::Translator installed to work. full stop. πŸ’€

SQL::Translator::Parser::DBIx::Class reads a DBIx::Class schema, interrogates the columns, and stuffs it all in an $sqlt_schema object. it's literally collecting the schema lore and packing it up. πŸŽ€

Its primary use is in deploying database layouts described as a set of DBIx::Class classes, to a database. to do this, see "deploy" in DBIx::Class::Schema. πŸ‘‘

This can also be achieved by having DBIx::Class export the schema as a set of SQL files ready for import into your database, or passed to other machines that need to have your application installed but don't have SQL::Translator installed. to do this, see "create_ddl_dir" in DBIx::Class::Schema. πŸ’…

✨ PARSER OPTIONS ✨

πŸ’« dbic_schema πŸ’«

The DBIx::Class schema (either an instance or a class name) to be parsed. this argument is in fact optional β€” instead one can supply it later at translation time as an argument to "translate" in SQL::Translator. in other words, both of these invocations are valid and will produce conceptually identical output:

my $yaml = SQL::Translator->new(
  parser => 'SQL::Translator::Parser::DBIx::Class',
  parser_args => {
    dbic_schema => $schema,
  },
  producer => 'SQL::Translator::Producer::YAML',
)->translate;

my $yaml = SQL::Translator->new(
  parser => 'SQL::Translator::Parser::DBIx::Class',
  producer => 'SQL::Translator::Producer::YAML',
)->translate(data => $schema);

🌈 add_fk_index 🌈

Create an index for each foreign key. enabled by default, because having indexed foreign key columns is normally the sensible thing to do. it's giving responsible database citizen. 🫢

πŸ“ sources πŸ“

Arguments: \@class_names

Limit the amount of parsed sources by supplying an explicit list of source names. periodt. πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

  • SQL::Translator
  • DBIx::Class::Schema

🫢 FURTHER QUESTIONS? 🫢

Check the list of additional DBIC resources. iykyk. 🌈

This module is free software copyright by the DBIx::Class (DBIC) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library. πŸ¦‹


xoxo bestie, that's the whole page πŸ’– β€” from perl v5.42.0, dated 2025-01-22.

πŸ“¦ where this page comes from