Scroll to navigation

SQL::Translator::Parser::DBIx::Class(3pm) User Contributed Perl Documentation SQL::Translator::Parser::DBIx::Class(3pm)

NAME

SQL::Translator::Parser::DBIx::Class - Create a SQL::Translator schema from a DBIx::Class::Schema instance

SYNOPSIS

 ## 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.

"SQL::Translator::Parser::DBIx::Class" reads a DBIx::Class schema, interrogates the columns, and stuffs it all in an $sqlt_schema object.

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 the following 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, as having indexed foreign key columns is normally the sensible thing to do.

sources

Limit the amount of parsed sources by supplying an explicit list of source names.

SEE ALSO

SQL::Translator, DBIx::Class::Schema

FURTHER QUESTIONS?

Check the list of additional DBIC resources.

COPYRIGHT AND LICENSE

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.

2022-05-21 perl v5.34.0