Scroll to navigation

Catmandu::Importer::DBI(3pm) User Contributed Perl Documentation Catmandu::Importer::DBI(3pm)

NAME

Catmandu::Importer::DBI - Catmandu module to import data from any DBI source

LIMITATIONS

Text columns are assumed to be utf-8.

SYNOPSIS

 # From the command line 
 $ catmandu convert DBI --dsn dbi:mysql:foobar --user foo --password bar --query "select * from table"
 # From Perl code
 use Catmandu;
 my %attrs = (
        dsn => 'dbi:mysql:foobar' ,
        user => 'foo' ,
        password => 'bar' ,
        query => 'select * from table'
 );
 my $importer = Catmandu->importer('DBI',%attrs);
 # Optional set extra parameters on the database handle
 # $importer->dbh->{LongReadLen} = 1024 * 64;
 $importer->each(sub {
        my $row_hash = shift;
        ...
 });

DESCRIPTION

This Catmandu::Importer can be used to access data stored in a relational database. Given a database handle and a SQL query an export of hits will be exported.

CONFIGURATION

Required. The connection parameters to the database. See DBI for more information.

Examples:

      dbi:mysql:foobar   <= a local mysql database 'foobar'
      dbi:Pg:dbname=foobar;host=myserver.org;port=5432 <= a remote PostGres database
      dbi:SQLite:mydb.sqlite <= a local SQLLite file based database mydb.sqlite
      dbi:Oracle:host=myserver.org;sid=data01 <= a remote Oracle database
    

Drivers for each database need to be available on your computer. Install then with:

    cpanm DBD::mysql
    cpanm DBD::Pg
    cpanm DBD::SQLite
    cpanm DBD::Oracle
    
Optional. A user name to connect to the database
Optional. A password for connecting to the database
Required. An SQL query to be executed against the datbase.

SEE ALSO

Catmandu, Catmandu::Importer , Catmandu::Store::DBI

2024-03-24 perl v5.38.2