DBIx::Inspector Schema Loader

Today, I was looking for a simple module that fetches my DB schema. Played around with DBIx::Class::Schema::Loader and Rose::DB::Object::Metadata, with no success.

Have already given up, but finally decided to make a Github search for DBIx, which provided exactly what I needed. Just curious why it was so hard to find this module?


use DBI;
use DBIx::Inspector;
use 5.010000;

my $username = "";
my $password = "";

$dbh = DBI->connect('dbi:mysql:mydb', $username, $password)
            or die $DBI::errstr;

my $inspector = DBIx::Inspector->new(dbh => $dbh);

my $table = $inspector->tables('users')->next;

say "Name";
say "    ", $table->name;

say "Primary Keys";
for my $pk ($table->primary_key) {
    say "   ", $pk->name;

say "Columns";
for my $column ($table->columns) {
    say "    ", $column->name, " ", $column->type_name,
      "(", $column->column_size ,")";


About Forward Ever

user-pic I blog about Perl.