cassava-records-0.1.0.4: Auto-generation of records data type.

Copyright(c) Guru Devanla 2018
LicenseMIT
Maintainergrdvnl@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.Cassava.Records

Contents

Description

This module provides an easy way to explore input files that may have numerous columns by helping create a Record types by guessing the types. That information can be used as is or persisted to a file so that other customizations can be performed.

Synopsis

Creating Record types

 

makeCsvRecord Source #

Arguments

:: String

Name to use for the Record type being created

-> FilePath

File path of input file

-> String

Prefix to be used to field names. Recommended to use "_" to work well with Lens

-> DecodeOptions

DecodeOptions as required by Cassava to read the input file

-> DecsQ 

Makes the Record that reflects the types inferred from the input file.

 

commaOptions :: DecodeOptions Source #

Provides a default DecodeOptions for comma separated input files

 

tabOptions :: DecodeOptions Source #

Provides a default DecodeOptions for tab separated input files

makeInstance Source #

Arguments

:: String

name of record for which the instance needs to be created

-> DecsQ 

Convinience method that creates the default instances required by Cassava. The generated methods assumed fields are prefixed with "_".

For example, if the column header in the input file have upper case or mixed case the names will not directly match with field names in the record. In that case explicity instances have to be provided manually and the field modifiers provided accordingly.

For example, if the columns in the input file have all headers listed in upper case, since the field names are all lower case, the defaultFieldNameOptions function would look like this

defaultFieldNameOptions :: Options
defaultFieldNameOptions = defaultOptions { fieldLabelModifier = rmUnderscore }
  where
    rmUnderscore ('_':str) = DT.unpack . DT.toUpper . DT.pack $ str
    rmUnderscore str = str

Note the DT.toUpper call to convert the field names to upper case before comparing to NamedRecords

 

loadData Source #

Arguments

:: FromNamedRecord a 
=> FilePath

Path of the file to be loaded

-> IO (Vector a)

a will be of a Record type

Helper function to load the data from the the provided file path