Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Stream, parse, and validate CSVs
A minor extension of cassava.
Using MonadValidate
and Conduit
.
Synopsis
- csvWithValidationSink :: forall a b err m. (MonadThrow m, MonadUnliftIO m, PrimMonad m, ValidateHeader a, FromNamedRecord a) => ConduitT () ByteString (ResourceT m) () -> (Vector a -> Validate (NonEmpty (CsvException err)) (Vector b)) -> m (Validate (NonEmpty (CsvException err)) (Vector b))
- csvWithParserAndValidationSink :: forall a b err m. (MonadThrow m, MonadUnliftIO m, PrimMonad m) => (Header -> Validate (NESeq String) ()) -> (NamedRecord -> Parser a) -> ConduitT () ByteString (ResourceT m) () -> (Vector a -> Validate (NonEmpty (CsvException err)) (Vector b)) -> m (Validate (NonEmpty (CsvException err)) (Vector b))
- runCsvConduit :: forall r m err. MonadUnliftIO m => ConduitT () Void (ValidateT (Seq (CsvException err)) (ResourceT m)) r -> m (Either (Seq (CsvException err)) r)
- decodeCsv :: forall a m err. (MonadThrow m, MonadValidate (Seq (CsvException err)) m, ValidateHeader a, FromNamedRecord a) => ConduitT ByteString a m ()
- class ValidateHeader a
- validateHeader :: (ValidateHeader a, Bind m, Monad m) => proxy a -> Header -> ValidateT (NESeq String) m ()
- hasHeader :: Monad m => Header -> Name -> ValidateT (NESeq String) m ()
- defaultValidateOrderedHeader :: forall a proxy m. (DefaultOrdered a, Monad m) => proxy a -> Header -> ValidateT (NESeq String) m ()
- data CsvException a
- defaultOptions :: Options
Documentation
csvWithValidationSink Source #
:: forall a b err m. (MonadThrow m, MonadUnliftIO m, PrimMonad m, ValidateHeader a, FromNamedRecord a) | |
=> ConduitT () ByteString (ResourceT m) () | CSV as a byte stream |
-> (Vector a -> Validate (NonEmpty (CsvException err)) (Vector b)) | Validation to apply to resulting rows |
-> m (Validate (NonEmpty (CsvException err)) (Vector b)) |
Stream parse a CSV
- Expects UTF-8
- Provides incremental validation
csvWithParserAndValidationSink Source #
:: forall a b err m. (MonadThrow m, MonadUnliftIO m, PrimMonad m) | |
=> (Header -> Validate (NESeq String) ()) | |
-> (NamedRecord -> Parser a) | Custom record parser |
-> ConduitT () ByteString (ResourceT m) () | CSV as a byte stream |
-> (Vector a -> Validate (NonEmpty (CsvException err)) (Vector b)) | Validation to apply to resulting rows |
-> m (Validate (NonEmpty (CsvException err)) (Vector b)) |
Stream parse a CSV with a custom parser
- Expects UTF-8
- Provides incremental validation
Conduit Primitives
runCsvConduit :: forall r m err. MonadUnliftIO m => ConduitT () Void (ValidateT (Seq (CsvException err)) (ResourceT m)) r -> m (Either (Seq (CsvException err)) r) Source #
Run a CSV conduit handling invalid UTF8
decodeCsv :: forall a m err. (MonadThrow m, MonadValidate (Seq (CsvException err)) m, ValidateHeader a, FromNamedRecord a) => ConduitT ByteString a m () Source #
Stream in ByteString
s and parse records in constant space
Header Validation
class ValidateHeader a Source #
validateHeader :: (ValidateHeader a, Bind m, Monad m) => proxy a -> Header -> ValidateT (NESeq String) m () Source #
defaultValidateOrderedHeader :: forall a proxy m. (DefaultOrdered a, Monad m) => proxy a -> Header -> ValidateT (NESeq String) m () Source #
Exceptions
data CsvException a Source #
CsvMissingColumn !Text | |
CsvParseException !Int !Text | |
CsvFileNotFound | |
CsvUnknownFileEncoding | |
CsvExceptionExtension a | A constructor for providing extensible csv exceptions |
Instances
ToJSON a => ToJSON (CsvException a) Source # | |
Defined in Freckle.App.Csv toJSON :: CsvException a -> Value # toEncoding :: CsvException a -> Encoding # toJSONList :: [CsvException a] -> Value # toEncodingList :: [CsvException a] -> Encoding # | |
Show a => Show (CsvException a) Source # | |
Defined in Freckle.App.Csv showsPrec :: Int -> CsvException a -> ShowS # show :: CsvException a -> String # showList :: [CsvException a] -> ShowS # | |
Eq a => Eq (CsvException a) Source # | |
Defined in Freckle.App.Csv (==) :: CsvException a -> CsvException a -> Bool # (/=) :: CsvException a -> CsvException a -> Bool # |