SQLDB-SCHEMA(1)

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

VERSION
0.191.0. Development release.

SYNOPSIS
  sqldb-schema [options] DATABASE PACKAGE [OUTFILE]

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

Use of sqldb-schema is not necessary for 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 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 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.

OPTIONS

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

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

--dbschema, -d
    The name of the database schema (if any) to narrow down the result of the 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.

SEE ALSO
SQL::DB, SQL::DB::Schema, App::sqldb_schema

AUTHOR
Mark Lawrence <nomad@null.net>

COPYRIGHT AND LICENSE
Copyright 2011 Mark Lawrence <nomad@null.net>

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.