{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{- You can't export a data family constructor, so there's an "unused" warning -}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}

module Database.Persist.Compatible.Types
    ( Compatible(..)
    ) where

import Data.Aeson
import Database.Persist.Class
import Database.Persist.Sql.Class
import Control.Monad.Trans.Reader (withReaderT)


-- | 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
newtype Compatible b s = Compatible { forall b s. Compatible b s -> s
unCompatible :: s }

instance (BackendCompatible b s, HasPersistBackend b) => HasPersistBackend (Compatible b s) where
    type BaseBackend (Compatible b s) = BaseBackend b
    persistBackend :: Compatible b s -> BaseBackend (Compatible b s)
persistBackend = forall backend.
HasPersistBackend backend =>
backend -> BaseBackend backend
persistBackend forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible

instance (BackendCompatible b s, PersistCore b) => PersistCore (Compatible b s) where
    -- | A newtype wrapper around @'BackendKey' b@, mainly useful for @DerivingVia@.
    --
    -- Similarly to @'Compatible' b s@, this data family instance is handy for deriving
    -- instances for @'BackendKey' s@ by defining them in terms of @'BackendKey' b@.
    --
    --
    -- For example, if you decide to augment the 'SqlBackend' with some additional
    -- features:
    --
    -- @
    -- data BetterSqlBackend = BetterSqlBackend { sqlBackend :: SqlBackend, ... }
    --
    -- instance PersistCore BetterSqlBackend where
    --   newtype BackendKey BetterSqlBackend = BSQLKey { unBSQLKey :: BackendKey (Compatible SqlBackend BetterSqlBackend) }
    -- @
    --
    -- Then you can use @DerivingVia@ to automatically get instances like:
    --
    -- @
    -- deriving via BackendKey (Compatible SqlBackend BetterSqlBackend) instance Show (BackendKey BetterSqlBackend)
    -- ...
    -- @
    --
    -- These instances will go through the compatible backend's key (in this case,
    -- @'BackendKey' 'SqlBackend'@) for all their logic.
    newtype BackendKey (Compatible b s) = CompatibleKey { forall b s. BackendKey (Compatible b s) -> BackendKey b
unCompatibleKey :: BackendKey b }

instance (HasPersistBackend b, BackendCompatible b s, PersistStoreRead b) => PersistStoreRead (Compatible b s) where
    get :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> ReaderT (Compatible b s) m (Maybe record)
get = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
get
    getMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Key record]
-> ReaderT (Compatible b s) m (Map (Key record) record)
getMany = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Key record] -> ReaderT backend m (Map (Key record) record)
getMany

instance (HasPersistBackend b, BackendCompatible b s, PersistQueryRead b) => PersistQueryRead (Compatible b s) where
    selectSourceRes :: forall record (m1 :: * -> *) (m2 :: * -> *).
(PersistRecordBackend record (Compatible b s), MonadIO m1,
 MonadIO m2) =>
[Filter record]
-> [SelectOpt record]
-> ReaderT
     (Compatible b s) m1 (Acquire (ConduitM () (Entity record) m2 ()))
selectSourceRes [Filter record]
filts [SelectOpt record]
opts = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall a b. (a -> b) -> a -> b
$ forall backend record (m1 :: * -> *) (m2 :: * -> *).
(PersistQueryRead backend, PersistRecordBackend record backend,
 MonadIO m1, MonadIO m2) =>
[Filter record]
-> [SelectOpt record]
-> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ()))
selectSourceRes [Filter record]
filts [SelectOpt record]
opts
    selectFirst :: forall (m :: * -> *) record.
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Filter record]
-> [SelectOpt record]
-> ReaderT (Compatible b s) m (Maybe (Entity record))
selectFirst [Filter record]
filts [SelectOpt record]
opts = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall a b. (a -> b) -> a -> b
$ forall backend (m :: * -> *) record.
(PersistQueryRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))
selectFirst [Filter record]
filts [SelectOpt record]
opts
    selectKeysRes :: forall (m1 :: * -> *) (m2 :: * -> *) record.
(MonadIO m1, MonadIO m2,
 PersistRecordBackend record (Compatible b s)) =>
[Filter record]
-> [SelectOpt record]
-> ReaderT
     (Compatible b s) m1 (Acquire (ConduitM () (Key record) m2 ()))
selectKeysRes [Filter record]
filts [SelectOpt record]
opts = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall a b. (a -> b) -> a -> b
$ forall backend (m1 :: * -> *) (m2 :: * -> *) record.
(PersistQueryRead backend, MonadIO m1, MonadIO m2,
 PersistRecordBackend record backend) =>
[Filter record]
-> [SelectOpt record]
-> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ()))
selectKeysRes [Filter record]
filts [SelectOpt record]
opts
    count :: forall (m :: * -> *) record.
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Filter record] -> ReaderT (Compatible b s) m Int
count = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend (m :: * -> *) record.
(PersistQueryRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m Int
count
    exists :: forall (m :: * -> *) record.
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Filter record] -> ReaderT (Compatible b s) m Bool
exists = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend (m :: * -> *) record.
(PersistQueryRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m Bool
exists

instance (HasPersistBackend b, BackendCompatible b s, PersistQueryWrite b) => PersistQueryWrite (Compatible b s) where
    updateWhere :: forall (m :: * -> *) record.
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Filter record] -> [Update record] -> ReaderT (Compatible b s) m ()
updateWhere [Filter record]
filts [Update record]
updates = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall a b. (a -> b) -> a -> b
$ forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> [Update record] -> ReaderT backend m ()
updateWhere [Filter record]
filts [Update record]
updates
    deleteWhere :: forall (m :: * -> *) record.
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Filter record] -> ReaderT (Compatible b s) m ()
deleteWhere = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend (m :: * -> *) record.
(PersistQueryWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Filter record] -> ReaderT backend m ()
deleteWhere

instance (HasPersistBackend b, BackendCompatible b s, PersistUniqueRead b) => PersistUniqueRead (Compatible b s) where
    getBy :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Unique record -> ReaderT (Compatible b s) m (Maybe (Entity record))
getBy = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueRead backend, MonadIO m,
 PersistRecordBackend record backend) =>
Unique record -> ReaderT backend m (Maybe (Entity record))
getBy

instance (HasPersistBackend b, BackendCompatible b s, PersistStoreWrite b) => PersistStoreWrite (Compatible b s) where
    insert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
record -> ReaderT (Compatible b s) m (Key record)
insert = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
insert
    insert_ :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
record -> ReaderT (Compatible b s) m ()
insert_ = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m ()
insert_
    insertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
[record] -> ReaderT (Compatible b s) m [Key record]
insertMany = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
[record] -> ReaderT backend m [Key record]
insertMany
    insertMany_ :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
[record] -> ReaderT (Compatible b s) m ()
insertMany_ = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
[record] -> ReaderT backend m ()
insertMany_
    insertEntityMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[Entity record] -> ReaderT (Compatible b s) m ()
insertEntityMany = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[Entity record] -> ReaderT backend m ()
insertEntityMany
    insertKey :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> record -> ReaderT (Compatible b s) m ()
insertKey Key record
k = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
insertKey Key record
k
    repsert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> record -> ReaderT (Compatible b s) m ()
repsert Key record
k = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
repsert Key record
k
    repsertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
[(Key record, record)] -> ReaderT (Compatible b s) m ()
repsertMany = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
[(Key record, record)] -> ReaderT backend m ()
repsertMany
    replace :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> record -> ReaderT (Compatible b s) m ()
replace Key record
k = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
replace Key record
k
    delete :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> ReaderT (Compatible b s) m ()
delete = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
delete
    update :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> [Update record] -> ReaderT (Compatible b s) m ()
update Key record
k = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> [Update record] -> ReaderT backend m ()
update Key record
k
    updateGet :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Key record -> [Update record] -> ReaderT (Compatible b s) m record
updateGet Key record
k = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Key record -> [Update record] -> ReaderT backend m record
updateGet Key record
k

instance (HasPersistBackend b, BackendCompatible b s, PersistUniqueWrite b) => PersistUniqueWrite (Compatible b s) where
    deleteBy :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s)) =>
Unique record -> ReaderT (Compatible b s) m ()
deleteBy = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueWrite backend, MonadIO m,
 PersistRecordBackend record backend) =>
Unique record -> ReaderT backend m ()
deleteBy
    insertUnique :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
record -> ReaderT (Compatible b s) m (Maybe (Key record))
insertUnique = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Maybe (Key record))
insertUnique
    upsert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 OnlyOneUniqueKey record, SafeToInsert record) =>
record
-> [Update record] -> ReaderT (Compatible b s) m (Entity record)
upsert record
rec = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueWrite backend, MonadIO m,
 PersistRecordBackend record backend, OnlyOneUniqueKey record,
 SafeToInsert record) =>
record -> [Update record] -> ReaderT backend m (Entity record)
upsert record
rec
    upsertBy :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
Unique record
-> record
-> [Update record]
-> ReaderT (Compatible b s) m (Entity record)
upsertBy Unique record
uniq record
rec = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
Unique record
-> record -> [Update record] -> ReaderT backend m (Entity record)
upsertBy Unique record
uniq record
rec
    putMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record (Compatible b s),
 SafeToInsert record) =>
[record] -> ReaderT (Compatible b s) m ()
putMany = forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend @b @s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b s. Compatible b s -> s
unCompatible) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall backend record (m :: * -> *).
(PersistUniqueWrite backend, MonadIO m,
 PersistRecordBackend record backend, SafeToInsert record) =>
[record] -> ReaderT backend m ()
putMany

deriving via (BackendKey b) instance (BackendCompatible b s, Show (BackendKey b)) => Show (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Read (BackendKey b)) => Read (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Eq (BackendKey b)) => Eq (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Ord (BackendKey b)) => Ord (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Num (BackendKey b)) => Num (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Integral (BackendKey b)) => Integral (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, PersistField (BackendKey b)) => PersistField (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, PersistFieldSql (BackendKey b)) => PersistFieldSql (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Real (BackendKey b)) => Real (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Enum (BackendKey b)) => Enum (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, Bounded (BackendKey b)) => Bounded (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, ToJSON (BackendKey b)) => ToJSON (BackendKey (Compatible b s))
deriving via (BackendKey b) instance (BackendCompatible b s, FromJSON (BackendKey b)) => FromJSON (BackendKey (Compatible b s))