module Data.Csv.Builder
(
encodeHeader
, encodeRecord
, encodeNamedRecord
, encodeDefaultOrderedNamedRecord
, encodeHeaderWith
, encodeRecordWith
, encodeNamedRecordWith
, encodeDefaultOrderedNamedRecordWith
) where
import Data.Monoid
import Data.ByteString.Builder as Builder
import Data.Csv.Conversion
import qualified Data.Csv.Encoding as Encoding
import Data.Csv.Encoding (EncodeOptions(..))
import Data.Csv.Types hiding (toNamedRecord)
encodeHeader :: Header -> Builder.Builder
encodeHeader = encodeRecord
encodeRecord :: ToRecord a => a -> Builder.Builder
encodeRecord = encodeRecordWith Encoding.defaultEncodeOptions
encodeNamedRecord :: ToNamedRecord a =>
Header -> a -> Builder.Builder
encodeNamedRecord = encodeNamedRecordWith Encoding.defaultEncodeOptions
encodeDefaultOrderedNamedRecord ::
(DefaultOrdered a, ToNamedRecord a) => a -> Builder.Builder
encodeDefaultOrderedNamedRecord =
encodeDefaultOrderedNamedRecordWith Encoding.defaultEncodeOptions
encodeHeaderWith :: EncodeOptions -> Header -> Builder.Builder
encodeHeaderWith = encodeRecordWith
encodeRecordWith :: ToRecord a => EncodeOptions -> a -> Builder.Builder
encodeRecordWith opts r =
Encoding.encodeRecord (encQuoting opts) (encDelimiter opts) (toRecord r)
<> Encoding.recordSep (encUseCrLf opts)
encodeNamedRecordWith :: ToNamedRecord a =>
EncodeOptions -> Header -> a -> Builder.Builder
encodeNamedRecordWith opts hdr nr =
Encoding.encodeNamedRecord hdr (encQuoting opts) (encDelimiter opts)
(toNamedRecord nr) <> Encoding.recordSep (encUseCrLf opts)
encodeDefaultOrderedNamedRecordWith ::
forall a. (DefaultOrdered a, ToNamedRecord a) =>
EncodeOptions -> a -> Builder.Builder
encodeDefaultOrderedNamedRecordWith opts =
encodeNamedRecordWith opts (headerOrder (undefined :: a))