beam-migrate-0.5.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 # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Show BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

ToJSON BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql2003BinaryAndVarBinaryDataTypeSyntax BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql2008BigIntDataTypeSyntax BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql99DataTypeSyntax BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql92DataTypeSyntax BeamSerializedDataType Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

newtype BeamSerializedConstraintDefinition Source #

Instances
Eq BeamSerializedConstraintDefinition Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Show BeamSerializedConstraintDefinition Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql92ColumnConstraintDefinitionSyntax BeamSerializedConstraintDefinition Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

type Sql92ColumnConstraintDefinitionConstraintSyntax BeamSerializedConstraintDefinition Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

type Sql92ColumnConstraintDefinitionAttributesSyntax BeamSerializedConstraintDefinition Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

newtype BeamSerializedConstraintAttributes Source #

Instances
Eq BeamSerializedConstraintAttributes Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Show BeamSerializedConstraintAttributes Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Semigroup BeamSerializedConstraintAttributes Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Monoid BeamSerializedConstraintAttributes Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql92ConstraintAttributesSyntax BeamSerializedConstraintAttributes Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

newtype BeamSerializedConstraint Source #

Instances
Eq BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

Show BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

IsSql92ColumnConstraintSyntax BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

type Sql92ColumnConstraintMatchTypeSyntax BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

type Sql92ColumnConstraintReferentialActionSyntax BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

type Sql92ColumnConstraintExpressionSyntax BeamSerializedConstraint Source # 
Instance details

Defined in Database.Beam.Migrate.Serialization

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 be 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 be. Typeable a => BeamDeserializers be -> Value -> Parser a Source #

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

beamDeserializeMaybe :: Typeable a => BeamDeserializers be -> 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

sql92Deserializers :: forall be. BeamMigrateSqlBackend be => BeamDeserializers be Source #

Deserializers for SQL92 syntaxes

sql99DataTypeDeserializers :: forall be. BeamMigrateSql99Backend be => BeamDeserializers be Source #

Deserializes data types that are instances of IsSql99DataTypeSyntax