beam-migrate-0.2.0.0: SQL DDL support and migrations support library for Beam

Safe HaskellNone
LanguageHaskell2010

Database.Beam.Migrate.Serialization

Contents

Description

Serialization and deserialization helpers for beam data types.

Used to read and write machine-readable schema descriptions.

Synopsis

Serialization helpers

Below we provide various instances of Beam SQL syntax types that produce an aeson Value that reflects the call tree. This allows us to read back these data types in various syntaxes.

Because these are formatted as standard beam syntaxes, backends can easily serialize their data to disk. For an example of what we mean by this, see the instance of IsSql92DataTypeSyntax for SqliteDataTypeSyntax in beam-sqlite.

newtype BeamSerializedDataType Source #

An IsSql92DataTypeSyntax for JSON. Supports all superclasses of IsSql92DataTypeSyntax declared in beam-core.

Instances

Eq BeamSerializedDataType Source # 
Show BeamSerializedDataType Source # 
ToJSON BeamSerializedDataType Source # 
IsSql2003BinaryAndVarBinaryDataTypeSyntax BeamSerializedDataType Source # 
IsSql2008BigIntDataTypeSyntax BeamSerializedDataType Source # 
IsSql99DataTypeSyntax BeamSerializedDataType Source # 
IsSql92DataTypeSyntax BeamSerializedDataType Source # 

newtype BeamSerializedConstraintDefinition Source #

newtype BeamSerializedConstraint Source #

Instances

Eq BeamSerializedConstraint Source # 
Show BeamSerializedConstraint Source # 
IsSql92ColumnConstraintSyntax BeamSerializedConstraint Source # 
type Sql92ColumnConstraintMatchTypeSyntax BeamSerializedConstraint Source # 
type Sql92ColumnConstraintReferentialActionSyntax BeamSerializedConstraint Source # 
type Sql92ColumnConstraintExpressionSyntax BeamSerializedConstraint Source # 

newtype BeamSerializedExpression Source #

IsSql92ExpressionSyntax is too complex for us to store in JSON. Additionally, many backends provide substantial amounts of extensions to the syntax that would make storing this highly unfeasible. Expressions are therefore represented as their full text rendering.

This means that expressions only match as equal if they match exactly. While this may seem overly pedantic, it's not much of a concern if your migrations are generated solely by beam-migrate. If you've modified the schema yourself, you may have to use IsCustomSqlSyntax to provide an exact expression.

beamSerializeJSON :: Text -> Value -> Value Source #

Some backends serialize data that can only be read by that backend. If so, they should wrap these data in beamSerializeJSON, which provides a standard syntax for specifying backend specific data, as well as which backend the data are valid for.

The first argument is a string that is unique to a given backend

serializePrecAndDecimal :: Maybe (Word, Maybe Word) -> Value Source #

Helper for serializing the precision and decimal count parameters to decimalType, etc.

Deserialization helpers

Deserialization requires that knowledge of every type of data we can deserialize is stored in one place. While this is not much of an issue when compiling full Haskell applications, due to the type class mechanism, beam-migrate tools load backends dynamically. This means that we need a separate way to discover deserialization instances for types we care about.

Values of the BeamDeserializers type represent a set of deserializers all related to one kind of command syntax. You can ask for the deserializers to deserialize any type from an aeson Value. The deserialization will succeed only if a deserializer for the requested type exists and the deserializer was able to parse the Value.

BeamDeserializers compose monoidally. Thus, you can extend any BeamDeserializers with your own custom deserializers, by mappending it with a new BeamDeserializers, created by calling beamDeserializer.

newtype BeamDeserializers cmd Source #

Provides a collection of deserializers from aeson Values for arbitrary types. The cmd type parameter is a phantom type parameter. Notionally, all deserializers within this BeamDeserializers relate to the cmd syntax.

Constructors

BeamDeserializers 

Fields

beamDeserialize :: forall a cmd. Typeable a => BeamDeserializers cmd -> Value -> Parser a Source #

Deserialize the requested type from the given deserializers and aeson Value.

beamDeserializeMaybe :: Typeable a => BeamDeserializers cmd -> Maybe Value -> Parser (Maybe a) Source #

Helper function to deserialize data from a Maybe Value.

beamDeserializeMaybe _ Nothing = pure Nothing
beamDeserializeMaybe d (Just v) = Just $ beamDeserialize d v

beamDeserializer :: Typeable ty => (forall cmd'. BeamDeserializers cmd' -> Value -> Parser ty) -> BeamDeserializers cmd Source #

sql92Deserializers :: forall cmd. IsSql92DdlCommandSyntax cmd => BeamDeserializers cmd Source #

Deserializers for SQL92 syntaxes