Diab Jerius
and 1 contributors

NAME

Data::Record::Serialize::Encode::dbi - store a record in a database

SYNOPSIS

    use Data::Record::Serialize;

    my $s = Data::Record::Serialize->new( encode => 'sqlite', ... );

    $s->send( \%record );

DESCRIPTION

Data::Record::Serialize::Encode::dbi writes a record to a database using DBI.

It performs both the Data::Record::Serialize::Role::Encode and Data::Record::Serialize::Role::Sink roles.

Types

Field types are recognized and converted to SQL types via the following map:

  S => 'text'
  N => 'real'
  I => 'integer'

Performance

Records are by default written to the database in batches (see the batch attribute) to improve performance. Each batch is performed as a single transaction. If there is an error during the transaction, record insertions during the transaction are not rolled back.

INTERFACE

You cannot construct this directly; you must use Data::Record::Serialize->new.

Attributes

These attributes are available in addition to the standard attributes defined for Data::Record::Serialize->new.

dsn

Required The DBI Data Source Name (DSN) passed to DBI. It may either be a string or an arrayref containing strings or arrayrefs, which should contain key-value pairs. Elements in the sub-arrays are joined with =, elements in the top array are joined with :. For example,

  [ 'SQLite', { dbname => $db } ]

is transformed to

  SQLite:dbname=$db

The standard prefix of dbi: will be added if not present.

db_user

The name of the database user

dbitrace

A trace setting passed to DBI.

batch

The number of rows to write to the database at once. This defaults to 100.

If greater than 1, batch rows are cached and then sent out in a single transaction. See "Performance" for more information.

db_pass

The database password

table

Required The name of the table in the database which will contain the records. It will be created if it does not exist.

drop_table

If true, the table is dropped and a new one is created.

create_table

If true, a table will be created if it does not exist.

primary

The output name of the field which should be the primary key. If not specified, no primary keys are defined.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-data-record-serialize@rt.cpan.org, or through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize.

SEE ALSO

LICENSE AND COPYRIGHT

Copyright (c) 2014 The Smithsonian Astrophysical Observatory

Data::Record::Serialize is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. p This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

AUTHOR

Diab Jerius <djerius@cpan.org>