HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepersistent-2.14.6.3Haskell2010

Database.Persist.Compatible

  • 1 type
  • 2 values
newtypenewtype Compatible b s
#

A newtype wrapper for compatible backends, mainly useful for DerivingVia.

When writing a new backend that is BackendCompatible with an existing backend, instances for the new backend can be naturally defined in terms of the instances for the existing backend.

For example, if you decide to augment the SqlBackend with some additional features:

data BetterSqlBackend = BetterSqlBackend { sqlBackend :: SqlBackend, ... }

instance BackendCompatible SqlBackend BetterSqlBackend where
  projectBackend = sqlBackend

Then you can use DerivingVia to automatically get instances like:

deriving via (Compatible SqlBackend BetterSqlBackend) instance PersistStoreRead BetterSqlBackend
deriving via (Compatible SqlBackend BetterSqlBackend) instance PersistStoreWrite BetterSqlBackend
...

These instances will go through the compatible backend (in this case, SqlBackend) for all their queries.

These instances require that both backends have the same BaseBackend, but deriving HasPersistBackend will enforce that for you.

deriving via (Compatible SqlBackend BetterSqlBackend) instance HasPersistBackend BetterSqlBackend

Constructors

Instances23Bounded, Enum, Eq, Integral, Num, Ord, …
valuemakeCompatibleInstances :: Q Type -> Q [Dec]
#

Gives a bunch of useful instance declarations for a backend based on its compatibility with another backend, using Compatible.

The argument should be a type of the form forall v1 ... vn. Compatible b s (Quantification is optional, but supported because TH won't let you have unbound type variables in a type splice). The instance is produced for s based on the instance defined for b, which is constrained in the instance head to exist.

v1 ... vn are implicitly quantified in the instance, which is derived via Compatible b s.

Gives a bunch of useful instance declarations for a backend key based on its compatibility with another backend & key, using Compatible.

The argument should be a type of the form forall v1 ... vn. Compatible b s (Quantification is optional, but supported because TH won't let you have unbound type variables in a type splice). The instance is produced for BackendKey s based on the instance defined for BackendKey b, which is constrained in the instance head to exist.

v1 ... vn are implicitly quantified in the instance, which is derived via BackendKey (Compatible b s).