| DBIx-DataModel documentation | view source | Contained in the DBIx-DataModel distribution. |
DBIx::DataModel::Schema::Generator - automatically generate a schema for DBIx::DataModel
perl -MDBIx::DataModel::Schema::Generator \
-e "fromDBI('dbi:connection:string')" -- \
-schema My::New::Schema > My/New/Schema.pm
perl -MDBIx::DataModel::Schema::Generator \
-e "fromDBIxClass('Some::DBIC::Schema')" -- \
-schema My::New::Schema > My/New/Schema.pm
If SQL::Translator is installed
sqlt -f <parser> -t DBIx::DataModel::Schema::Generator <parser_input>
Generates schema, table and association declarations for DBIx::DataModel, either from a DBI connection, or from an existing DBIx::Class schema. The result is written on standard output and can be redirected to a .pm file.
The module can be called easily from the perl command line,
as demonstrated in the synopsis above. Command-line arguments
after -- are passed to method new.
Alternatively, if SQL::Translator is
installed, you can use DBIx::DataModel::Schema::Generator
as a producer, translating from any available
SQL::Translator parser.
The generated code is a skeleton that most probably will need some manual additions or modifications to get a fully functional datamodel, because part of the information cannot be inferred automatically. In particular, you should inspect the names and multiplicities of the generated associations, and decide which of these associations should rather be compositions (Composition in DBIx::DataModel::Doc::Reference); and you should declare the column types (ColumnType in DBIx::DataModel::Doc::Reference) for columns that need automatic inflation/deflation.
my $generator = DBIx::DataModel::Schema::Generator->new(@args);
Creates a new instance of a schema generator.
Functions fromDBI and fromDBIxClass automatically call
new if necessary, so usually you do not need to call it yourself.
Arguments are :
Name of the DBIx::DataModel::Schema
subclass that will be generated (default is My::Schema).
$generator->fromDBI(@dbi_connection_args); # or fromDBI(@dbi_connection_args);
Connects to a DBI data source, gathers information from the
database about tables, primary and foreign keys, and generates
a DBIx::DataModel schema on standard output.
This can be used either as a regular method, or as
a function (this function is exported by default).
In the latter case, a generator is automatically
created by calling new with arguments @ARGV.
DBI connection arguments are as in connect in DBI.
$generator->fromDBIxClass('Some::DBIC::Schema');
# or
fromDBIxClass('Some::DBIC::Schema');
Loads an existing DBIx::Class schema, and translates
its declarations into a DBIx::DataModel schema
printed on standard output.
This can be used either as a regular method, or as
a function (this function is exported by default).
In the latter case, a generator is automatically
created by calling new with arguments @ARGV.
Implementation of SQL::Translator::Producer.
Laurent Dami, <laurent.dami AT etat ge ch>
Copyright 2008 Laurent Dami.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| DBIx-DataModel documentation | view source | Contained in the DBIx-DataModel distribution. |