Safe Haskell | None |
---|---|
Language | Haskell2010 |
Definitions of interest to those implement a new beam backend.
Steps to defining a beam backend:
- Ensure the command syntax for your backend satisfies
Sql92SaneDdlCommandSyntax
. - Create a value of type
BeamMigrationBackend
- For compatibility with
beam-migrate-cli
, export this value in an exposed module with the namemigrationBackend
.
This may sound trivial, but it's a bit more involved. In particular, in order
to complete step 2, you will have to define several instances for some of
your syntax pieces (for example, data types and constraints will need to be
Hashable
). You will also need to provide a reasonable function to fetch
predicates from your database, and a function to convert all these predicates
to corresponding predicates in the Haskell syntax. If you have custom data
types or predicates, you will need to supply BeamDeserializers
to
deserialize them from JSON. Finally, if your backend has custom
DatabasePredicate
s you will have to provide appropriate ActionProvider
s
to discover potential actions for your backend. See the documentation for
Database.Beam.Migrate.Actions for more information.
Tools may be interested in the SomeBeamMigrationBackend
data type which
provides a monomorphic type to wrap the polymorphic BeamMigrationBackend
type. Currently, beam-migrate-cli
uses this type to get the underlying
BeamMigrationBackend
via the hint
package.
For an example migrate backend, see Database.Beam.Sqlite.Migrate
Synopsis
- data BeamMigrationBackend commandSyntax be hdl m where
- BeamMigrationBackend :: (MonadBeam commandSyntax be hdl m, Typeable be, HasQBuilder (Sql92SelectSyntax commandSyntax), HasSqlValueSyntax (Sql92ValueSyntax commandSyntax) LocalTime, HasSqlValueSyntax (Sql92ValueSyntax commandSyntax) (Maybe LocalTime), HasSqlValueSyntax (Sql92ValueSyntax commandSyntax) Text, HasSqlValueSyntax (Sql92ValueSyntax commandSyntax) SqlNull, IsSql92Syntax commandSyntax, Sql92SanityCheck commandSyntax, Sql92SaneDdlCommandSyntax commandSyntax, Sql92SerializableDataTypeSyntax (Sql92DdlCommandDataTypeSyntax commandSyntax), Sql92ReasonableMarshaller be) => {..} -> BeamMigrationBackend commandSyntax be hdl m
- type DdlError = String
- newtype HaskellPredicateConverter = HaskellPredicateConverter (SomeDatabasePredicate -> Maybe SomeDatabasePredicate)
- sql92HsPredicateConverters :: forall columnSchemaSyntax. Typeable columnSchemaSyntax => (Sql92ColumnSchemaColumnTypeSyntax columnSchemaSyntax -> Maybe HsDataType) -> HaskellPredicateConverter
- hasColumnConverter :: forall columnSchemaSyntax. Typeable columnSchemaSyntax => (Sql92ColumnSchemaColumnTypeSyntax columnSchemaSyntax -> Maybe HsDataType) -> HaskellPredicateConverter
- trivialHsConverter :: forall pred. Typeable pred => HaskellPredicateConverter
- hsPredicateConverter :: Typeable pred => (pred -> Maybe SomeDatabasePredicate) -> HaskellPredicateConverter
- data SomeBeamMigrationBackend where
- SomeBeamMigrationBackend :: (Typeable commandSyntax, IsSql92DdlCommandSyntax commandSyntax, IsSql92Syntax commandSyntax, Sql92SanityCheck commandSyntax) => BeamMigrationBackend commandSyntax be hdl m -> SomeBeamMigrationBackend
Documentation
data BeamMigrationBackend commandSyntax be hdl m where Source #
Backends should create a value of this type and export it in an exposed
module under the name migrationBackend
. See the module documentation for
more details.
type DdlError = String Source #
Type of errors that can be thrown by backends during DDL statement
execution. Currently just a synonym for String
Haskell predicate conversion
newtype HaskellPredicateConverter Source #
In order to support Haskell schema generation, backends need to provide a
way to convert arbitrary DatabasePredicate
s generated by the backend's
backendGetDbConstraints
function into appropriate predicates in the Haskell
syntax. Not all predicates have any meaning when translated to Haskell, so
backends can choose to drop any predicate (simply return Nothing
).
Instances
Semigroup HaskellPredicateConverter Source # | |
Monoid HaskellPredicateConverter Source # |
|
sql92HsPredicateConverters :: forall columnSchemaSyntax. Typeable columnSchemaSyntax => (Sql92ColumnSchemaColumnTypeSyntax columnSchemaSyntax -> Maybe HsDataType) -> HaskellPredicateConverter Source #
Converters for the TableExistsPredicate
, TableHasPrimaryKey
, and
TableHasColumn
(when supplied with a function to convert a backend data
type to a haskell one).
hasColumnConverter :: forall columnSchemaSyntax. Typeable columnSchemaSyntax => (Sql92ColumnSchemaColumnTypeSyntax columnSchemaSyntax -> Maybe HsDataType) -> HaskellPredicateConverter Source #
Converter for TableHasColumn
, when given a function to convert backend
data type to a haskell one.
trivialHsConverter :: forall pred. Typeable pred => HaskellPredicateConverter Source #
Some predicates have no dependence on a backend. For example, TableExistsPredicate
has no parameters that
depend on the backend. It can be converted straightforwardly:
trivialHsConverter @TableExistsPredicate
hsPredicateConverter :: Typeable pred => (pred -> Maybe SomeDatabasePredicate) -> HaskellPredicateConverter Source #
Utility function for converting a monomorphically typed predicate to a haskell one.
For tooling authors
data SomeBeamMigrationBackend where Source #
Monomorphic wrapper for use with plugin loaders that cannot handle polymorphism
SomeBeamMigrationBackend :: (Typeable commandSyntax, IsSql92DdlCommandSyntax commandSyntax, IsSql92Syntax commandSyntax, Sql92SanityCheck commandSyntax) => BeamMigrationBackend commandSyntax be hdl m -> SomeBeamMigrationBackend |