NAME

DBIx::Class::ResultSet::PrettyPrint - Pretty print DBIx::Class result sets.

VERSION

Version 0.01

SYNOPSIS

use DBIx::Class::ResultSet::PrettyPrint;
use Schema;  # load your DBIx::Class schema

# load your database and fetch a result set
my $schema = Schema->connect( 'dbi:SQLite:books.db' );
my $books = $schema->resultset( 'Book' );

# pretty print the result set
my $pp = DBIx::Class::ResultSet::PrettyPrint->new();
$pp->print_table( $books );

+----+---------------------+---------------+------------+-----------+---------------+
| id | title               | author        | pub_date   | num_pages | isbn          |
+----+---------------------+---------------+------------+-----------+---------------+
| 2  | Perl by Example     | Ellie Quigley | 1994-01-01 | 200       | 9780131228399 |
| 4  | Perl Best Practices | Damian Conway | 2005-07-01 | 517       | 9780596001735 |
+----+---------------------+---------------+------------+-----------+---------------+

DESCRIPTION

Ever wanted to quickly visualise what a DBIx::Class result set looks like (for instance, in tests) without having to resort to reproducing the query in SQL in a DBMS REPL? This is what this module does: it pretty prints result sets wherever you are, be it in tests or within a debugging session.

While searching for such a solution, I stumbled across an answer on StackOverflow and thought: that would be nice as a module. And so here it is.

SUBROUTINES/METHODS

new()

Constructor; creates a new pretty printer object.

Print the "table" from the given result set.

ACKNOWLEDGEMENTS

I borrowed heavily upon the test structure used in https://github.com/davidolrik/DBIx-Class-FormTools for the test database setup and creation.

AUTHOR

Paul Cochrane, <paul at peateasea.de>

BUGS

Please report any bugs or feature requests via the project's GitHub repository at https://github.com/paultcochrane/DBIx-Class-ResultSet-PrettyPrint.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc DBIx::Class::ResultSet::PrettyPrint

Bug reports and pull requests are welcome. Please submit these to the project's GitHub repository.

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by Paul Cochrane.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.