avro-0.3.2.0: Avro serialization support for Haskell

Safe HaskellNone
LanguageHaskell2010

Data.Avro.Deriving

Contents

Synopsis

Deriving options

data DeriveOptions Source #

Derives Avro from a given schema file. Generates data types, FromAvro and ToAvro instances.

Constructors

DeriveOptions 

Fields

Instances

Generic DeriveOptions Source # 

Associated Types

type Rep DeriveOptions :: * -> * #

type Rep DeriveOptions Source # 
type Rep DeriveOptions = D1 * (MetaData "DeriveOptions" "Data.Avro.Deriving" "avro-0.3.2.0-9cD8U4h12AjEj8sJagXFYl" False) (C1 * (MetaCons "DeriveOptions" PrefixI True) (S1 * (MetaSel (Just Symbol "fieldNameBuilder") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (TypeName -> Field -> Text))))

defaultDeriveOptions :: DeriveOptions Source #

Default deriving options

defaultDeriveOptions = DeriveOptions
  { fieldNameBuilder = mkPrefixedFieldName
  }

mkPrefixedFieldName :: TypeName -> Field -> Text Source #

Generates a field name that is prefixed with the type name.

For example, if the schema defines type Person that has a field firstName, then the generated Haskell type will be like

Person { personFirstName :: Text }

mkAsIsFieldName :: TypeName -> Field -> Text Source #

Generates a field name that matches the field name in schema (sanitised for Haskell, so first letter is lower cased)

For example, if the schema defines type Person that has a field firstName, then the generated Haskell type will be like

Person { firstName :: Text }

You may want to enable DuplicateRecordFields if you want to use this method.

Deriving Haskell types from Avro schema

makeSchema :: FilePath -> Q Exp Source #

Generates the value of type Schema that it can later be used with deriveAvro' or deriveAvroWithOptions'.

mySchema :: Schema
mySchema = $(makeSchema "schemas/my-schema.avsc")

deriveAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec] Source #

Generates Haskell classes and FromAvro and ToAvro instances given the Avro schema file

deriveAvroWithOptions' :: DeriveOptions -> Schema -> Q [Dec] Source #

Generates Haskell classes and FromAvro and ToAvro instances given the Avro schema

deriveFromAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec] Source #

Derives "read only" Avro from a given schema file. Generates data types and FromAvro.

deriveAvro :: FilePath -> Q [Dec] Source #

Same as deriveAvroWithOptions but uses defaultDeriveOptions

deriveAvro' = deriveAvroWithOptions' defaultDeriveOptions

deriveFromAvro :: FilePath -> Q [Dec] Source #

Derives "read only" Avro from a given schema file. Generates data types and FromAvro.