{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Database.Persist.Sql.Orphan.PersistStore
( withRawQuery
, BackendKey(..)
, toSqlKey
, fromSqlKey
, getFieldName
, getTableName
, tableDBName
, fieldDBName
) where
import Control.Exception (throwIO)
import Control.Monad.IO.Class
import Control.Monad.Trans.Reader (ReaderT, ask)
import Data.Acquire (with)
import qualified Data.Aeson as A
import Data.ByteString.Char8 (readInteger)
import Data.Conduit (ConduitM, runConduit, (.|))
import qualified Data.Conduit.List as CL
import qualified Data.Foldable as Foldable
import Data.Function (on)
import Data.Int (Int64)
import Data.List (find, nubBy)
import qualified Data.Map as Map
import Data.Maybe (isJust)
import Data.Text (Text, unpack)
import qualified Data.Text as T
import Data.Void (Void)
import GHC.Generics (Generic)
import Web.HttpApiData (FromHttpApiData, ToHttpApiData)
import Web.PathPieces (PathPiece)
import Database.Persist
import Database.Persist.Class ()
import Database.Persist.Sql.Class (PersistFieldSql)
import Database.Persist.Sql.Raw
import Database.Persist.Sql.Types
import Database.Persist.Sql.Types.Internal
import Database.Persist.Sql.Util
( commaSeparated
, dbIdColumns
, keyAndEntityColumnNames
, mkInsertValues
, mkUpdateText
, parseEntityValues
, updatePersistValue
)
withRawQuery :: MonadIO m
=> Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery :: forall (m :: * -> *) a.
MonadIO m =>
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery Text
sql [PersistValue]
vals ConduitM [PersistValue] Void IO a
sink = do
Acquire (ConduitM () [PersistValue] IO ())
srcRes <- Text
-> [PersistValue]
-> ReaderT
SqlBackend m (Acquire (ConduitM () [PersistValue] IO ()))
forall (m1 :: * -> *) (m2 :: * -> *) env.
(MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) =>
Text
-> [PersistValue]
-> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ()))
rawQueryRes Text
sql [PersistValue]
vals
IO a -> ReaderT SqlBackend m a
forall a. IO a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> ReaderT SqlBackend m a) -> IO a -> ReaderT SqlBackend m a
forall a b. (a -> b) -> a -> b
$ Acquire (ConduitM () [PersistValue] IO ())
-> (ConduitM () [PersistValue] IO () -> IO a) -> IO a
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Acquire a -> (a -> m b) -> m b
with Acquire (ConduitM () [PersistValue] IO ())
srcRes (\ConduitM () [PersistValue] IO ()
src -> ConduitT () Void IO a -> IO a
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit (ConduitT () Void IO a -> IO a) -> ConduitT () Void IO a -> IO a
forall a b. (a -> b) -> a -> b
$ ConduitM () [PersistValue] IO ()
src ConduitM () [PersistValue] IO ()
-> ConduitM [PersistValue] Void IO a -> ConduitT () Void IO a
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| ConduitM [PersistValue] Void IO a
sink)
toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record
toSqlKey :: forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey = BackendKey SqlBackend -> Key record
forall backend record.
ToBackendKey backend record =>
BackendKey backend -> Key record
fromBackendKey (BackendKey SqlBackend -> Key record)
-> (Int64 -> BackendKey SqlBackend) -> Int64 -> Key record
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> BackendKey SqlBackend
SqlBackendKey
fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64
fromSqlKey :: forall record.
ToBackendKey SqlBackend record =>
Key record -> Int64
fromSqlKey = BackendKey SqlBackend -> Int64
unSqlBackendKey (BackendKey SqlBackend -> Int64)
-> (Key record -> BackendKey SqlBackend) -> Key record -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key record -> BackendKey SqlBackend
forall backend record.
ToBackendKey backend record =>
Key record -> BackendKey backend
toBackendKey
whereStmtForKey :: PersistEntity record => SqlBackend -> Key record -> Text
whereStmtForKey :: forall record.
PersistEntity record =>
SqlBackend -> Key record -> Text
whereStmtForKey SqlBackend
conn Key record
k =
Text -> [Text] -> Text
T.intercalate Text
" AND "
([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
(NonEmpty Text -> [Text]) -> NonEmpty Text -> [Text]
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> NonEmpty Text -> NonEmpty Text
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=? ")
(NonEmpty Text -> NonEmpty Text) -> NonEmpty Text -> NonEmpty Text
forall a b. (a -> b) -> a -> b
$ SqlBackend -> EntityDef -> NonEmpty Text
dbIdColumns SqlBackend
conn EntityDef
entDef
where
entDef :: EntityDef
entDef = Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ Key record -> Maybe record
forall record. Key record -> Maybe record
dummyFromKey Key record
k
whereStmtForKeys :: PersistEntity record => SqlBackend -> [Key record] -> Text
whereStmtForKeys :: forall record.
PersistEntity record =>
SqlBackend -> [Key record] -> Text
whereStmtForKeys SqlBackend
conn [Key record]
ks = Text -> [Text] -> Text
T.intercalate Text
" OR " ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ SqlBackend -> Key record -> Text
forall record.
PersistEntity record =>
SqlBackend -> Key record -> Text
whereStmtForKey SqlBackend
conn (Key record -> Text) -> [Key record] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` [Key record]
ks
getTableName :: forall record m backend.
( PersistEntity record
, BackendCompatible SqlBackend backend
, Monad m
) => record -> ReaderT backend m Text
getTableName :: forall record (m :: * -> *) backend.
(PersistEntity record, BackendCompatible SqlBackend backend,
Monad m) =>
record -> ReaderT backend m Text
getTableName record
rec = ReaderT SqlBackend m Text -> ReaderT backend m Text
forall sup sub (m :: * -> *) a.
BackendCompatible sup sub =>
ReaderT sup m a -> ReaderT sub m a
withCompatibleBackend (ReaderT SqlBackend m Text -> ReaderT backend m Text)
-> ReaderT SqlBackend m Text -> ReaderT backend m Text
forall a b. (a -> b) -> a -> b
$ do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
Text -> ReaderT SqlBackend m Text
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ReaderT SqlBackend m Text)
-> Text -> ReaderT SqlBackend m Text
forall a b. (a -> b) -> a -> b
$ SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn (Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ record -> Maybe record
forall a. a -> Maybe a
Just record
rec)
tableDBName :: (PersistEntity record) => record -> EntityNameDB
tableDBName :: forall record. PersistEntity record => record -> EntityNameDB
tableDBName record
rec = EntityDef -> EntityNameDB
getEntityDBName (EntityDef -> EntityNameDB) -> EntityDef -> EntityNameDB
forall a b. (a -> b) -> a -> b
$ Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (record -> Maybe record
forall a. a -> Maybe a
Just record
rec)
getFieldName :: forall record typ m backend.
( PersistEntity record
, PersistEntityBackend record ~ SqlBackend
, BackendCompatible SqlBackend backend
, Monad m
)
=> EntityField record typ -> ReaderT backend m Text
getFieldName :: forall record typ (m :: * -> *) backend.
(PersistEntity record, PersistEntityBackend record ~ SqlBackend,
BackendCompatible SqlBackend backend, Monad m) =>
EntityField record typ -> ReaderT backend m Text
getFieldName EntityField record typ
rec = ReaderT SqlBackend m Text -> ReaderT backend m Text
forall sup sub (m :: * -> *) a.
BackendCompatible sup sub =>
ReaderT sup m a -> ReaderT sub m a
withCompatibleBackend (ReaderT SqlBackend m Text -> ReaderT backend m Text)
-> ReaderT SqlBackend m Text -> ReaderT backend m Text
forall a b. (a -> b) -> a -> b
$ do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
Text -> ReaderT SqlBackend m Text
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ReaderT SqlBackend m Text)
-> Text -> ReaderT SqlBackend m Text
forall a b. (a -> b) -> a -> b
$ SqlBackend -> FieldNameDB -> Text
connEscapeFieldName SqlBackend
conn (FieldDef -> FieldNameDB
fieldDB (FieldDef -> FieldNameDB) -> FieldDef -> FieldNameDB
forall a b. (a -> b) -> a -> b
$ EntityField record typ -> FieldDef
forall record typ.
PersistEntity record =>
EntityField record typ -> FieldDef
forall typ. EntityField record typ -> FieldDef
persistFieldDef EntityField record typ
rec)
fieldDBName :: forall record typ. (PersistEntity record) => EntityField record typ -> FieldNameDB
fieldDBName :: forall record typ.
PersistEntity record =>
EntityField record typ -> FieldNameDB
fieldDBName = FieldDef -> FieldNameDB
fieldDB (FieldDef -> FieldNameDB)
-> (EntityField record typ -> FieldDef)
-> EntityField record typ
-> FieldNameDB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityField record typ -> FieldDef
forall record typ.
PersistEntity record =>
EntityField record typ -> FieldDef
forall typ. EntityField record typ -> FieldDef
persistFieldDef
instance PersistCore SqlBackend where
newtype BackendKey SqlBackend = SqlBackendKey { BackendKey SqlBackend -> Int64
unSqlBackendKey :: Int64 }
deriving stock (Int -> BackendKey SqlBackend -> ShowS
[BackendKey SqlBackend] -> ShowS
BackendKey SqlBackend -> String
(Int -> BackendKey SqlBackend -> ShowS)
-> (BackendKey SqlBackend -> String)
-> ([BackendKey SqlBackend] -> ShowS)
-> Show (BackendKey SqlBackend)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BackendKey SqlBackend -> ShowS
showsPrec :: Int -> BackendKey SqlBackend -> ShowS
$cshow :: BackendKey SqlBackend -> String
show :: BackendKey SqlBackend -> String
$cshowList :: [BackendKey SqlBackend] -> ShowS
showList :: [BackendKey SqlBackend] -> ShowS
Show, ReadPrec [BackendKey SqlBackend]
ReadPrec (BackendKey SqlBackend)
Int -> ReadS (BackendKey SqlBackend)
ReadS [BackendKey SqlBackend]
(Int -> ReadS (BackendKey SqlBackend))
-> ReadS [BackendKey SqlBackend]
-> ReadPrec (BackendKey SqlBackend)
-> ReadPrec [BackendKey SqlBackend]
-> Read (BackendKey SqlBackend)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS (BackendKey SqlBackend)
readsPrec :: Int -> ReadS (BackendKey SqlBackend)
$creadList :: ReadS [BackendKey SqlBackend]
readList :: ReadS [BackendKey SqlBackend]
$creadPrec :: ReadPrec (BackendKey SqlBackend)
readPrec :: ReadPrec (BackendKey SqlBackend)
$creadListPrec :: ReadPrec [BackendKey SqlBackend]
readListPrec :: ReadPrec [BackendKey SqlBackend]
Read, BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
(BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> (BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> Eq (BackendKey SqlBackend)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
== :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c/= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
/= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
Eq, Eq (BackendKey SqlBackend)
Eq (BackendKey SqlBackend) =>
(BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering)
-> (BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> (BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> (BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> (BackendKey SqlBackend -> BackendKey SqlBackend -> Bool)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> Ord (BackendKey SqlBackend)
BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering
BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering
compare :: BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering
$c< :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
< :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c<= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
<= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c> :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
> :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c>= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
>= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$cmax :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
max :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cmin :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
min :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
Ord, (forall x. BackendKey SqlBackend -> Rep (BackendKey SqlBackend) x)
-> (forall x.
Rep (BackendKey SqlBackend) x -> BackendKey SqlBackend)
-> Generic (BackendKey SqlBackend)
forall x. Rep (BackendKey SqlBackend) x -> BackendKey SqlBackend
forall x. BackendKey SqlBackend -> Rep (BackendKey SqlBackend) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BackendKey SqlBackend -> Rep (BackendKey SqlBackend) x
from :: forall x. BackendKey SqlBackend -> Rep (BackendKey SqlBackend) x
$cto :: forall x. Rep (BackendKey SqlBackend) x -> BackendKey SqlBackend
to :: forall x. Rep (BackendKey SqlBackend) x -> BackendKey SqlBackend
Generic)
deriving newtype (Integer -> BackendKey SqlBackend
BackendKey SqlBackend -> BackendKey SqlBackend
BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
(BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend -> BackendKey SqlBackend)
-> (Integer -> BackendKey SqlBackend)
-> Num (BackendKey SqlBackend)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
+ :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$c- :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
- :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$c* :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
* :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cnegate :: BackendKey SqlBackend -> BackendKey SqlBackend
negate :: BackendKey SqlBackend -> BackendKey SqlBackend
$cabs :: BackendKey SqlBackend -> BackendKey SqlBackend
abs :: BackendKey SqlBackend -> BackendKey SqlBackend
$csignum :: BackendKey SqlBackend -> BackendKey SqlBackend
signum :: BackendKey SqlBackend -> BackendKey SqlBackend
$cfromInteger :: Integer -> BackendKey SqlBackend
fromInteger :: Integer -> BackendKey SqlBackend
Num, Enum (BackendKey SqlBackend)
Real (BackendKey SqlBackend)
(Real (BackendKey SqlBackend), Enum (BackendKey SqlBackend)) =>
(BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend))
-> (BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend))
-> (BackendKey SqlBackend -> Integer)
-> Integral (BackendKey SqlBackend)
BackendKey SqlBackend -> Integer
BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
quot :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$crem :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
rem :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cdiv :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
div :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cmod :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
mod :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cquotRem :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
quotRem :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
$cdivMod :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
divMod :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
$ctoInteger :: BackendKey SqlBackend -> Integer
toInteger :: BackendKey SqlBackend -> Integer
Integral, PersistValue -> Either Text (BackendKey SqlBackend)
BackendKey SqlBackend -> PersistValue
(BackendKey SqlBackend -> PersistValue)
-> (PersistValue -> Either Text (BackendKey SqlBackend))
-> PersistField (BackendKey SqlBackend)
forall a.
(a -> PersistValue)
-> (PersistValue -> Either Text a) -> PersistField a
$ctoPersistValue :: BackendKey SqlBackend -> PersistValue
toPersistValue :: BackendKey SqlBackend -> PersistValue
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlBackend)
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlBackend)
PersistField, PersistField (BackendKey SqlBackend)
Proxy (BackendKey SqlBackend) -> SqlType
PersistField (BackendKey SqlBackend) =>
(Proxy (BackendKey SqlBackend) -> SqlType)
-> PersistFieldSql (BackendKey SqlBackend)
forall a.
PersistField a =>
(Proxy a -> SqlType) -> PersistFieldSql a
$csqlType :: Proxy (BackendKey SqlBackend) -> SqlType
sqlType :: Proxy (BackendKey SqlBackend) -> SqlType
PersistFieldSql, Text -> Maybe (BackendKey SqlBackend)
BackendKey SqlBackend -> Text
(Text -> Maybe (BackendKey SqlBackend))
-> (BackendKey SqlBackend -> Text)
-> PathPiece (BackendKey SqlBackend)
forall s. (Text -> Maybe s) -> (s -> Text) -> PathPiece s
$cfromPathPiece :: Text -> Maybe (BackendKey SqlBackend)
fromPathPiece :: Text -> Maybe (BackendKey SqlBackend)
$ctoPathPiece :: BackendKey SqlBackend -> Text
toPathPiece :: BackendKey SqlBackend -> Text
PathPiece, BackendKey SqlBackend -> Text
BackendKey SqlBackend -> ByteString
BackendKey SqlBackend -> Builder
(BackendKey SqlBackend -> Text)
-> (BackendKey SqlBackend -> Builder)
-> (BackendKey SqlBackend -> ByteString)
-> (BackendKey SqlBackend -> Text)
-> (BackendKey SqlBackend -> Builder)
-> ToHttpApiData (BackendKey SqlBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: BackendKey SqlBackend -> Text
toUrlPiece :: BackendKey SqlBackend -> Text
$ctoEncodedUrlPiece :: BackendKey SqlBackend -> Builder
toEncodedUrlPiece :: BackendKey SqlBackend -> Builder
$ctoHeader :: BackendKey SqlBackend -> ByteString
toHeader :: BackendKey SqlBackend -> ByteString
$ctoQueryParam :: BackendKey SqlBackend -> Text
toQueryParam :: BackendKey SqlBackend -> Text
$ctoEncodedQueryParam :: BackendKey SqlBackend -> Builder
toEncodedQueryParam :: BackendKey SqlBackend -> Builder
ToHttpApiData, Text -> Either Text (BackendKey SqlBackend)
ByteString -> Either Text (BackendKey SqlBackend)
(Text -> Either Text (BackendKey SqlBackend))
-> (ByteString -> Either Text (BackendKey SqlBackend))
-> (Text -> Either Text (BackendKey SqlBackend))
-> FromHttpApiData (BackendKey SqlBackend)
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text (BackendKey SqlBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlBackend)
parseQueryParam :: Text -> Either Text (BackendKey SqlBackend)
FromHttpApiData, Num (BackendKey SqlBackend)
Ord (BackendKey SqlBackend)
(Num (BackendKey SqlBackend), Ord (BackendKey SqlBackend)) =>
(BackendKey SqlBackend -> Rational) -> Real (BackendKey SqlBackend)
BackendKey SqlBackend -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: BackendKey SqlBackend -> Rational
toRational :: BackendKey SqlBackend -> Rational
Real, Int -> BackendKey SqlBackend
BackendKey SqlBackend -> Int
BackendKey SqlBackend -> [BackendKey SqlBackend]
BackendKey SqlBackend -> BackendKey SqlBackend
BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend]
(BackendKey SqlBackend -> BackendKey SqlBackend)
-> (BackendKey SqlBackend -> BackendKey SqlBackend)
-> (Int -> BackendKey SqlBackend)
-> (BackendKey SqlBackend -> Int)
-> (BackendKey SqlBackend -> [BackendKey SqlBackend])
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend])
-> (BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend])
-> (BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend])
-> Enum (BackendKey SqlBackend)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BackendKey SqlBackend -> BackendKey SqlBackend
succ :: BackendKey SqlBackend -> BackendKey SqlBackend
$cpred :: BackendKey SqlBackend -> BackendKey SqlBackend
pred :: BackendKey SqlBackend -> BackendKey SqlBackend
$ctoEnum :: Int -> BackendKey SqlBackend
toEnum :: Int -> BackendKey SqlBackend
$cfromEnum :: BackendKey SqlBackend -> Int
fromEnum :: BackendKey SqlBackend -> Int
$cenumFrom :: BackendKey SqlBackend -> [BackendKey SqlBackend]
enumFrom :: BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFromThen :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
enumFromThen :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFromTo :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
enumFromTo :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFromThenTo :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend]
enumFromThenTo :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend]
Enum, BackendKey SqlBackend
BackendKey SqlBackend
-> BackendKey SqlBackend -> Bounded (BackendKey SqlBackend)
forall a. a -> a -> Bounded a
$cminBound :: BackendKey SqlBackend
minBound :: BackendKey SqlBackend
$cmaxBound :: BackendKey SqlBackend
maxBound :: BackendKey SqlBackend
Bounded, [BackendKey SqlBackend] -> Value
[BackendKey SqlBackend] -> Encoding
BackendKey SqlBackend -> Bool
BackendKey SqlBackend -> Value
BackendKey SqlBackend -> Encoding
(BackendKey SqlBackend -> Value)
-> (BackendKey SqlBackend -> Encoding)
-> ([BackendKey SqlBackend] -> Value)
-> ([BackendKey SqlBackend] -> Encoding)
-> (BackendKey SqlBackend -> Bool)
-> ToJSON (BackendKey SqlBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: BackendKey SqlBackend -> Value
toJSON :: BackendKey SqlBackend -> Value
$ctoEncoding :: BackendKey SqlBackend -> Encoding
toEncoding :: BackendKey SqlBackend -> Encoding
$ctoJSONList :: [BackendKey SqlBackend] -> Value
toJSONList :: [BackendKey SqlBackend] -> Value
$ctoEncodingList :: [BackendKey SqlBackend] -> Encoding
toEncodingList :: [BackendKey SqlBackend] -> Encoding
$comitField :: BackendKey SqlBackend -> Bool
omitField :: BackendKey SqlBackend -> Bool
A.ToJSON, Maybe (BackendKey SqlBackend)
Value -> Parser [BackendKey SqlBackend]
Value -> Parser (BackendKey SqlBackend)
(Value -> Parser (BackendKey SqlBackend))
-> (Value -> Parser [BackendKey SqlBackend])
-> Maybe (BackendKey SqlBackend)
-> FromJSON (BackendKey SqlBackend)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser (BackendKey SqlBackend)
parseJSON :: Value -> Parser (BackendKey SqlBackend)
$cparseJSONList :: Value -> Parser [BackendKey SqlBackend]
parseJSONList :: Value -> Parser [BackendKey SqlBackend]
$comittedField :: Maybe (BackendKey SqlBackend)
omittedField :: Maybe (BackendKey SqlBackend)
A.FromJSON)
instance PersistCore SqlReadBackend where
newtype BackendKey SqlReadBackend = SqlReadBackendKey { BackendKey SqlReadBackend -> Int64
unSqlReadBackendKey :: Int64 }
deriving stock (Int -> BackendKey SqlReadBackend -> ShowS
[BackendKey SqlReadBackend] -> ShowS
BackendKey SqlReadBackend -> String
(Int -> BackendKey SqlReadBackend -> ShowS)
-> (BackendKey SqlReadBackend -> String)
-> ([BackendKey SqlReadBackend] -> ShowS)
-> Show (BackendKey SqlReadBackend)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BackendKey SqlReadBackend -> ShowS
showsPrec :: Int -> BackendKey SqlReadBackend -> ShowS
$cshow :: BackendKey SqlReadBackend -> String
show :: BackendKey SqlReadBackend -> String
$cshowList :: [BackendKey SqlReadBackend] -> ShowS
showList :: [BackendKey SqlReadBackend] -> ShowS
Show, ReadPrec [BackendKey SqlReadBackend]
ReadPrec (BackendKey SqlReadBackend)
Int -> ReadS (BackendKey SqlReadBackend)
ReadS [BackendKey SqlReadBackend]
(Int -> ReadS (BackendKey SqlReadBackend))
-> ReadS [BackendKey SqlReadBackend]
-> ReadPrec (BackendKey SqlReadBackend)
-> ReadPrec [BackendKey SqlReadBackend]
-> Read (BackendKey SqlReadBackend)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS (BackendKey SqlReadBackend)
readsPrec :: Int -> ReadS (BackendKey SqlReadBackend)
$creadList :: ReadS [BackendKey SqlReadBackend]
readList :: ReadS [BackendKey SqlReadBackend]
$creadPrec :: ReadPrec (BackendKey SqlReadBackend)
readPrec :: ReadPrec (BackendKey SqlReadBackend)
$creadListPrec :: ReadPrec [BackendKey SqlReadBackend]
readListPrec :: ReadPrec [BackendKey SqlReadBackend]
Read, BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
(BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> Eq (BackendKey SqlReadBackend)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
== :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c/= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
/= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
Eq, Eq (BackendKey SqlReadBackend)
Eq (BackendKey SqlReadBackend) =>
(BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> Ordering)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> Ord (BackendKey SqlReadBackend)
BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Ordering
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Ordering
compare :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Ordering
$c< :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
< :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c<= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
<= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c> :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
> :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c>= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
>= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$cmax :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
max :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cmin :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
min :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
Ord, (forall x.
BackendKey SqlReadBackend -> Rep (BackendKey SqlReadBackend) x)
-> (forall x.
Rep (BackendKey SqlReadBackend) x -> BackendKey SqlReadBackend)
-> Generic (BackendKey SqlReadBackend)
forall x.
Rep (BackendKey SqlReadBackend) x -> BackendKey SqlReadBackend
forall x.
BackendKey SqlReadBackend -> Rep (BackendKey SqlReadBackend) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
BackendKey SqlReadBackend -> Rep (BackendKey SqlReadBackend) x
from :: forall x.
BackendKey SqlReadBackend -> Rep (BackendKey SqlReadBackend) x
$cto :: forall x.
Rep (BackendKey SqlReadBackend) x -> BackendKey SqlReadBackend
to :: forall x.
Rep (BackendKey SqlReadBackend) x -> BackendKey SqlReadBackend
Generic)
deriving newtype (Integer -> BackendKey SqlReadBackend
BackendKey SqlReadBackend -> BackendKey SqlReadBackend
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
(BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (Integer -> BackendKey SqlReadBackend)
-> Num (BackendKey SqlReadBackend)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
+ :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$c- :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
- :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$c* :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
* :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cnegate :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
negate :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cabs :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
abs :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$csignum :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
signum :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cfromInteger :: Integer -> BackendKey SqlReadBackend
fromInteger :: Integer -> BackendKey SqlReadBackend
Num, Enum (BackendKey SqlReadBackend)
Real (BackendKey SqlReadBackend)
(Real (BackendKey SqlReadBackend),
Enum (BackendKey SqlReadBackend)) =>
(BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend))
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend))
-> (BackendKey SqlReadBackend -> Integer)
-> Integral (BackendKey SqlReadBackend)
BackendKey SqlReadBackend -> Integer
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
quot :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$crem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
rem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cdiv :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
div :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cmod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
mod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cquotRem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
quotRem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
$cdivMod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
divMod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
$ctoInteger :: BackendKey SqlReadBackend -> Integer
toInteger :: BackendKey SqlReadBackend -> Integer
Integral, PersistValue -> Either Text (BackendKey SqlReadBackend)
BackendKey SqlReadBackend -> PersistValue
(BackendKey SqlReadBackend -> PersistValue)
-> (PersistValue -> Either Text (BackendKey SqlReadBackend))
-> PersistField (BackendKey SqlReadBackend)
forall a.
(a -> PersistValue)
-> (PersistValue -> Either Text a) -> PersistField a
$ctoPersistValue :: BackendKey SqlReadBackend -> PersistValue
toPersistValue :: BackendKey SqlReadBackend -> PersistValue
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlReadBackend)
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlReadBackend)
PersistField, PersistField (BackendKey SqlReadBackend)
Proxy (BackendKey SqlReadBackend) -> SqlType
PersistField (BackendKey SqlReadBackend) =>
(Proxy (BackendKey SqlReadBackend) -> SqlType)
-> PersistFieldSql (BackendKey SqlReadBackend)
forall a.
PersistField a =>
(Proxy a -> SqlType) -> PersistFieldSql a
$csqlType :: Proxy (BackendKey SqlReadBackend) -> SqlType
sqlType :: Proxy (BackendKey SqlReadBackend) -> SqlType
PersistFieldSql, Text -> Maybe (BackendKey SqlReadBackend)
BackendKey SqlReadBackend -> Text
(Text -> Maybe (BackendKey SqlReadBackend))
-> (BackendKey SqlReadBackend -> Text)
-> PathPiece (BackendKey SqlReadBackend)
forall s. (Text -> Maybe s) -> (s -> Text) -> PathPiece s
$cfromPathPiece :: Text -> Maybe (BackendKey SqlReadBackend)
fromPathPiece :: Text -> Maybe (BackendKey SqlReadBackend)
$ctoPathPiece :: BackendKey SqlReadBackend -> Text
toPathPiece :: BackendKey SqlReadBackend -> Text
PathPiece, BackendKey SqlReadBackend -> Text
BackendKey SqlReadBackend -> ByteString
BackendKey SqlReadBackend -> Builder
(BackendKey SqlReadBackend -> Text)
-> (BackendKey SqlReadBackend -> Builder)
-> (BackendKey SqlReadBackend -> ByteString)
-> (BackendKey SqlReadBackend -> Text)
-> (BackendKey SqlReadBackend -> Builder)
-> ToHttpApiData (BackendKey SqlReadBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: BackendKey SqlReadBackend -> Text
toUrlPiece :: BackendKey SqlReadBackend -> Text
$ctoEncodedUrlPiece :: BackendKey SqlReadBackend -> Builder
toEncodedUrlPiece :: BackendKey SqlReadBackend -> Builder
$ctoHeader :: BackendKey SqlReadBackend -> ByteString
toHeader :: BackendKey SqlReadBackend -> ByteString
$ctoQueryParam :: BackendKey SqlReadBackend -> Text
toQueryParam :: BackendKey SqlReadBackend -> Text
$ctoEncodedQueryParam :: BackendKey SqlReadBackend -> Builder
toEncodedQueryParam :: BackendKey SqlReadBackend -> Builder
ToHttpApiData, Text -> Either Text (BackendKey SqlReadBackend)
ByteString -> Either Text (BackendKey SqlReadBackend)
(Text -> Either Text (BackendKey SqlReadBackend))
-> (ByteString -> Either Text (BackendKey SqlReadBackend))
-> (Text -> Either Text (BackendKey SqlReadBackend))
-> FromHttpApiData (BackendKey SqlReadBackend)
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text (BackendKey SqlReadBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlReadBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlReadBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlReadBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlReadBackend)
parseQueryParam :: Text -> Either Text (BackendKey SqlReadBackend)
FromHttpApiData, Num (BackendKey SqlReadBackend)
Ord (BackendKey SqlReadBackend)
(Num (BackendKey SqlReadBackend),
Ord (BackendKey SqlReadBackend)) =>
(BackendKey SqlReadBackend -> Rational)
-> Real (BackendKey SqlReadBackend)
BackendKey SqlReadBackend -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: BackendKey SqlReadBackend -> Rational
toRational :: BackendKey SqlReadBackend -> Rational
Real, Int -> BackendKey SqlReadBackend
BackendKey SqlReadBackend -> Int
BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
BackendKey SqlReadBackend -> BackendKey SqlReadBackend
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend]
(BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend -> BackendKey SqlReadBackend)
-> (Int -> BackendKey SqlReadBackend)
-> (BackendKey SqlReadBackend -> Int)
-> (BackendKey SqlReadBackend -> [BackendKey SqlReadBackend])
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend])
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend])
-> (BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend])
-> Enum (BackendKey SqlReadBackend)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
succ :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cpred :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
pred :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$ctoEnum :: Int -> BackendKey SqlReadBackend
toEnum :: Int -> BackendKey SqlReadBackend
$cfromEnum :: BackendKey SqlReadBackend -> Int
fromEnum :: BackendKey SqlReadBackend -> Int
$cenumFrom :: BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
enumFrom :: BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFromThen :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
enumFromThen :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFromTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
enumFromTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFromThenTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend]
enumFromThenTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend]
Enum, BackendKey SqlReadBackend
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> Bounded (BackendKey SqlReadBackend)
forall a. a -> a -> Bounded a
$cminBound :: BackendKey SqlReadBackend
minBound :: BackendKey SqlReadBackend
$cmaxBound :: BackendKey SqlReadBackend
maxBound :: BackendKey SqlReadBackend
Bounded, [BackendKey SqlReadBackend] -> Value
[BackendKey SqlReadBackend] -> Encoding
BackendKey SqlReadBackend -> Bool
BackendKey SqlReadBackend -> Value
BackendKey SqlReadBackend -> Encoding
(BackendKey SqlReadBackend -> Value)
-> (BackendKey SqlReadBackend -> Encoding)
-> ([BackendKey SqlReadBackend] -> Value)
-> ([BackendKey SqlReadBackend] -> Encoding)
-> (BackendKey SqlReadBackend -> Bool)
-> ToJSON (BackendKey SqlReadBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: BackendKey SqlReadBackend -> Value
toJSON :: BackendKey SqlReadBackend -> Value
$ctoEncoding :: BackendKey SqlReadBackend -> Encoding
toEncoding :: BackendKey SqlReadBackend -> Encoding
$ctoJSONList :: [BackendKey SqlReadBackend] -> Value
toJSONList :: [BackendKey SqlReadBackend] -> Value
$ctoEncodingList :: [BackendKey SqlReadBackend] -> Encoding
toEncodingList :: [BackendKey SqlReadBackend] -> Encoding
$comitField :: BackendKey SqlReadBackend -> Bool
omitField :: BackendKey SqlReadBackend -> Bool
A.ToJSON, Maybe (BackendKey SqlReadBackend)
Value -> Parser [BackendKey SqlReadBackend]
Value -> Parser (BackendKey SqlReadBackend)
(Value -> Parser (BackendKey SqlReadBackend))
-> (Value -> Parser [BackendKey SqlReadBackend])
-> Maybe (BackendKey SqlReadBackend)
-> FromJSON (BackendKey SqlReadBackend)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser (BackendKey SqlReadBackend)
parseJSON :: Value -> Parser (BackendKey SqlReadBackend)
$cparseJSONList :: Value -> Parser [BackendKey SqlReadBackend]
parseJSONList :: Value -> Parser [BackendKey SqlReadBackend]
$comittedField :: Maybe (BackendKey SqlReadBackend)
omittedField :: Maybe (BackendKey SqlReadBackend)
A.FromJSON)
instance PersistCore SqlWriteBackend where
newtype BackendKey SqlWriteBackend = SqlWriteBackendKey { BackendKey SqlWriteBackend -> Int64
unSqlWriteBackendKey :: Int64 }
deriving stock (Int -> BackendKey SqlWriteBackend -> ShowS
[BackendKey SqlWriteBackend] -> ShowS
BackendKey SqlWriteBackend -> String
(Int -> BackendKey SqlWriteBackend -> ShowS)
-> (BackendKey SqlWriteBackend -> String)
-> ([BackendKey SqlWriteBackend] -> ShowS)
-> Show (BackendKey SqlWriteBackend)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BackendKey SqlWriteBackend -> ShowS
showsPrec :: Int -> BackendKey SqlWriteBackend -> ShowS
$cshow :: BackendKey SqlWriteBackend -> String
show :: BackendKey SqlWriteBackend -> String
$cshowList :: [BackendKey SqlWriteBackend] -> ShowS
showList :: [BackendKey SqlWriteBackend] -> ShowS
Show, ReadPrec [BackendKey SqlWriteBackend]
ReadPrec (BackendKey SqlWriteBackend)
Int -> ReadS (BackendKey SqlWriteBackend)
ReadS [BackendKey SqlWriteBackend]
(Int -> ReadS (BackendKey SqlWriteBackend))
-> ReadS [BackendKey SqlWriteBackend]
-> ReadPrec (BackendKey SqlWriteBackend)
-> ReadPrec [BackendKey SqlWriteBackend]
-> Read (BackendKey SqlWriteBackend)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS (BackendKey SqlWriteBackend)
readsPrec :: Int -> ReadS (BackendKey SqlWriteBackend)
$creadList :: ReadS [BackendKey SqlWriteBackend]
readList :: ReadS [BackendKey SqlWriteBackend]
$creadPrec :: ReadPrec (BackendKey SqlWriteBackend)
readPrec :: ReadPrec (BackendKey SqlWriteBackend)
$creadListPrec :: ReadPrec [BackendKey SqlWriteBackend]
readListPrec :: ReadPrec [BackendKey SqlWriteBackend]
Read, BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
(BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Bool)
-> Eq (BackendKey SqlWriteBackend)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
== :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c/= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
/= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
Eq, Eq (BackendKey SqlWriteBackend)
Eq (BackendKey SqlWriteBackend) =>
(BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Bool)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Bool)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Bool)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Bool)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> Ord (BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering
compare :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering
$c< :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
< :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c<= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
<= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c> :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
> :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c>= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
>= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$cmax :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
max :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cmin :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
min :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
Ord, (forall x.
BackendKey SqlWriteBackend -> Rep (BackendKey SqlWriteBackend) x)
-> (forall x.
Rep (BackendKey SqlWriteBackend) x -> BackendKey SqlWriteBackend)
-> Generic (BackendKey SqlWriteBackend)
forall x.
Rep (BackendKey SqlWriteBackend) x -> BackendKey SqlWriteBackend
forall x.
BackendKey SqlWriteBackend -> Rep (BackendKey SqlWriteBackend) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
BackendKey SqlWriteBackend -> Rep (BackendKey SqlWriteBackend) x
from :: forall x.
BackendKey SqlWriteBackend -> Rep (BackendKey SqlWriteBackend) x
$cto :: forall x.
Rep (BackendKey SqlWriteBackend) x -> BackendKey SqlWriteBackend
to :: forall x.
Rep (BackendKey SqlWriteBackend) x -> BackendKey SqlWriteBackend
Generic)
deriving newtype (Integer -> BackendKey SqlWriteBackend
BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
(BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (Integer -> BackendKey SqlWriteBackend)
-> Num (BackendKey SqlWriteBackend)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
+ :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$c- :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
- :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$c* :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
* :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cnegate :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
negate :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cabs :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
abs :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$csignum :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
signum :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cfromInteger :: Integer -> BackendKey SqlWriteBackend
fromInteger :: Integer -> BackendKey SqlWriteBackend
Num, Enum (BackendKey SqlWriteBackend)
Real (BackendKey SqlWriteBackend)
(Real (BackendKey SqlWriteBackend),
Enum (BackendKey SqlWriteBackend)) =>
(BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend))
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend))
-> (BackendKey SqlWriteBackend -> Integer)
-> Integral (BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend -> Integer
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
quot :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$crem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
rem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cdiv :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
div :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cmod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
mod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cquotRem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
quotRem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
$cdivMod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
divMod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
$ctoInteger :: BackendKey SqlWriteBackend -> Integer
toInteger :: BackendKey SqlWriteBackend -> Integer
Integral, PersistValue -> Either Text (BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend -> PersistValue
(BackendKey SqlWriteBackend -> PersistValue)
-> (PersistValue -> Either Text (BackendKey SqlWriteBackend))
-> PersistField (BackendKey SqlWriteBackend)
forall a.
(a -> PersistValue)
-> (PersistValue -> Either Text a) -> PersistField a
$ctoPersistValue :: BackendKey SqlWriteBackend -> PersistValue
toPersistValue :: BackendKey SqlWriteBackend -> PersistValue
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlWriteBackend)
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlWriteBackend)
PersistField, PersistField (BackendKey SqlWriteBackend)
Proxy (BackendKey SqlWriteBackend) -> SqlType
PersistField (BackendKey SqlWriteBackend) =>
(Proxy (BackendKey SqlWriteBackend) -> SqlType)
-> PersistFieldSql (BackendKey SqlWriteBackend)
forall a.
PersistField a =>
(Proxy a -> SqlType) -> PersistFieldSql a
$csqlType :: Proxy (BackendKey SqlWriteBackend) -> SqlType
sqlType :: Proxy (BackendKey SqlWriteBackend) -> SqlType
PersistFieldSql, Text -> Maybe (BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend -> Text
(Text -> Maybe (BackendKey SqlWriteBackend))
-> (BackendKey SqlWriteBackend -> Text)
-> PathPiece (BackendKey SqlWriteBackend)
forall s. (Text -> Maybe s) -> (s -> Text) -> PathPiece s
$cfromPathPiece :: Text -> Maybe (BackendKey SqlWriteBackend)
fromPathPiece :: Text -> Maybe (BackendKey SqlWriteBackend)
$ctoPathPiece :: BackendKey SqlWriteBackend -> Text
toPathPiece :: BackendKey SqlWriteBackend -> Text
PathPiece, BackendKey SqlWriteBackend -> Text
BackendKey SqlWriteBackend -> ByteString
BackendKey SqlWriteBackend -> Builder
(BackendKey SqlWriteBackend -> Text)
-> (BackendKey SqlWriteBackend -> Builder)
-> (BackendKey SqlWriteBackend -> ByteString)
-> (BackendKey SqlWriteBackend -> Text)
-> (BackendKey SqlWriteBackend -> Builder)
-> ToHttpApiData (BackendKey SqlWriteBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: BackendKey SqlWriteBackend -> Text
toUrlPiece :: BackendKey SqlWriteBackend -> Text
$ctoEncodedUrlPiece :: BackendKey SqlWriteBackend -> Builder
toEncodedUrlPiece :: BackendKey SqlWriteBackend -> Builder
$ctoHeader :: BackendKey SqlWriteBackend -> ByteString
toHeader :: BackendKey SqlWriteBackend -> ByteString
$ctoQueryParam :: BackendKey SqlWriteBackend -> Text
toQueryParam :: BackendKey SqlWriteBackend -> Text
$ctoEncodedQueryParam :: BackendKey SqlWriteBackend -> Builder
toEncodedQueryParam :: BackendKey SqlWriteBackend -> Builder
ToHttpApiData, Text -> Either Text (BackendKey SqlWriteBackend)
ByteString -> Either Text (BackendKey SqlWriteBackend)
(Text -> Either Text (BackendKey SqlWriteBackend))
-> (ByteString -> Either Text (BackendKey SqlWriteBackend))
-> (Text -> Either Text (BackendKey SqlWriteBackend))
-> FromHttpApiData (BackendKey SqlWriteBackend)
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text (BackendKey SqlWriteBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlWriteBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlWriteBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlWriteBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlWriteBackend)
parseQueryParam :: Text -> Either Text (BackendKey SqlWriteBackend)
FromHttpApiData, Num (BackendKey SqlWriteBackend)
Ord (BackendKey SqlWriteBackend)
(Num (BackendKey SqlWriteBackend),
Ord (BackendKey SqlWriteBackend)) =>
(BackendKey SqlWriteBackend -> Rational)
-> Real (BackendKey SqlWriteBackend)
BackendKey SqlWriteBackend -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: BackendKey SqlWriteBackend -> Rational
toRational :: BackendKey SqlWriteBackend -> Rational
Real, Int -> BackendKey SqlWriteBackend
BackendKey SqlWriteBackend -> Int
BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend]
(BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend)
-> (Int -> BackendKey SqlWriteBackend)
-> (BackendKey SqlWriteBackend -> Int)
-> (BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend])
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend])
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend])
-> (BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend])
-> Enum (BackendKey SqlWriteBackend)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
succ :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cpred :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
pred :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$ctoEnum :: Int -> BackendKey SqlWriteBackend
toEnum :: Int -> BackendKey SqlWriteBackend
$cfromEnum :: BackendKey SqlWriteBackend -> Int
fromEnum :: BackendKey SqlWriteBackend -> Int
$cenumFrom :: BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
enumFrom :: BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFromThen :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
enumFromThen :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFromTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
enumFromTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFromThenTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend]
enumFromThenTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend]
Enum, BackendKey SqlWriteBackend
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> Bounded (BackendKey SqlWriteBackend)
forall a. a -> a -> Bounded a
$cminBound :: BackendKey SqlWriteBackend
minBound :: BackendKey SqlWriteBackend
$cmaxBound :: BackendKey SqlWriteBackend
maxBound :: BackendKey SqlWriteBackend
Bounded, [BackendKey SqlWriteBackend] -> Value
[BackendKey SqlWriteBackend] -> Encoding
BackendKey SqlWriteBackend -> Bool
BackendKey SqlWriteBackend -> Value
BackendKey SqlWriteBackend -> Encoding
(BackendKey SqlWriteBackend -> Value)
-> (BackendKey SqlWriteBackend -> Encoding)
-> ([BackendKey SqlWriteBackend] -> Value)
-> ([BackendKey SqlWriteBackend] -> Encoding)
-> (BackendKey SqlWriteBackend -> Bool)
-> ToJSON (BackendKey SqlWriteBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: BackendKey SqlWriteBackend -> Value
toJSON :: BackendKey SqlWriteBackend -> Value
$ctoEncoding :: BackendKey SqlWriteBackend -> Encoding
toEncoding :: BackendKey SqlWriteBackend -> Encoding
$ctoJSONList :: [BackendKey SqlWriteBackend] -> Value
toJSONList :: [BackendKey SqlWriteBackend] -> Value
$ctoEncodingList :: [BackendKey SqlWriteBackend] -> Encoding
toEncodingList :: [BackendKey SqlWriteBackend] -> Encoding
$comitField :: BackendKey SqlWriteBackend -> Bool
omitField :: BackendKey SqlWriteBackend -> Bool
A.ToJSON, Maybe (BackendKey SqlWriteBackend)
Value -> Parser [BackendKey SqlWriteBackend]
Value -> Parser (BackendKey SqlWriteBackend)
(Value -> Parser (BackendKey SqlWriteBackend))
-> (Value -> Parser [BackendKey SqlWriteBackend])
-> Maybe (BackendKey SqlWriteBackend)
-> FromJSON (BackendKey SqlWriteBackend)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser (BackendKey SqlWriteBackend)
parseJSON :: Value -> Parser (BackendKey SqlWriteBackend)
$cparseJSONList :: Value -> Parser [BackendKey SqlWriteBackend]
parseJSONList :: Value -> Parser [BackendKey SqlWriteBackend]
$comittedField :: Maybe (BackendKey SqlWriteBackend)
omittedField :: Maybe (BackendKey SqlWriteBackend)
A.FromJSON)
instance BackendCompatible SqlBackend SqlBackend where
projectBackend :: SqlBackend -> SqlBackend
projectBackend = SqlBackend -> SqlBackend
forall a. a -> a
id
instance BackendCompatible SqlBackend SqlReadBackend where
projectBackend :: SqlReadBackend -> SqlBackend
projectBackend = SqlReadBackend -> SqlBackend
unSqlReadBackend
instance BackendCompatible SqlBackend SqlWriteBackend where
projectBackend :: SqlWriteBackend -> SqlBackend
projectBackend = SqlWriteBackend -> SqlBackend
unSqlWriteBackend
instance PersistStoreWrite SqlBackend where
update :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> [Update record] -> ReaderT SqlBackend m ()
update Key record
_ [] = () -> ReaderT SqlBackend m ()
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
update Key record
k [Update record]
upds = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let wher :: Text
wher = SqlBackend -> Key record -> Text
forall record.
PersistEntity record =>
SqlBackend -> Key record -> Text
whereStmtForKey SqlBackend
conn Key record
k
let sql :: Text
sql = [Text] -> Text
T.concat
[ Text
"UPDATE "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn (Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ record -> Maybe record
forall a. a -> Maybe a
Just (record -> Maybe record) -> record -> Maybe record
forall a b. (a -> b) -> a -> b
$ Key record -> record
forall record. Key record -> record
recordTypeFromKey Key record
k)
, Text
" SET "
, Text -> [Text] -> Text
T.intercalate Text
"," ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Update record -> Text) -> [Update record] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (SqlBackend -> Update record -> Text
forall record.
PersistEntity record =>
SqlBackend -> Update record -> Text
mkUpdateText SqlBackend
conn) [Update record]
upds
, Text
" WHERE "
, Text
wher
]
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql ([PersistValue] -> ReaderT SqlBackend m ())
-> [PersistValue] -> ReaderT SqlBackend m ()
forall a b. (a -> b) -> a -> b
$
(Update record -> PersistValue)
-> [Update record] -> [PersistValue]
forall a b. (a -> b) -> [a] -> [b]
map Update record -> PersistValue
forall v. Update v -> PersistValue
updatePersistValue [Update record]
upds [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Monoid a => a -> a -> a
`mappend` Key record -> [PersistValue]
forall record. PersistEntity record => Key record -> [PersistValue]
keyToValues Key record
k
insert_ :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
record -> ReaderT SqlBackend m ()
insert_ record
val = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let vals :: [PersistValue]
vals = record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues record
val
case SqlBackend -> EntityDef -> [PersistValue] -> InsertSqlResult
connInsertSql SqlBackend
conn (Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (record -> Maybe record
forall a. a -> Maybe a
Just record
val)) [PersistValue]
vals of
ISRSingle Text
sql -> do
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO ()
-> ReaderT SqlBackend m ()
forall (m :: * -> *) a.
MonadIO m =>
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery Text
sql [PersistValue]
vals (ConduitM [PersistValue] Void IO () -> ReaderT SqlBackend m ())
-> ConduitM [PersistValue] Void IO () -> ReaderT SqlBackend m ()
forall a b. (a -> b) -> a -> b
$ do
() -> ConduitM [PersistValue] Void IO ()
forall a. a -> ConduitT [PersistValue] Void IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
ISRInsertGet Text
sql1 Text
_sql2 -> do
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql1 [PersistValue]
vals
ISRManyKeys Text
sql [PersistValue]
_fs -> do
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql [PersistValue]
vals
insert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
record -> ReaderT SqlBackend m (Key record)
insert record
val = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let esql :: InsertSqlResult
esql = SqlBackend -> EntityDef -> [PersistValue] -> InsertSqlResult
connInsertSql SqlBackend
conn EntityDef
t [PersistValue]
vals
Key record
key <-
case InsertSqlResult
esql of
ISRSingle Text
sql -> Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record)
forall (m :: * -> *) a.
MonadIO m =>
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery Text
sql [PersistValue]
vals (ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record))
-> ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record)
forall a b. (a -> b) -> a -> b
$ do
Maybe [PersistValue]
x <- ConduitT [PersistValue] Void IO (Maybe [PersistValue])
forall (m :: * -> *) a o. Monad m => ConduitT a o m (Maybe a)
CL.head
case Maybe [PersistValue]
x of
Just [PersistInt64 Int64
i] -> case [PersistValue] -> Either Text (Key record)
forall record.
PersistEntity record =>
[PersistValue] -> Either Text (Key record)
keyFromValues [Int64 -> PersistValue
PersistInt64 Int64
i] of
Left Text
err -> String -> ConduitM [PersistValue] Void IO (Key record)
forall a. HasCallStack => String -> a
error (String -> ConduitM [PersistValue] Void IO (Key record))
-> String -> ConduitM [PersistValue] Void IO (Key record)
forall a b. (a -> b) -> a -> b
$ String
"SQL insert: keyFromValues: PersistInt64 " String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` Int64 -> String
forall a. Show a => a -> String
show Int64
i String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` String
" " String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` Text -> String
unpack Text
err
Right Key record
k -> Key record -> ConduitM [PersistValue] Void IO (Key record)
forall a. a -> ConduitT [PersistValue] Void IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Key record
k
Maybe [PersistValue]
Nothing -> String -> ConduitM [PersistValue] Void IO (Key record)
forall a. HasCallStack => String -> a
error (String -> ConduitM [PersistValue] Void IO (Key record))
-> String -> ConduitM [PersistValue] Void IO (Key record)
forall a b. (a -> b) -> a -> b
$ String
"SQL insert did not return a result giving the generated ID"
Just [PersistValue]
vals' -> case [PersistValue] -> Either Text (Key record)
forall record.
PersistEntity record =>
[PersistValue] -> Either Text (Key record)
keyFromValues [PersistValue]
vals' of
Left Text
e -> String -> ConduitM [PersistValue] Void IO (Key record)
forall a. HasCallStack => String -> a
error (String -> ConduitM [PersistValue] Void IO (Key record))
-> String -> ConduitM [PersistValue] Void IO (Key record)
forall a b. (a -> b) -> a -> b
$ String
"Invalid result from a SQL insert, got: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [PersistValue] -> String
forall a. Show a => a -> String
show [PersistValue]
vals' String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
". Error was: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
unpack Text
e
Right Key record
k -> Key record -> ConduitM [PersistValue] Void IO (Key record)
forall a. a -> ConduitT [PersistValue] Void IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Key record
k
ISRInsertGet Text
sql1 Text
sql2 -> do
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql1 [PersistValue]
vals
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record)
forall (m :: * -> *) a.
MonadIO m =>
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery Text
sql2 [] (ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record))
-> ConduitM [PersistValue] Void IO (Key record)
-> ReaderT SqlBackend m (Key record)
forall a b. (a -> b) -> a -> b
$ do
Maybe [PersistValue]
mm <- ConduitT [PersistValue] Void IO (Maybe [PersistValue])
forall (m :: * -> *) a o. Monad m => ConduitT a o m (Maybe a)
CL.head
let m :: Either Text [PersistValue]
m = Either Text [PersistValue]
-> ([PersistValue] -> Either Text [PersistValue])
-> Maybe [PersistValue]
-> Either Text [PersistValue]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(Text -> Either Text [PersistValue]
forall a b. a -> Either a b
Left (Text -> Either Text [PersistValue])
-> Text -> Either Text [PersistValue]
forall a b. (a -> b) -> a -> b
$ Text
"No results from ISRInsertGet: " Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` (Text, Text) -> Text
forall a. Show a => a -> Text
tshow (Text
sql1, Text
sql2))
[PersistValue] -> Either Text [PersistValue]
forall a b. b -> Either a b
Right Maybe [PersistValue]
mm
let convert :: [PersistValue] -> [PersistValue]
convert [PersistValue]
x =
case [PersistValue]
x of
[PersistByteString ByteString
i] -> case ByteString -> Maybe (Integer, ByteString)
readInteger ByteString
i of
Just (Integer
ret,ByteString
"") -> [Int64 -> PersistValue
PersistInt64 (Int64 -> PersistValue) -> Int64 -> PersistValue
forall a b. (a -> b) -> a -> b
$ Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
ret]
Maybe (Integer, ByteString)
_ -> [PersistValue]
x
[PersistValue]
_ -> [PersistValue]
x
onLeft :: Either a b -> Either a b -> Either a b
onLeft Left{} Either a b
x = Either a b
x
onLeft Either a b
x Either a b
_ = Either a b
x
case Either Text [PersistValue]
m Either Text [PersistValue]
-> ([PersistValue] -> Either Text (Key record))
-> Either Text (Key record)
forall a b. Either Text a -> (a -> Either Text b) -> Either Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\[PersistValue]
x -> [PersistValue] -> Either Text (Key record)
forall record.
PersistEntity record =>
[PersistValue] -> Either Text (Key record)
keyFromValues [PersistValue]
x Either Text (Key record)
-> Either Text (Key record) -> Either Text (Key record)
forall {a} {b}. Either a b -> Either a b -> Either a b
`onLeft` [PersistValue] -> Either Text (Key record)
forall record.
PersistEntity record =>
[PersistValue] -> Either Text (Key record)
keyFromValues ([PersistValue] -> [PersistValue]
convert [PersistValue]
x)) of
Right Key record
k -> Key record -> ConduitM [PersistValue] Void IO (Key record)
forall a. a -> ConduitT [PersistValue] Void IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Key record
k
Left Text
err -> Text -> ConduitM [PersistValue] Void IO (Key record)
forall {a}. Text -> ConduitT [PersistValue] Void IO a
throw (Text -> ConduitM [PersistValue] Void IO (Key record))
-> Text -> ConduitM [PersistValue] Void IO (Key record)
forall a b. (a -> b) -> a -> b
$ Text
"ISRInsertGet: keyFromValues failed: " Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text
err
ISRManyKeys Text
sql [PersistValue]
fs -> do
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql [PersistValue]
vals
case EntityDef -> Maybe CompositeDef
entityPrimary EntityDef
t of
Maybe CompositeDef
Nothing ->
String -> ReaderT SqlBackend m (Key record)
forall a. HasCallStack => String -> a
error (String -> ReaderT SqlBackend m (Key record))
-> String -> ReaderT SqlBackend m (Key record)
forall a b. (a -> b) -> a -> b
$ String
"ISRManyKeys is used when Primary is defined " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
sql
Just CompositeDef
pdef ->
let pks :: [FieldNameHS]
pks = NonEmpty FieldNameHS -> [FieldNameHS]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList (NonEmpty FieldNameHS -> [FieldNameHS])
-> NonEmpty FieldNameHS -> [FieldNameHS]
forall a b. (a -> b) -> a -> b
$ (FieldDef -> FieldNameHS)
-> NonEmpty FieldDef -> NonEmpty FieldNameHS
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FieldDef -> FieldNameHS
fieldHaskell (NonEmpty FieldDef -> NonEmpty FieldNameHS)
-> NonEmpty FieldDef -> NonEmpty FieldNameHS
forall a b. (a -> b) -> a -> b
$ CompositeDef -> NonEmpty FieldDef
compositeFields CompositeDef
pdef
keyvals :: [PersistValue]
keyvals = ((FieldNameHS, PersistValue) -> PersistValue)
-> [(FieldNameHS, PersistValue)] -> [PersistValue]
forall a b. (a -> b) -> [a] -> [b]
map (FieldNameHS, PersistValue) -> PersistValue
forall a b. (a, b) -> b
snd ([(FieldNameHS, PersistValue)] -> [PersistValue])
-> [(FieldNameHS, PersistValue)] -> [PersistValue]
forall a b. (a -> b) -> a -> b
$ ((FieldNameHS, PersistValue) -> Bool)
-> [(FieldNameHS, PersistValue)] -> [(FieldNameHS, PersistValue)]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(FieldNameHS
a, PersistValue
_) -> let ret :: Bool
ret=Maybe FieldNameHS -> Bool
forall a. Maybe a -> Bool
isJust ((FieldNameHS -> Bool) -> [FieldNameHS] -> Maybe FieldNameHS
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (FieldNameHS -> FieldNameHS -> Bool
forall a. Eq a => a -> a -> Bool
== FieldNameHS
a) [FieldNameHS]
pks) in Bool
ret) ([(FieldNameHS, PersistValue)] -> [(FieldNameHS, PersistValue)])
-> [(FieldNameHS, PersistValue)] -> [(FieldNameHS, PersistValue)]
forall a b. (a -> b) -> a -> b
$ [FieldNameHS] -> [PersistValue] -> [(FieldNameHS, PersistValue)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((FieldDef -> FieldNameHS) -> [FieldDef] -> [FieldNameHS]
forall a b. (a -> b) -> [a] -> [b]
map FieldDef -> FieldNameHS
fieldHaskell ([FieldDef] -> [FieldNameHS]) -> [FieldDef] -> [FieldNameHS]
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
getEntityFields EntityDef
t) [PersistValue]
fs
in case [PersistValue] -> Either Text (Key record)
forall record.
PersistEntity record =>
[PersistValue] -> Either Text (Key record)
keyFromValues [PersistValue]
keyvals of
Right Key record
k -> Key record -> ReaderT SqlBackend m (Key record)
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return Key record
k
Left Text
e -> String -> ReaderT SqlBackend m (Key record)
forall a. HasCallStack => String -> a
error (String -> ReaderT SqlBackend m (Key record))
-> String -> ReaderT SqlBackend m (Key record)
forall a b. (a -> b) -> a -> b
$ String
"ISRManyKeys: unexpected keyvals result: " String -> ShowS
forall a. Monoid a => a -> a -> a
`mappend` Text -> String
unpack Text
e
Key record -> ReaderT SqlBackend m (Key record)
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return Key record
key
where
tshow :: Show a => a -> Text
tshow :: forall a. Show a => a -> Text
tshow = String -> Text
T.pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show
throw :: Text -> ConduitT [PersistValue] Void IO a
throw = IO a -> ConduitT [PersistValue] Void IO a
forall a. IO a -> ConduitT [PersistValue] Void IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> ConduitT [PersistValue] Void IO a)
-> (Text -> IO a) -> Text -> ConduitT [PersistValue] Void IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IO a
forall e a. Exception e => e -> IO a
throwIO (IOError -> IO a) -> (Text -> IOError) -> Text -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IOError
userError (String -> IOError) -> (Text -> String) -> Text -> IOError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
t :: EntityDef
t = Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ record -> Maybe record
forall a. a -> Maybe a
Just record
val
vals :: [PersistValue]
vals = record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues record
val
insertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlBackend m [Key record]
insertMany [] = [Key record] -> ReaderT SqlBackend m [Key record]
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return []
insertMany [record]
vals = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
case SqlBackend
-> Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
connInsertManySql SqlBackend
conn of
Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
Nothing -> (record -> ReaderT SqlBackend m (Key record))
-> [record] -> ReaderT SqlBackend m [Key record]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM record -> ReaderT SqlBackend m (Key record)
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
record -> ReaderT SqlBackend m (Key record)
insert [record]
vals
Just EntityDef -> [[PersistValue]] -> InsertSqlResult
insertManyFn ->
case EntityDef -> [[PersistValue]] -> InsertSqlResult
insertManyFn EntityDef
ent [[PersistValue]]
valss of
ISRSingle Text
sql -> Text -> [PersistValue] -> ReaderT SqlBackend m [Key record]
forall a (m :: * -> *) backend.
(RawSql a, MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m [a]
rawSql Text
sql ([[PersistValue]] -> [PersistValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[PersistValue]]
valss)
InsertSqlResult
_ -> String -> ReaderT SqlBackend m [Key record]
forall a. HasCallStack => String -> a
error String
"ISRSingle is expected from the connInsertManySql function"
where
ent :: EntityDef
ent = [record] -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef [record]
vals
valss :: [[PersistValue]]
valss = (record -> [PersistValue]) -> [record] -> [[PersistValue]]
forall a b. (a -> b) -> [a] -> [b]
map record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues [record]
vals
insertMany_ :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlBackend m ()
insertMany_ [record]
vals0 = Int
-> ([record] -> ReaderT SqlBackend m ())
-> [record]
-> ReaderT SqlBackend m ()
forall (m :: * -> *) a.
Monad m =>
Int
-> ([a] -> ReaderT SqlBackend m ())
-> [a]
-> ReaderT SqlBackend m ()
runChunked ([FieldDef] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([FieldDef] -> Int) -> [FieldDef] -> Int
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
getEntityFields EntityDef
t) [record] -> ReaderT SqlBackend m ()
insertMany_' [record]
vals0
where
t :: EntityDef
t = [record] -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef [record]
vals0
insertMany_' :: [record] -> ReaderT SqlBackend m ()
insertMany_' [record]
vals = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let valss :: [[PersistValue]]
valss = (record -> [PersistValue]) -> [record] -> [[PersistValue]]
forall a b. (a -> b) -> [a] -> [b]
map record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues [record]
vals
let sql :: Text
sql = [Text] -> Text
T.concat
[ Text
"INSERT INTO "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn EntityDef
t
, Text
"("
, Text -> [Text] -> Text
T.intercalate Text
"," ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (FieldDef -> Text) -> [FieldDef] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (SqlBackend -> FieldNameDB -> Text
connEscapeFieldName SqlBackend
conn (FieldNameDB -> Text)
-> (FieldDef -> FieldNameDB) -> FieldDef -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> FieldNameDB
fieldDB) ([FieldDef] -> [Text]) -> [FieldDef] -> [Text]
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
getEntityFields EntityDef
t
, Text
") VALUES ("
, Text -> [Text] -> Text
T.intercalate Text
"),(" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> [Text]
forall a. Int -> a -> [a]
replicate ([[PersistValue]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[PersistValue]]
valss) (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"," ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (FieldDef -> Text) -> [FieldDef] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> FieldDef -> Text
forall a b. a -> b -> a
const Text
"?") (EntityDef -> [FieldDef]
getEntityFields EntityDef
t)
, Text
")"
]
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql ([[PersistValue]] -> [PersistValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[PersistValue]]
valss)
replace :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
replace Key record
k record
val = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let t :: EntityDef
t = Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ record -> Maybe record
forall a. a -> Maybe a
Just record
val
let wher :: Text
wher = SqlBackend -> Key record -> Text
forall record.
PersistEntity record =>
SqlBackend -> Key record -> Text
whereStmtForKey SqlBackend
conn Key record
k
let sql :: Text
sql = [Text] -> Text
T.concat
[ Text
"UPDATE "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn EntityDef
t
, Text
" SET "
, Text -> [Text] -> Text
T.intercalate Text
"," ((FieldDef -> Text) -> [FieldDef] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (SqlBackend -> FieldNameDB -> Text
go SqlBackend
conn (FieldNameDB -> Text)
-> (FieldDef -> FieldNameDB) -> FieldDef -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> FieldNameDB
fieldDB) ([FieldDef] -> [Text]) -> [FieldDef] -> [Text]
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
getEntityFields EntityDef
t)
, Text
" WHERE "
, Text
wher
]
vals :: [PersistValue]
vals = record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues record
val [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Monoid a => a -> a -> a
`mappend` Key record -> [PersistValue]
forall record. PersistEntity record => Key record -> [PersistValue]
keyToValues Key record
k
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute Text
sql [PersistValue]
vals
where
go :: SqlBackend -> FieldNameDB -> Text
go SqlBackend
conn FieldNameDB
x = SqlBackend -> FieldNameDB -> Text
connEscapeFieldName SqlBackend
conn FieldNameDB
x Text -> Text -> Text
`T.append` Text
"=?"
insertKey :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
insertKey Key record
k record
v = Text -> [Entity record] -> ReaderT SqlBackend m ()
forall (m :: * -> *) val.
(MonadIO m, PersistEntity val) =>
Text -> [Entity val] -> ReaderT SqlBackend m ()
insrepHelper Text
"INSERT" [Key record -> record -> Entity record
forall record. Key record -> record -> Entity record
Entity Key record
k record
v]
insertEntityMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Entity record] -> ReaderT SqlBackend m ()
insertEntityMany [Entity record]
es' = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let entDef :: EntityDef
entDef = [record] -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef ([record] -> EntityDef) -> [record] -> EntityDef
forall a b. (a -> b) -> a -> b
$ (Entity record -> record) -> [Entity record] -> [record]
forall a b. (a -> b) -> [a] -> [b]
map Entity record -> record
forall record. Entity record -> record
entityVal [Entity record]
es'
let columnNames :: NonEmpty Text
columnNames = EntityDef -> SqlBackend -> NonEmpty Text
keyAndEntityColumnNames EntityDef
entDef SqlBackend
conn
Int
-> ([Entity record] -> ReaderT SqlBackend m ())
-> [Entity record]
-> ReaderT SqlBackend m ()
forall (m :: * -> *) a.
Monad m =>
Int
-> ([a] -> ReaderT SqlBackend m ())
-> [a]
-> ReaderT SqlBackend m ()
runChunked (NonEmpty Text -> Int
forall a. NonEmpty a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length NonEmpty Text
columnNames) [Entity record] -> ReaderT SqlBackend m ()
go [Entity record]
es'
where
go :: [Entity record] -> ReaderT SqlBackend m ()
go = Text -> [Entity record] -> ReaderT SqlBackend m ()
forall (m :: * -> *) val.
(MonadIO m, PersistEntity val) =>
Text -> [Entity val] -> ReaderT SqlBackend m ()
insrepHelper Text
"INSERT"
repsert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
repsert Key record
key record
value = [(Key record, record)] -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
[(Key record, record)] -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[(Key record, record)] -> ReaderT SqlBackend m ()
repsertMany [(Key record
key, record
value)]
repsertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[(Key record, record)] -> ReaderT SqlBackend m ()
repsertMany [] = () -> ReaderT SqlBackend m ()
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
repsertMany [(Key record, record)]
krsDups = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let krs :: [(Key record, record)]
krs = ((Key record, record) -> (Key record, record) -> Bool)
-> [(Key record, record)] -> [(Key record, record)]
forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy (Key record -> Key record -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Key record -> Key record -> Bool)
-> ((Key record, record) -> Key record)
-> (Key record, record)
-> (Key record, record)
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Key record, record) -> Key record
forall a b. (a, b) -> a
fst) ([(Key record, record)] -> [(Key record, record)]
forall a. [a] -> [a]
reverse [(Key record, record)]
krsDups)
let rs :: [record]
rs = (Key record, record) -> record
forall a b. (a, b) -> b
snd ((Key record, record) -> record)
-> [(Key record, record)] -> [record]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` [(Key record, record)]
krs
let ent :: EntityDef
ent = [record] -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef [record]
rs
let nr :: Int
nr = [(Key record, record)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Key record, record)]
krs
let toVals :: (Key record, record) -> [PersistValue]
toVals (Key record
k,record
r)
= case EntityDef -> Maybe CompositeDef
entityPrimary EntityDef
ent of
Maybe CompositeDef
Nothing -> Key record -> [PersistValue]
forall record. PersistEntity record => Key record -> [PersistValue]
keyToValues Key record
k [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> (record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues record
r)
Just CompositeDef
_ -> record -> [PersistValue]
forall rec. PersistEntity rec => rec -> [PersistValue]
mkInsertValues record
r
case SqlBackend -> Maybe (EntityDef -> Int -> Text)
connRepsertManySql SqlBackend
conn of
(Just EntityDef -> Int -> Text
mkSql) -> Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute (EntityDef -> Int -> Text
mkSql EntityDef
ent Int
nr) (((Key record, record) -> [PersistValue])
-> [(Key record, record)] -> [PersistValue]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Key record, record) -> [PersistValue]
toVals [(Key record, record)]
krs)
Maybe (EntityDef -> Int -> Text)
Nothing -> ((Key record, record) -> ReaderT SqlBackend m ())
-> [(Key record, record)] -> ReaderT SqlBackend m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Key record, record) -> ReaderT SqlBackend m ()
forall {record} {backend} {m :: * -> *}.
(PersistEntityBackend record ~ BaseBackend backend, MonadIO m,
PersistEntity record, PersistStoreWrite backend) =>
(Key record, record) -> ReaderT backend m ()
repsert' [(Key record, record)]
krs
where
repsert' :: (Key record, record) -> ReaderT backend m ()
repsert' (Key record
key, record
value) = do
Maybe record
mExisting <- Key record -> ReaderT backend m (Maybe record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
get Key record
key
case Maybe record
mExisting of
Maybe record
Nothing -> Key record -> record -> ReaderT backend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
insertKey Key record
key record
value
Just record
_ -> Key record -> record -> ReaderT backend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
replace Key record
key record
value
delete :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> ReaderT SqlBackend m ()
delete Key record
k = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute (SqlBackend -> Text
sql SqlBackend
conn) (Key record -> [PersistValue]
forall record. PersistEntity record => Key record -> [PersistValue]
keyToValues Key record
k)
where
wher :: SqlBackend -> Text
wher SqlBackend
conn = SqlBackend -> Key record -> Text
forall record.
PersistEntity record =>
SqlBackend -> Key record -> Text
whereStmtForKey SqlBackend
conn Key record
k
sql :: SqlBackend -> Text
sql SqlBackend
conn = [Text] -> Text
T.concat
[ Text
"DELETE FROM "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn (Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef) -> Maybe record -> EntityDef
forall a b. (a -> b) -> a -> b
$ record -> Maybe record
forall a. a -> Maybe a
Just (record -> Maybe record) -> record -> Maybe record
forall a b. (a -> b) -> a -> b
$ Key record -> record
forall record. Key record -> record
recordTypeFromKey Key record
k)
, Text
" WHERE "
, SqlBackend -> Text
wher SqlBackend
conn
]
instance PersistStoreWrite SqlWriteBackend where
insert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend,
SafeToInsert record) =>
record -> ReaderT SqlWriteBackend m (Key record)
insert record
v = ReaderT (BaseBackend SqlWriteBackend) m (Key record)
-> ReaderT SqlWriteBackend m (Key record)
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m (Key record)
-> ReaderT SqlWriteBackend m (Key record))
-> ReaderT (BaseBackend SqlWriteBackend) m (Key record)
-> ReaderT SqlWriteBackend m (Key record)
forall a b. (a -> b) -> a -> b
$ record -> ReaderT SqlBackend m (Key record)
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
record -> ReaderT backend m (Key record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
record -> ReaderT SqlBackend m (Key record)
insert record
v
insertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlWriteBackend m [Key record]
insertMany [record]
vs = ReaderT (BaseBackend SqlWriteBackend) m [Key record]
-> ReaderT SqlWriteBackend m [Key record]
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m [Key record]
-> ReaderT SqlWriteBackend m [Key record])
-> ReaderT (BaseBackend SqlWriteBackend) m [Key record]
-> ReaderT SqlWriteBackend m [Key record]
forall a b. (a -> b) -> a -> b
$ [record] -> ReaderT SqlBackend m [Key record]
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
[record] -> ReaderT backend m [Key record]
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlBackend m [Key record]
insertMany [record]
vs
insertMany_ :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlWriteBackend m ()
insertMany_ [record]
vs = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ [record] -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend, SafeToInsert record) =>
[record] -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend,
SafeToInsert record) =>
[record] -> ReaderT SqlBackend m ()
insertMany_ [record]
vs
insertEntityMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
[Entity record] -> ReaderT SqlWriteBackend m ()
insertEntityMany [Entity record]
vs = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ [Entity record] -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
[Entity record] -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Entity record] -> ReaderT SqlBackend m ()
insertEntityMany [Entity record]
vs
insertKey :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> record -> ReaderT SqlWriteBackend m ()
insertKey Key record
k record
v = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
insertKey Key record
k record
v
repsert :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> record -> ReaderT SqlWriteBackend m ()
repsert Key record
k record
v = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
repsert Key record
k record
v
replace :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> record -> ReaderT SqlWriteBackend m ()
replace Key record
k record
v = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> record -> ReaderT SqlBackend m ()
replace Key record
k record
v
delete :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> ReaderT SqlWriteBackend m ()
delete Key record
k = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ Key record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> ReaderT SqlBackend m ()
delete Key record
k
update :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> [Update record] -> ReaderT SqlWriteBackend m ()
update Key record
k [Update record]
upds = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ Key record -> [Update record] -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> [Update record] -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> [Update record] -> ReaderT SqlBackend m ()
update Key record
k [Update record]
upds
repsertMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
[(Key record, record)] -> ReaderT SqlWriteBackend m ()
repsertMany [(Key record, record)]
krs = ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ())
-> ReaderT (BaseBackend SqlWriteBackend) m ()
-> ReaderT SqlWriteBackend m ()
forall a b. (a -> b) -> a -> b
$ [(Key record, record)] -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
[(Key record, record)] -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[(Key record, record)] -> ReaderT SqlBackend m ()
repsertMany [(Key record, record)]
krs
instance PersistStoreRead SqlBackend where
get :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> ReaderT SqlBackend m (Maybe record)
get Key record
k = do
Map (Key record) record
mEs <- [Key record] -> ReaderT SqlBackend m (Map (Key record) record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
[Key record] -> ReaderT backend m (Map (Key record) record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Key record] -> ReaderT SqlBackend m (Map (Key record) record)
getMany [Key record
k]
Maybe record -> ReaderT SqlBackend m (Maybe record)
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe record -> ReaderT SqlBackend m (Maybe record))
-> Maybe record -> ReaderT SqlBackend m (Maybe record)
forall a b. (a -> b) -> a -> b
$ Key record -> Map (Key record) record -> Maybe record
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Key record
k Map (Key record) record
mEs
getMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Key record] -> ReaderT SqlBackend m (Map (Key record) record)
getMany [] = Map (Key record) record
-> ReaderT SqlBackend m (Map (Key record) record)
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return Map (Key record) record
forall k a. Map k a
Map.empty
getMany ks :: [Key record]
ks@(Key record
k:[Key record]
_)= do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let t :: EntityDef
t = Maybe record -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy record -> EntityDef
entityDef (Maybe record -> EntityDef)
-> (Key record -> Maybe record) -> Key record -> EntityDef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key record -> Maybe record
forall record. Key record -> Maybe record
dummyFromKey (Key record -> EntityDef) -> Key record -> EntityDef
forall a b. (a -> b) -> a -> b
$ Key record
k
let cols :: SqlBackend -> Text
cols = [Text] -> Text
commaSeparated ([Text] -> Text) -> (SqlBackend -> [Text]) -> SqlBackend -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList (NonEmpty Text -> [Text])
-> (SqlBackend -> NonEmpty Text) -> SqlBackend -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityDef -> SqlBackend -> NonEmpty Text
keyAndEntityColumnNames EntityDef
t
let wher :: Text
wher = SqlBackend -> [Key record] -> Text
forall record.
PersistEntity record =>
SqlBackend -> [Key record] -> Text
whereStmtForKeys SqlBackend
conn [Key record]
ks
let sql :: Text
sql = [Text] -> Text
T.concat
[ Text
"SELECT "
, SqlBackend -> Text
cols SqlBackend
conn
, Text
" FROM "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn EntityDef
t
, Text
" WHERE "
, Text
wher
]
let parse :: [PersistValue] -> IO (Entity record)
parse [PersistValue]
vals
= case EntityDef -> [PersistValue] -> Either Text (Entity record)
forall record.
PersistEntity record =>
EntityDef -> [PersistValue] -> Either Text (Entity record)
parseEntityValues EntityDef
t [PersistValue]
vals of
Left Text
s -> IO (Entity record) -> IO (Entity record)
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Entity record) -> IO (Entity record))
-> IO (Entity record) -> IO (Entity record)
forall a b. (a -> b) -> a -> b
$ PersistException -> IO (Entity record)
forall e a. Exception e => e -> IO a
throwIO (PersistException -> IO (Entity record))
-> PersistException -> IO (Entity record)
forall a b. (a -> b) -> a -> b
$
Text -> PersistException
PersistMarshalError (Text
"getBy: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s)
Right Entity record
row -> Entity record -> IO (Entity record)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Entity record
row
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO (Map (Key record) record)
-> ReaderT SqlBackend m (Map (Key record) record)
forall (m :: * -> *) a.
MonadIO m =>
Text
-> [PersistValue]
-> ConduitM [PersistValue] Void IO a
-> ReaderT SqlBackend m a
withRawQuery Text
sql ((Key record -> [PersistValue]) -> [Key record] -> [PersistValue]
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap Key record -> [PersistValue]
forall record. PersistEntity record => Key record -> [PersistValue]
keyToValues [Key record]
ks) (ConduitM [PersistValue] Void IO (Map (Key record) record)
-> ReaderT SqlBackend m (Map (Key record) record))
-> ConduitM [PersistValue] Void IO (Map (Key record) record)
-> ReaderT SqlBackend m (Map (Key record) record)
forall a b. (a -> b) -> a -> b
$ do
[Entity record]
es <- ([PersistValue] -> IO (Entity record))
-> ConduitT [PersistValue] (Entity record) IO ()
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConduitT a b m ()
CL.mapM [PersistValue] -> IO (Entity record)
parse ConduitT [PersistValue] (Entity record) IO ()
-> ConduitT (Entity record) Void IO [Entity record]
-> ConduitT [PersistValue] Void IO [Entity record]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| ConduitT (Entity record) Void IO [Entity record]
forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
CL.consume
Map (Key record) record
-> ConduitM [PersistValue] Void IO (Map (Key record) record)
forall a. a -> ConduitT [PersistValue] Void IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Map (Key record) record
-> ConduitM [PersistValue] Void IO (Map (Key record) record))
-> Map (Key record) record
-> ConduitM [PersistValue] Void IO (Map (Key record) record)
forall a b. (a -> b) -> a -> b
$ [(Key record, record)] -> Map (Key record) record
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(Key record, record)] -> Map (Key record) record)
-> [(Key record, record)] -> Map (Key record) record
forall a b. (a -> b) -> a -> b
$ (Entity record -> (Key record, record))
-> [Entity record] -> [(Key record, record)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Entity record
e -> (Entity record -> Key record
forall record. Entity record -> Key record
entityKey Entity record
e, Entity record -> record
forall record. Entity record -> record
entityVal Entity record
e)) [Entity record]
es
instance PersistStoreRead SqlReadBackend where
get :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlReadBackend) =>
Key record -> ReaderT SqlReadBackend m (Maybe record)
get Key record
k = ReaderT (BaseBackend SqlReadBackend) m (Maybe record)
-> ReaderT SqlReadBackend m (Maybe record)
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlReadBackend) m (Maybe record)
-> ReaderT SqlReadBackend m (Maybe record))
-> ReaderT (BaseBackend SqlReadBackend) m (Maybe record)
-> ReaderT SqlReadBackend m (Maybe record)
forall a b. (a -> b) -> a -> b
$ Key record -> ReaderT SqlBackend m (Maybe record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> ReaderT SqlBackend m (Maybe record)
get Key record
k
getMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlReadBackend) =>
[Key record] -> ReaderT SqlReadBackend m (Map (Key record) record)
getMany [Key record]
ks = ReaderT (BaseBackend SqlReadBackend) m (Map (Key record) record)
-> ReaderT SqlReadBackend m (Map (Key record) record)
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlReadBackend) m (Map (Key record) record)
-> ReaderT SqlReadBackend m (Map (Key record) record))
-> ReaderT (BaseBackend SqlReadBackend) m (Map (Key record) record)
-> ReaderT SqlReadBackend m (Map (Key record) record)
forall a b. (a -> b) -> a -> b
$ [Key record] -> ReaderT SqlBackend m (Map (Key record) record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
[Key record] -> ReaderT backend m (Map (Key record) record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Key record] -> ReaderT SqlBackend m (Map (Key record) record)
getMany [Key record]
ks
instance PersistStoreRead SqlWriteBackend where
get :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
Key record -> ReaderT SqlWriteBackend m (Maybe record)
get Key record
k = ReaderT (BaseBackend SqlWriteBackend) m (Maybe record)
-> ReaderT SqlWriteBackend m (Maybe record)
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m (Maybe record)
-> ReaderT SqlWriteBackend m (Maybe record))
-> ReaderT (BaseBackend SqlWriteBackend) m (Maybe record)
-> ReaderT SqlWriteBackend m (Maybe record)
forall a b. (a -> b) -> a -> b
$ Key record -> ReaderT SqlBackend m (Maybe record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> ReaderT backend m (Maybe record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
Key record -> ReaderT SqlBackend m (Maybe record)
get Key record
k
getMany :: forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlWriteBackend) =>
[Key record] -> ReaderT SqlWriteBackend m (Map (Key record) record)
getMany [Key record]
ks = ReaderT (BaseBackend SqlWriteBackend) m (Map (Key record) record)
-> ReaderT SqlWriteBackend m (Map (Key record) record)
forall backend (m :: * -> *) a.
HasPersistBackend backend =>
ReaderT (BaseBackend backend) m a -> ReaderT backend m a
withBaseBackend (ReaderT (BaseBackend SqlWriteBackend) m (Map (Key record) record)
-> ReaderT SqlWriteBackend m (Map (Key record) record))
-> ReaderT
(BaseBackend SqlWriteBackend) m (Map (Key record) record)
-> ReaderT SqlWriteBackend m (Map (Key record) record)
forall a b. (a -> b) -> a -> b
$ [Key record] -> ReaderT SqlBackend m (Map (Key record) record)
forall backend record (m :: * -> *).
(PersistStoreRead backend, MonadIO m,
PersistRecordBackend record backend) =>
[Key record] -> ReaderT backend m (Map (Key record) record)
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record SqlBackend) =>
[Key record] -> ReaderT SqlBackend m (Map (Key record) record)
getMany [Key record]
ks
dummyFromKey :: Key record -> Maybe record
dummyFromKey :: forall record. Key record -> Maybe record
dummyFromKey = record -> Maybe record
forall a. a -> Maybe a
Just (record -> Maybe record)
-> (Key record -> record) -> Key record -> Maybe record
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key record -> record
forall record. Key record -> record
recordTypeFromKey
recordTypeFromKey :: Key record -> record
recordTypeFromKey :: forall record. Key record -> record
recordTypeFromKey Key record
_ = String -> record
forall a. HasCallStack => String -> a
error String
"dummyFromKey"
insrepHelper :: (MonadIO m, PersistEntity val)
=> Text
-> [Entity val]
-> ReaderT SqlBackend m ()
insrepHelper :: forall (m :: * -> *) val.
(MonadIO m, PersistEntity val) =>
Text -> [Entity val] -> ReaderT SqlBackend m ()
insrepHelper Text
_ [] = () -> ReaderT SqlBackend m ()
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
insrepHelper Text
command [Entity val]
es = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
let columnNames :: [Text]
columnNames = NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList (NonEmpty Text -> [Text]) -> NonEmpty Text -> [Text]
forall a b. (a -> b) -> a -> b
$ EntityDef -> SqlBackend -> NonEmpty Text
keyAndEntityColumnNames EntityDef
entDef SqlBackend
conn
Text -> [PersistValue] -> ReaderT SqlBackend m ()
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m ()
rawExecute (SqlBackend -> [Text] -> Text
sql SqlBackend
conn [Text]
columnNames) [PersistValue]
vals
where
entDef :: EntityDef
entDef = [val] -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy val -> EntityDef
entityDef ([val] -> EntityDef) -> [val] -> EntityDef
forall a b. (a -> b) -> a -> b
$ (Entity val -> val) -> [Entity val] -> [val]
forall a b. (a -> b) -> [a] -> [b]
map Entity val -> val
forall record. Entity record -> record
entityVal [Entity val]
es
sql :: SqlBackend -> [Text] -> Text
sql SqlBackend
conn [Text]
columnNames = [Text] -> Text
T.concat
[ Text
command
, Text
" INTO "
, SqlBackend -> EntityDef -> Text
connEscapeTableName SqlBackend
conn EntityDef
entDef
, Text
"("
, Text -> [Text] -> Text
T.intercalate Text
"," [Text]
columnNames
, Text
") VALUES ("
, Text -> [Text] -> Text
T.intercalate Text
"),(" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> [Text]
forall a. Int -> a -> [a]
replicate ([Entity val] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Entity val]
es) (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"," ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Text -> Text
forall a b. a -> b -> a
const Text
"?") [Text]
columnNames
, Text
")"
]
vals :: [PersistValue]
vals = (Entity val -> [PersistValue]) -> [Entity val] -> [PersistValue]
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap Entity val -> [PersistValue]
forall record.
PersistEntity record =>
Entity record -> [PersistValue]
entityValues [Entity val]
es
runChunked
:: (Monad m)
=> Int
-> ([a] -> ReaderT SqlBackend m ())
-> [a]
-> ReaderT SqlBackend m ()
runChunked :: forall (m :: * -> *) a.
Monad m =>
Int
-> ([a] -> ReaderT SqlBackend m ())
-> [a]
-> ReaderT SqlBackend m ()
runChunked Int
_ [a] -> ReaderT SqlBackend m ()
_ [] = () -> ReaderT SqlBackend m ()
forall a. a -> ReaderT SqlBackend m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
runChunked Int
width [a] -> ReaderT SqlBackend m ()
m [a]
xs = do
SqlBackend
conn <- ReaderT SqlBackend m SqlBackend
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
case SqlBackend -> Maybe Int
connMaxParams SqlBackend
conn of
Maybe Int
Nothing -> [a] -> ReaderT SqlBackend m ()
m [a]
xs
Just Int
maxParams -> let chunkSize :: Int
chunkSize = Int
maxParams Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
width in
([a] -> ReaderT SqlBackend m ())
-> [[a]] -> ReaderT SqlBackend m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [a] -> ReaderT SqlBackend m ()
m (Int -> [a] -> [[a]]
forall a. Int -> [a] -> [[a]]
chunksOf Int
chunkSize [a]
xs)
chunksOf :: Int -> [a] -> [[a]]
chunksOf :: forall a. Int -> [a] -> [[a]]
chunksOf Int
_ [] = []
chunksOf Int
size [a]
xs = let ([a]
chunk, [a]
rest) = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
size [a]
xs in [a]
chunk [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: Int -> [a] -> [[a]]
forall a. Int -> [a] -> [[a]]
chunksOf Int
size [a]
rest