Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data DeriveOptions = DeriveOptions {
- fieldNameBuilder :: TypeName -> Field -> Text
- fieldRepresentation :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
- data FieldStrictness
- data FieldUnpackedness
- defaultDeriveOptions :: DeriveOptions
- mkPrefixedFieldName :: TypeName -> Field -> Text
- mkAsIsFieldName :: TypeName -> Field -> Text
- mkLazyField :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
- mkStrictPrimitiveField :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness)
- makeSchema :: FilePath -> Q Exp
- deriveAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec]
- deriveAvroWithOptions' :: DeriveOptions -> Schema -> Q [Dec]
- deriveFromAvroWithOptions :: DeriveOptions -> FilePath -> Q [Dec]
- deriveAvro :: FilePath -> Q [Dec]
- deriveAvro' :: Schema -> Q [Dec]
- deriveFromAvro :: FilePath -> Q [Dec]
Deriving options
data DeriveOptions Source #
Derives Avro from a given schema file. Generates data types, FromAvro and ToAvro instances.
DeriveOptions | |
|
Instances
Generic DeriveOptions Source # | |
Defined in Data.Avro.Deriving type Rep DeriveOptions :: * -> * # from :: DeriveOptions -> Rep DeriveOptions x # to :: Rep DeriveOptions x -> DeriveOptions # | |
type Rep DeriveOptions Source # | |
Defined in Data.Avro.Deriving type Rep DeriveOptions = D1 (MetaData "DeriveOptions" "Data.Avro.Deriving" "avro-0.3.5.1-7DszkXVyvMFKBf6ZP6snk4" False) (C1 (MetaCons "DeriveOptions" PrefixI True) (S1 (MetaSel (Just "fieldNameBuilder") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (TypeName -> Field -> Text)) :*: S1 (MetaSel (Just "fieldRepresentation") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (TypeName -> Field -> (FieldStrictness, FieldUnpackedness))))) |
data FieldStrictness Source #
Describes the strictness of a field for a derived
data type. The field will be derived as if it were
written with a !
.
Instances
Generic FieldStrictness Source # | |
Defined in Data.Avro.Deriving type Rep FieldStrictness :: * -> * # from :: FieldStrictness -> Rep FieldStrictness x # to :: Rep FieldStrictness x -> FieldStrictness # | |
type Rep FieldStrictness Source # | |
data FieldUnpackedness Source #
Describes the representation of a field for a derived
data type. The field will be derived as if it were written
with an {--}
pragma.
Instances
Generic FieldUnpackedness Source # | |
Defined in Data.Avro.Deriving type Rep FieldUnpackedness :: * -> * # from :: FieldUnpackedness -> Rep FieldUnpackedness x # to :: Rep FieldUnpackedness x -> FieldUnpackedness # | |
type Rep FieldUnpackedness Source # | |
defaultDeriveOptions :: DeriveOptions Source #
Default deriving options
defaultDeriveOptions =DeriveOptions
{ fieldNameBuilder =mkPrefixedFieldName
, fieldStrictness =mkLazyField
}
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.
mkLazyField :: TypeName -> Field -> (FieldStrictness, FieldUnpackedness) Source #
Marks any field as non-strict in the generated data types.
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 #
deriveAvroWithOptions' :: DeriveOptions -> Schema -> Q [Dec] Source #
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
deriveAvro' :: Schema -> Q [Dec] Source #
Same as deriveAvroWithOptions'
but uses defaultDeriveOptions
deriveAvro' =deriveAvroWithOptions'
defaultDeriveOptions