Database.Persist.Compatible

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

Safe Haskell | None
Language | Haskell2010

Database.Persist.Compatible

Synopsis

- newtype Compatible b s = Compatible {
  - unCompatible :: s
  }
- makeCompatibleInstances :: Q Type -> Q [Dec]
- makeCompatibleKeyInstances :: Q Type -> Q [Dec]

# Documentation

newtype 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

Since: 2.12

Constructors

Compatible |
Fields unCompatible :: s

#### Instances

Instances details

(BackendCompatible b s, FromJSON (BackendKey b)) => FromJSON (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods parseJSON :: Value -> Parser (BackendKey (Compatible b s)) # parseJSONList :: Value -> Parser [BackendKey (Compatible b s)] # omittedField :: Maybe (BackendKey (Compatible b s)) #
(BackendCompatible b s, ToJSON (BackendKey b)) => ToJSON (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods toJSON :: BackendKey (Compatible b s) -> Value # toEncoding :: BackendKey (Compatible b s) -> Encoding # toJSONList :: [BackendKey (Compatible b s)] -> Value # toEncodingList :: [BackendKey (Compatible b s)] -> Encoding # omitField :: BackendKey (Compatible b s) -> Bool #
(BackendCompatible b s, Bounded (BackendKey b)) => Bounded (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods minBound :: BackendKey (Compatible b s) # maxBound :: BackendKey (Compatible b s) #
(BackendCompatible b s, Enum (BackendKey b)) => Enum (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods succ :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) # pred :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) # toEnum :: Int -> BackendKey (Compatible b s) # fromEnum :: BackendKey (Compatible b s) -> Int # enumFrom :: BackendKey (Compatible b s) -> [BackendKey (Compatible b s)] # enumFromThen :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> [BackendKey (Compatible b s)] # enumFromTo :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> [BackendKey (Compatible b s)] # enumFromThenTo :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> [BackendKey (Compatible b s)] #
(BackendCompatible b s, Num (BackendKey b)) => Num (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods (+) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # (-) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # (*) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # negate :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) # abs :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) # signum :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) # fromInteger :: Integer -> BackendKey (Compatible b s) #
(BackendCompatible b s, Read (BackendKey b)) => Read (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods readsPrec :: Int -> ReadS (BackendKey (Compatible b s)) # readList :: ReadS [BackendKey (Compatible b s)] # readPrec :: ReadPrec (BackendKey (Compatible b s)) # readListPrec :: ReadPrec [BackendKey (Compatible b s)] #
(BackendCompatible b s, Integral (BackendKey b)) => Integral (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods quot :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # rem :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # div :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # mod :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # quotRem :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> (BackendKey (Compatible b s), BackendKey (Compatible b s)) # divMod :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> (BackendKey (Compatible b s), BackendKey (Compatible b s)) # toInteger :: BackendKey (Compatible b s) -> Integer #
(BackendCompatible b s, Real (BackendKey b)) => Real (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods toRational :: BackendKey (Compatible b s) -> Rational #
(BackendCompatible b s, Show (BackendKey b)) => Show (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods showsPrec :: Int -> BackendKey (Compatible b s) -> ShowS # show :: BackendKey (Compatible b s) -> String # showList :: [BackendKey (Compatible b s)] -> ShowS #
(BackendCompatible b s, Eq (BackendKey b)) => Eq (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods (==) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool # (/=) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool #
(BackendCompatible b s, Ord (BackendKey b)) => Ord (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods compare :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Ordering # (<) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool # (<=) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool # (>) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool # (>=) :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> Bool # max :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) # min :: BackendKey (Compatible b s) -> BackendKey (Compatible b s) -> BackendKey (Compatible b s) #
(BackendCompatible b s, PersistField (BackendKey b)) => PersistField (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods toPersistValue :: BackendKey (Compatible b s) -> PersistValue # fromPersistValue :: PersistValue -> Either Text (BackendKey (Compatible b s)) #
(BackendCompatible b s, PersistFieldSql (BackendKey b)) => PersistFieldSql (BackendKey (Compatible b s)) # |
Instance details Defined in Database.Persist.Compatible.Types Methods sqlType :: Proxy (BackendKey (Compatible b s)) -> SqlType #
(HasPersistBackend b, BackendCompatible b s, PersistQueryRead b) => PersistQueryRead (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistRecordBackend record (Compatible b s), MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT (Compatible b s) m1 (Acquire (ConduitM () (Entity record) m2 ())) # selectFirst :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Filter record] -> [SelectOpt record] -> ReaderT (Compatible b s) m (Maybe (Entity record)) # selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (MonadIO m1, MonadIO m2, PersistRecordBackend record (Compatible b s)) => [Filter record] -> [SelectOpt record] -> ReaderT (Compatible b s) m1 (Acquire (ConduitM () (Key record) m2 ())) # count :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Filter record] -> ReaderT (Compatible b s) m Int # exists :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Filter record] -> ReaderT (Compatible b s) m Bool #
(HasPersistBackend b, BackendCompatible b s, PersistQueryWrite b) => PersistQueryWrite (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods updateWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Filter record] -> [Update record] -> ReaderT (Compatible b s) m () # deleteWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Filter record] -> ReaderT (Compatible b s) m () #
(BackendCompatible b s, HasPersistBackend b) => HasPersistBackend (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Associated Types
type BaseBackend (Compatible b s) |
Instance details Defined in Database.Persist.Compatible.Types type BaseBackend (Compatible b s) = BaseBackend b
Methods persistBackend :: Compatible b s -> BaseBackend (Compatible b s) #
(BackendCompatible b s, PersistCore b) => PersistCore (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Associated Types
newtype BackendKey (Compatible b s) |
Instance details Defined in Database.Persist.Compatible.Types newtype BackendKey (Compatible b s) = CompatibleKey { unCompatibleKey :: BackendKey b }
(HasPersistBackend b, BackendCompatible b s, PersistStoreRead b) => PersistStoreRead (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods get :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> ReaderT (Compatible b s) m (Maybe record) # getMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Key record] -> ReaderT (Compatible b s) m (Map (Key record) record) #
(HasPersistBackend b, BackendCompatible b s, PersistStoreWrite b) => PersistStoreWrite (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods insert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => record -> ReaderT (Compatible b s) m (Key record) # insert_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => record -> ReaderT (Compatible b s) m () # insertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => [record] -> ReaderT (Compatible b s) m [Key record] # insertMany_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => [record] -> ReaderT (Compatible b s) m () # insertEntityMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => [Entity record] -> ReaderT (Compatible b s) m () # insertKey :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> record -> ReaderT (Compatible b s) m () # repsert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> record -> ReaderT (Compatible b s) m () # repsertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => [(Key record, record)] -> ReaderT (Compatible b s) m () # replace :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> record -> ReaderT (Compatible b s) m () # delete :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> ReaderT (Compatible b s) m () # update :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> [Update record] -> ReaderT (Compatible b s) m () # updateGet :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Key record -> [Update record] -> ReaderT (Compatible b s) m record #
(HasPersistBackend b, BackendCompatible b s, PersistUniqueRead b) => PersistUniqueRead (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods getBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Unique record -> ReaderT (Compatible b s) m (Maybe (Entity record)) # existsBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Unique record -> ReaderT (Compatible b s) m Bool #
(HasPersistBackend b, BackendCompatible b s, PersistUniqueWrite b) => PersistUniqueWrite (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types Methods deleteBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s)) => Unique record -> ReaderT (Compatible b s) m () # insertUnique :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => record -> ReaderT (Compatible b s) m (Maybe (Key record)) # insertUnique_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => record -> ReaderT (Compatible b s) m (Maybe ()) # upsert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), OnlyOneUniqueKey record, SafeToInsert record) => record -> [Update record] -> ReaderT (Compatible b s) m (Entity record) # upsertBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => Unique record -> record -> [Update record] -> ReaderT (Compatible b s) m (Entity record) # putMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record (Compatible b s), SafeToInsert record) => [record] -> ReaderT (Compatible b s) m () #
newtype BackendKey (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types newtype BackendKey (Compatible b s) = CompatibleKey { unCompatibleKey :: BackendKey b }
type BaseBackend (Compatible b s) # |
Instance details Defined in Database.Persist.Compatible.Types type BaseBackend (Compatible b s) = BaseBackend b

makeCompatibleInstances :: 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`.

Since: 2.12

makeCompatibleKeyInstances :: Q Type -> Q [Dec] #

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