Module csv

CSV file parsing functions.

Copyright © 2021 Serge Aleynikov

Authors: Serge Aleynikov (saleyn@gmail.com).

Description

CSV file parsing functions

Function Index

guess_data_type/1
guess_data_types/2
load_to_mysql/4Load CSV data from File to MySQL database NOTE: this function requires https://github.com/mysql-otp/mysql-otp.git.
max_field_lengths/2Get max field lengths for a list obtained by parsing a CSV file with parse_csv_file(File,[fix_lengths]).
parse/1
parse/2Parse a given CSV file.
parse_line/1

Function Details

guess_data_type/1

guess_data_type(S :: binary()) ->
                   {null | date | datetime | integer | float |
                    string,
                    term(),
                    string()}

guess_data_types/2

guess_data_types(HasHeaders, CSV) -> any()

load_to_mysql/4

load_to_mysql(File :: string(),
              Tab :: string(),
              MySqlPid :: pid(),
              Opts ::
                  [{batch_size, integer()} |
                   {blob_size, integer()} |
                   {save_create_sql_to_file, string()} |
                   {guess_types, boolean()} |
                   {guess_limit_rows, integer()} |
                   {max_nulls_pcnt, float()} |
                   {primary_key,
                    PKColumns :: binary() | [binary() | list()]} |
                   {encoding, string() | atom()} |
                   {verbose, boolean()}]) ->
                 {Columns :: list(), RecCount :: integer()}

Load CSV data from File to MySQL database NOTE: this function requires https://github.com/mysql-otp/mysql-otp.git

max_field_lengths/2

max_field_lengths(HasHeaderRow :: boolean(),
                  Rows :: [Fields :: list()]) ->
                     [Len :: integer()]

Get max field lengths for a list obtained by parsing a CSV file with parse_csv_file(File,[fix_lengths]).

parse/1

parse(File :: string()) -> [[string()]]

parse/2

parse(File :: string(),
      Opts :: [fix_lengths | {open, Opts :: list()}]) ->
         [[string()]]

Parse a given CSV file. Options:

fix_lengths
if a record has a column count greater than what's found in the header row, those extra columns will be dropped, and if a row has fewer columns, empty columns will be added.
{open, list()}
Options given to file:open/2
{open, list()}
Options given to file:open/2

parse_line/1

parse_line(Line) -> any()


Generated by EDoc