persistent-2.12.1.0: Type-safe, multi-backend data serialization.

Database.Persist.Compatible

Synopsis

# Documentation

newtype Compatible b s Source #

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


Since: 2.12

Constructors

 Compatible FieldsunCompatible :: s

#### Instances

Instances details

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.

Since: 2.12

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).

Since: 2.12