The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Beam::Make::DBI::CSV - A Beam::Make recipe

VERSION

version 0.001

SYNOPSIS

    ### container.yml
    # A Beam::Wire container to configure a database connection to use
    sqlite:
        $class: DBI
        $method: connect
        $args:
            - dbi:SQLite:conversion.db

    ### Beamfile
    load_data:
        $class: Beam::Wire::DBI
        dbh: { $ref: 'container.yml:sqlite' }
        table: cpan_recent
        file: cpan_recent.csv

DESCRIPTION

This Beam::Make recipe class loads data into a database from a CSV file.

ATTRIBUTES

dbh

Required. The DBI database handle to use. Can be a reference to a service in a Beam::Wire container using { $ref: "<container>:<service>" }.

table

Required. The table to load data to.

file

Required. The path to the CSV file to load.

csv

The configured Text::CSV object to use. Can be a reference to a service in a Beam::Wire container using { $ref: "<container>:<service>" }. Defaults to a new, blank Text::CSV object.

    ### container.yml
    # Configure a CSV parser for pipe-separated values
    psv:
        $class: Text::CSV
        $args:
            - binary: 1
              sep_char: '|'
              quote_char: ~
              escape_char: ~

    ### Beamfile
    # Load a PSV into the database
    load_psv:
        $class: Beam::Make::DBI::CSV
        dbh: { $ref: 'container.yml:sqlite' }
        csv: { $ref: 'container.yml:psv' }
        file: accounts.psv
        table: accounts

SEE ALSO

Beam::Make, Beam::Wire, DBI

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Doug Bell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.