{- |
Module      : DataFrame.Typed.TH.CSV
License     : MIT

CSV-file-based typed-schema derivation. Splits the CSV path out of
@DataFrame.Typed.TH@ so it can live in @dataframe-csv-th@.
-}
module DataFrame.Typed.TH.CSV (
    deriveSchemaFromCsvFile,
    deriveSchemaFromCsvFileWith,
) where

import Control.Monad.IO.Class (liftIO)
import Language.Haskell.TH

import qualified DataFrame.IO.CSV as D
import DataFrame.Typed.TH.Records (deriveSchema)

deriveSchemaFromCsvFile :: String -> String -> DecsQ
deriveSchemaFromCsvFile :: String -> String -> DecsQ
deriveSchemaFromCsvFile = ReadOptions -> String -> String -> DecsQ
deriveSchemaFromCsvFileWith ReadOptions
D.defaultReadOptions

deriveSchemaFromCsvFileWith :: D.ReadOptions -> String -> String -> DecsQ
deriveSchemaFromCsvFileWith :: ReadOptions -> String -> String -> DecsQ
deriveSchemaFromCsvFileWith ReadOptions
opts String
typeName String
path = do
    DataFrame
df <- IO DataFrame -> Q DataFrame
forall a. IO a -> Q a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (ReadOptions -> String -> IO DataFrame
D.readSeparated ReadOptions
opts String
path)
    String -> DataFrame -> DecsQ
deriveSchema String
typeName DataFrame
df