Safe Haskell | None |
---|---|
Language | Haskell2010 |
Serialization and deserialization helpers for beam data types.
Used to read and write machine-readable schema descriptions.
Synopsis
- 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 be = BeamDeserializers {
- beamArbitraryDeserializers :: DMap BeamDeserializerLabel BeamDeserializer
- beamDeserialize :: forall a be. Typeable a => BeamDeserializers be -> Value -> Parser a
- beamDeserializeMaybe :: Typeable a => BeamDeserializers be -> Maybe Value -> Parser (Maybe a)
- beamDeserializer :: Typeable ty => (forall be'. BeamDeserializers be' -> Value -> Parser ty) -> BeamDeserializers be
- sql92Deserializers :: forall be. BeamMigrateSqlBackend be => BeamDeserializers be
- sql99DataTypeDeserializers :: forall be. BeamMigrateSql99Backend be => BeamDeserializers be
- sql2003BinaryAndVarBinaryDataTypeDeserializers :: forall be. (BeamMigrateSqlBackend be, BeamSqlT021Backend be) => BeamDeserializers be
- sql2008BigIntDataTypeDeserializers :: forall be. (BeamMigrateSqlBackend be, BeamSqlT071Backend be) => BeamDeserializers be
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
newtype BeamSerializedConstraintDefinition Source #
IsSql92ColumnConstraintDefinitionSyntax
type for JSON
Instances
newtype BeamSerializedConstraintAttributes Source #
IsSql92ConstraintAttributesSyntax
type for JSON
Instances
newtype BeamSerializedConstraint Source #
IsSql92ColumnConstraintSyntax
type for JSON
Instances
newtype BeamSerializedMatchType Source #
IsSql92MatchTypeSyntax
type for JSON
Instances
newtype BeamSerializedReferentialAction Source #
IsSql92ReferentialActionSyntax
type for JSON
Instances
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.
Instances
Eq BeamSerializedExpression Source # | |
Defined in Database.Beam.Migrate.Serialization | |
Show BeamSerializedExpression Source # | |
Defined in Database.Beam.Migrate.Serialization showsPrec :: Int -> BeamSerializedExpression -> ShowS # show :: BeamSerializedExpression -> String # showList :: [BeamSerializedExpression] -> ShowS # |
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 be 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 | |
|
Instances
Semigroup (BeamDeserializers be) Source # | |
Defined in Database.Beam.Migrate.Serialization (<>) :: BeamDeserializers be -> BeamDeserializers be -> BeamDeserializers be # sconcat :: NonEmpty (BeamDeserializers be) -> BeamDeserializers be # stimes :: Integral b => b -> BeamDeserializers be -> BeamDeserializers be # | |
Monoid (BeamDeserializers be) Source # | |
Defined in Database.Beam.Migrate.Serialization mempty :: BeamDeserializers be # mappend :: BeamDeserializers be -> BeamDeserializers be -> BeamDeserializers be # mconcat :: [BeamDeserializers be] -> BeamDeserializers be # |
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 #
beamDeserializer :: Typeable ty => (forall be'. BeamDeserializers be' -> Value -> Parser ty) -> BeamDeserializers be Source #
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
sql2003BinaryAndVarBinaryDataTypeDeserializers :: forall be. (BeamMigrateSqlBackend be, BeamSqlT021Backend be) => BeamDeserializers be Source #
Deserialize data types that are instances of IsSql2003BinaryAndVarBinaryDataTypeSyntax
sql2008BigIntDataTypeDeserializers :: forall be. (BeamMigrateSqlBackend be, BeamSqlT071Backend be) => BeamDeserializers be Source #
Deserialize data types that are instance of IsSql2008BigIntDataTypeSyntax