-
Notifications
You must be signed in to change notification settings - Fork 0
davidwollmann/dbix-class-dataimporter
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
NAME DBIx::Class::DataImporter SYNOPSIS package My::Importer; use Moose; extends 'DBIx::Class::DataImporter'; sub lookup_state_id { my $state = shift; my $id = ...; return $id; } sub find_or_new_zip_id { my $zip = shift; my $id = ...; # find existing email row or insert new email row, return id return $id; } sub find_or_new_email_id { my $email = shift; my $id = ...; # find existing email row or insert new email row, return id return $id; } # In your program use My::Importer; my $imp = My::Importer->new( src_schema => $oldschema, dest_schema => $newschema, import_maps => [ { from_source => 'cust', from_source_rs_method => [ search => { id => { '>' => 100 } } ], to_source => 'Customer', map => [ name => 'name', address1 => 'street1', city => 'city', state => [ \&lookup_state_id, 'state' ], zip => [ \&find_or_new_zip_id, 'zipcode' ], email => [ \&find_or_new_email_id, 'emailaddr' ], ] }, ] ); $imp->run_import(); # or to limit the import to a subset of the defined import maps: $imp->run_import(qw/ cust /); DESCRIPTION Import data from schema 'src_schema' to schema 'dest_schema' using the maps defined in the 'import_maps' array. Use the 'lint' method to sanity check the import maps. Looks for possible truncation, data loss, unreferenced columns, etc. ATTRIBUTES src_schema The source DBIx::Class::Schema object. dest_schema The destination DBIx::Class::Schema object. import_maps A reference to an array of hash references with key-value pairs 'from_source' and 'to_source', specifying source and destination schema source names, and the 'map' key-value pair containing an array with a list of source accessor and destination accessor or a reference to a callback subroutine. The callback subroutine will be passed the value from the source data column and should return the value to be stored in the destination. from_source The schema source from which data are imported. from_source_rs_method Optional name of method to invoke against from_source schema to generate a query to limit the source data set and a hash containing the arguments. See DBIx::Class::ResultSet to_source The schema source to which the imported data are stored. map A reference to an array of source accessor and target specifiers. The target specifier may be either a target schema accessor or a reference to a subroutine. The referent subroutine will be passed the value of the source column. METHODS lint Not yet implemented. Check consistency of maps. Look for real or potential data loss. run_import Run the import. Pass a list of from_source names to limit the import to a subset of the defined import maps. AUTHOR David P.C. Wollmann <converter42 at gmail dot com> CONTRIBUTORS mst and the crew on IRC who answer my silly questions. COPYRIGHT Copyright 2009 by David P.C. Wollmann LICENSE This library is free software and may be distributed under the same terms as perl itself.
About
Import data from one schema to another
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published