Safe Haskell | None |
---|---|
Language | Haskell2010 |
Serialization and deserialization helpers for beam data types.
Used to read and write machine-readable schema descriptions.
- newtype BeamSerializedDataType = BeamSerializedDataType {}
- newtype BeamSerializedConstraintDefinition = BeamSerializedConstraintDefinition {}
- newtype BeamSerializedConstraintAttributes = BeamSerializedConstraintAttributes {}
- newtype BeamSerializedConstraint = BeamSerializedConstraint {}
- newtype BeamSerializedMatchType = BeamSerializedMatchType {}
- newtype BeamSerializedReferentialAction = BeamSerializedReferentialAction {}
- newtype BeamSerializedExpression = BeamSerializedExpression {}
- beamSerializeJSON :: Text -> Value -> Value
- serializePrecAndDecimal :: Maybe (Word, Maybe Word) -> Value
- newtype BeamDeserializers cmd = BeamDeserializers {
- beamArbitraryDeserializers :: DMap BeamDeserializerLabel BeamDeserializer
- beamDeserialize :: forall a cmd. Typeable a => BeamDeserializers cmd -> Value -> Parser a
- beamDeserializeMaybe :: Typeable a => BeamDeserializers cmd -> Maybe Value -> Parser (Maybe a)
- beamDeserializer :: Typeable ty => (forall cmd'. BeamDeserializers cmd' -> Value -> Parser ty) -> BeamDeserializers cmd
- sql92Deserializers :: forall cmd. IsSql92DdlCommandSyntax cmd => BeamDeserializers cmd
- sql99DataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql99DataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd
- sql2003BinaryAndVarBinaryDataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql2003BinaryAndVarBinaryDataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd
- sql2008BigIntDataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql2008BigIntDataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd
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
.
newtype BeamSerializedConstraintDefinition Source #
IsSql92ColumnConstraintDefinitionSyntax
type for JSON
newtype BeamSerializedConstraintAttributes Source #
IsSql92ConstraintAttributesSyntax
type for JSON
newtype BeamSerializedConstraint Source #
IsSql92ColumnConstraintSyntax
type for JSON
newtype BeamSerializedMatchType Source #
IsSql92MatchTypeSyntax
type for JSON
newtype BeamSerializedReferentialAction Source #
IsSql92ReferentialActionSyntax
type for JSON
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 mappend
ing it
with a new BeamDeserializers
, created by calling beamDeserializer
.
newtype BeamDeserializers cmd Source #
Provides a collection of deserializers from aeson Value
s for arbitrary
types. The cmd
type parameter is a phantom type parameter. Notionally, all
deserializers within this BeamDeserializers
relate to the cmd
syntax.
BeamDeserializers | |
|
Monoid (BeamDeserializers cmd) Source # | |
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 #
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
sql99DataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql99DataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd Source #
Deserializes data types that are instances of IsSql99DataTypeSyntax
sql2003BinaryAndVarBinaryDataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql2003BinaryAndVarBinaryDataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd Source #
Deserialize data types that are instances of IsSql2003BinaryAndVarBinaryDataTypeSyntax
sql2008BigIntDataTypeDeserializers :: forall cmd. (IsSql92DdlCommandSyntax cmd, IsSql2008BigIntDataTypeSyntax (Sql92DdlCommandDataTypeSyntax cmd)) => BeamDeserializers cmd Source #
Deserialize data types that are instance of IsSql2008BigIntDataTypeSyntax