#!/usr/bin/perl
use strict;
use warnings;
use App::sqldb_schema::Dispatcher;

App::sqldb_schema::Dispatcher->run;

__END__

=head1 NAME

sqldb-schema - generate a SQL::DB schema from a database

=head1 VERSION

0.19_10. Development release.

=head1 SYNOPSIS

  sqldb-schema [options] DSN PACKAGE [OUTFILE]

=head1 DESCRIPTION

B<sqldb-schema> is a helper for building L<SQL::DB>-based Perl
applications. Given a Data Source Name (DSN) (or SQLite filename) and a
Perl package class, B<sqldb-schema> will connect to the database and
output a Perl module that can be used by L<SQL::DB::Schema> at runtime.
Output is printed to STDOUT if OUTFILE is not specified.

Use of B<sqldb-schema> is not necessary for L<SQL::DB> applications,
but could be an important optimisation to minimize database calls in
applications with more than a trivial number of tables. This is more
interesting for remote database engines such as PostgreSQL with a
higher query latency than for local database engines such as SQLite.

The standard usage scenario is as follows. After any schema change to
your database you run B<sqldb-schema> and save the output as a Perl
module:

    $ sqldb-schema dbi:Pg:dbname=myapp MyApp::Pg lib/MyApp/Pg.pm
    Username: mylogin
    Password: ********

Then in your application code you set the L<SQL::DB> object "schema"
attribute to the schema package, but without the trailing ::Driver.
SQL::DB will automatically add the missing '::Driver' part based on the
'dsn' value. This way your constructor doesn't need to change if you
are running the same code against different database types.

    package MyApp;
    use SQL::DB;

    my $db = SQL::DB->new(
        dsn    => 'dbi:Pg:dbname=myapp',
        dbuser => 'username',
        dbpass => '******',
        schema => 'MyApp', # ::Pg will automatically be appended
    );

Now any calls to "urow" or "srow" on the $db object will not need to
query the database to know the table structure.

=head1 OPTIONS

=over 4

=item --username, -u

The username to connect to the database with. You will be prompted if
this is not given (for any driver other than SQLite).

=item --password, -p

The password to connect to the database with. For security reasons it
is not recommended to use this option. You will be prompted if this is
not given (for any driver other than SQLite).

=item --dbschema, -d

The name of the database schema (if any) to narrow down the result of
the L<DBI> "table_info" call. For PostgreSQL databases this defaults to
'public'. For SQLite databases this defaults to 'main'. Setting it to
'%' will retrieve the tables from all schemas.

=back

=head1 SEE ALSO

L<SQL::DB>, L<SQL::DB::Schema>, L<App::sqldb_schema>

=head1 AUTHOR

Mark Lawrence E<lt>nomad@null.netE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2011 Mark Lawrence E<lt>nomad@null.netE<gt>

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

=cut
