DBIx::MultiDB - join data from multiple databases
use DBIx::MultiDB; # Example 1 my $query = DBIx::MultiDB->new( dsn => 'dbi:SQLite:dbname=/tmp/db1.db', sql => 'SELECT id, name, company_id FROM employee', ); $query->left_join( dsn => 'dbi:SQLite:dbname=/tmp/db2.db', sql => 'SELECT id, name AS company_name FROM company', key => 'id', # in this table referenced_by => 'company_id', # in base table ); $query->execute(); # Example 2 my $query = DBIx::MultiDB->new( dsn => 'dbi:SQLite:dbname=/tmp/db1.db', ); $query->left_join( dsn => 'dbi:SQLite:dbname=/tmp/db2.db', sql => 'SELECT id, name AS company_name FROM company', key => 'company_id', # in base table references => 'id', # in this table ); $query->prepare('SELECT id, name, company_id FROM employee'); $query->execute(); while ( my $row = $query->fetchrow_hashref ) { # ... }
DBIx::MultiDB provides a simple way to join data from different sources.
You are not limited to a single database engine: in fact, you can join data from any source for which you have a DBI driver (MySQL, PostgreSQL, SQLite, etc). You can even mix them!
Constructor. You can provide a dsn and sql, which is your base query.
Once you have a base query, you can attach multiple queries that will be joined to it. For each one, you must provide a dsn, sql, and the relationship information (key and referenced_by).
Please note that this will also load the attached query into memory.
Not yet implemented.
If you didn't provide the sql to the constructor, you can do it here. Example:
$query->prepare('SELECT id, name, company_id FROM employee'); $query->execute();
Execute the base query.
Return a hashref, containing field names and values. The keys pointing to attached queries will be expanded into the attached queries' fields.
Nelson Ferraz, <nferraz at gmail.com>
<nferraz at gmail.com>
While the base query is processed row by row, the joined tables must be previously stored in memory.
That means you can easily process hundreds of millions rows in the base query; but you must watch how much information you retrieve in the joins.
Please report any bugs or feature requests to bug-dbix-multidb at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-MultiDB. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dbix-multidb at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc DBIx::MultiDB
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-MultiDB
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/DBIx-MultiDB
CPAN Ratings
http://cpanratings.perl.org/d/DBIx-MultiDB
Search CPAN
http://search.cpan.org/dist/DBIx-MultiDB/
Copyright 2010 Nelson Ferraz, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::MultiDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::MultiDB
CPAN shell
perl -MCPAN -e shell install DBIx::MultiDB
For more information on module installation, please visit the detailed CPAN module installation guide.