DBIx::FixtureLoader - Loading fixtures and inserting to your database
use DBI; use DBIx::FixtureLoader; my $dbh = DBI->connect(...); my $loader = DBIx::FixtureLoader->new(dbh => $dbh); $loader->load_fixture('item.csv');
DBIx::FixtureLoader is to load fixture data and insert to your database.
$loader = DBIx::FixtureLoader->new(%option)
new is Constructor method. Various options may be set in %option, which affect the behaviour of the object (Type and defaults in parentheses):
new
%option
dbh (DBI::db)
Required. Database handler.
bulk_insert (Bool)
Using bulk_insert or not. Default value depends on your database.
update (Bool, Default: false)
Using INSERT ON DUPLICATE or not. It only works on MySQL.
INSERT ON DUPLICATE
ignore (Bool, Default: false)
Using INSERT IGNORE or not. This option is exclusive with update.
INSERT IGNORE
update
csv_option (HashRef, Default: +{})
Specifying Text::CSV's option. binary and blank_is_undef are automatically set.
binary
blank_is_undef
$loader->load_fixture($file_or_data:(Str|HashRef|ArrayRef), [%option])
Loading fixture and inserting to your database. Table name and file format is guessed from file name. For example, "item.csv" contains data of "item" table and format is "CSV".
In most cases %option is not needed. Available keys of %option are as follows.
table:Str
table name of database.
format:Str
data format. "CSV", "YAML" and "JSON" are available.
update:Bool
Using ON DUPLICATE KEY UPDATE or not. Default value depends on object setting.
ON DUPLICATE KEY UPDATE
ignore:Bool
Using INSERT IGNORE or not.
Data format is guessed from extension. Table name is guessed from basename. Leading alphabets, underscores and numbers are considered table name. So, "user_item-2.csv" is considered CSV format and containing data of "user_item" table.
"user_item-2.csv"
"CSV", "YAML" and "JSON" are parsable. CSV file must have header line for determining column names.
Datas in "YAML" or "JSON" must be ArrayRef or HashRef containing HashRefs. Each HashRef is the data of database record and keys of HashRef is matching to column names of the table.
Copyright (C) Masayuki Matsuki.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Masayuki Matsuki <y.songmu@gmail.com>
To install DBIx::FixtureLoader, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::FixtureLoader
CPAN shell
perl -MCPAN -e shell install DBIx::FixtureLoader
For more information on module installation, please visit the detailed CPAN module installation guide.