The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version 0.13

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.

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

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.

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.

table

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

schema

The schema to which the table belongs. Optional.

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

A single output column name or an array of output column names which should be the primary key(s). If not specified, no primary keys are defined.

db_user

The name of the database user

db_pass

The database password

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.

dbitrace

A trace setting passed to DBI.

BUGS AND LIMITATIONS

You can make new bug reports, and view existing ones, through the web interface at https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize.

SEE ALSO

Please see those modules/websites for more information related to this module.

AUTHOR

Diab Jerius <djerius@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007