NAME

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

VERSION

0.97_3. Development release.

SYNOPSIS

sqldb-schema [options] DSN [OUTFILE]

DESCRIPTION

sqldb-schema is a helper for building SQL::DB-based Perl applications. Given a Data Source Name (DSN) or SQLite filename, sqldb-schema will connect to the database and build the Perl code to define a matching schema.

Use of sqldb-schema is not necessary for SQL::DB applications, but is 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.

Output is printed to STDOUT if OUTFILE is not specified.

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

$ sqldb-schema -s 'myapp' -p My::App::Schema \
    dbi:Pg:dbname=myapp lib/My/App/Schema.pm
Username: mylogin
Password: ********

Then in your application code you 'use' your schema module and set the SQL::DB object "schema" attribute to the same '-s' value:

package My::App;
use SQL::DB;
use My::App::Schema

my $db = SQL::DB->new(
    dsn    => $dsn,
    schema => 'myapp', # must match the '-s'
);

Now any calls to "urow" or "srow" on the $db object will not need to query the database for 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

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

--schema, -s

The name of the SQL::DB schema. Defaults to 'default'. You will need to set your SQL::DB object's "schema" attribute to the same value.

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

--package, -p

An optional package name to include in the output. Useful (but not strictly necessary) if you want to send the output directly to a module file:

$ sqldb-schema -p My::App::Schema myapp.sqlite \
    lib/My/App/Schema.pm

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.