The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

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 (defaults shown):

### DBH settings:
# expand database handle objects
filter_db.connection_details = 1
### DBIx::Class settings:
# signal when a result column is dirty:
filter_db.show_updated_label = 1
# signal when result rows contain extra columns:
filter_db.show_extra_label = 1
# override class.expand for schema dump
filter_db.schema.expand = 1
# expand DBH handle on schema dump (may touch DB)
filter_db.schema.show_handle = 0
# show source details (connected tables) on schema dump
# (may be set to 'names', 'details' or 'none')
filter_db.schema.loaded_sources = names
# show source table name ResultSource objects
filter_db.show_source_table = 1
# show source columns ('names', 'details' or 'none'):
filter_db.column_info = details
# this plugin honors theme colors where applicable
# and provides the following custom colors for you to use:
colors.filter_db_connected = #a0d332
colors.filter_db_disconnected = #b3422d

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