The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Printer::Filter::DB - pretty-printing database objects (DBI, DBIx::Class, etc)

SYNOPSIS

In your .dataprinter file:

    filters = DB

You may also customize the look and feel with the following options:

    filter_db.expand_dbh = 1

    # you can even customize your themes:
    colors.filter_db_connected    = #00cc00
    colors.filter_db_disconnected = #cc0000

That's it!

DESCRIPTION

This is a filter plugin for Data::Printer that displays (hopefully) more relevant information on database objects than a regular dump.

Parsed Modules

DBI

If it's a database handle, for example, this filter may show you something like this:

    SQLite Database Handle (connected) {
        dbname: file.db
        Auto Commit: 1
        Statement Handles: 2 (1 active)
        Last Statement: SELECT * FROM some_table
    }

You can show less information by setting this option on your .dataprinter:

    filter_db.connection_details = 0

If you have a statement handler like this (for example):

    my $sth = $dbh->prepare('SELECT * FROM foo WHERE bar = ?');
    $sth->execute(42);

    use DDP; p $sth;

This is what you'll get:

    SELECT * FROM foo WHERE bar = ?  (42)

Note that if your driver does not support holding of parameter values, you'll get a bindings unavailable message instead of the bound values.

DBIx::Class

This filter is able to pretty-print many common DBIx::Class objects for inspection. Unless otherwrise noted, none of those calls will touch the database.

DBIx::Class::Schema objects are dumped by default like this:

    MyApp::Schema {
        connection: MySQL Database Handle (connected)
        replication lag: 4
        loaded sources: ResultName1, ResultName2, ResultName3
    }

If your .dataprinter settings have class.expand set to 0, it will only show this:

    MyApp::Schema (MySQL - connected)

You may override this with filter_db.schema.expand = 1 (or 0). Other available options for the schema are (default values shown):

    # if set to 1, expands 'connection' into a complete DBH dump
    # NOTE: this may touch the database as it could try to reconnect
    # to fetch a healthy DBH:
    filter_db.schema.show_handle = 0

    # set to 'expand' to view source details, or 'none' to skip it:
    filter_db.schema.loaded_sources = names

DBIx::Class::ResultSource objects will be expanded to show details of what that source represents on the database (as perceived by DBIx::Class), including column information and whether the table is virtual or not.

    User ResultSource {
        table: "user"
        columns:
            user_id integer not null auto_increment (primary),
            email varchar(100),
            bio text
        non-primary uniques:
            (email) as 'user_email'
    }

Ever got bit by DBIx::Class?

Let us know if we can help by creating an issue on Data::Printer's Github. Patches are welcome!

SEE ALSO

Data::Printer