{-# 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 :: 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 (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 =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ConduitM [PersistValue] Void IO a
sink)
toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record
toSqlKey :: 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 :: 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 :: 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 (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 (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
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 :: 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 (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 :: 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 (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
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 :: 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
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 :: 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 (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
persistFieldDef EntityField record typ
rec)
fieldDBName :: forall record typ. (PersistEntity record) => EntityField record typ -> FieldNameDB
fieldDBName :: 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
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
showList :: [BackendKey SqlBackend] -> ShowS
$cshowList :: [BackendKey SqlBackend] -> ShowS
show :: BackendKey SqlBackend -> String
$cshow :: BackendKey SqlBackend -> String
showsPrec :: Int -> BackendKey SqlBackend -> ShowS
$cshowsPrec :: Int -> 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
readListPrec :: ReadPrec [BackendKey SqlBackend]
$creadListPrec :: ReadPrec [BackendKey SqlBackend]
readPrec :: ReadPrec (BackendKey SqlBackend)
$creadPrec :: ReadPrec (BackendKey SqlBackend)
readList :: ReadS [BackendKey SqlBackend]
$creadList :: ReadS [BackendKey SqlBackend]
readsPrec :: Int -> ReadS (BackendKey SqlBackend)
$creadsPrec :: Int -> ReadS (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
/= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c/= :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
== :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
$c== :: 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
min :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cmin :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
max :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cmax :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
>= :: 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
$c< :: BackendKey SqlBackend -> BackendKey SqlBackend -> Bool
compare :: BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering
$ccompare :: BackendKey SqlBackend -> BackendKey SqlBackend -> Ordering
$cp1Ord :: Eq (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
$cto :: forall x. Rep (BackendKey SqlBackend) x -> BackendKey SqlBackend
$cfrom :: forall x. BackendKey SqlBackend -> Rep (BackendKey SqlBackend) x
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
fromInteger :: Integer -> BackendKey SqlBackend
$cfromInteger :: Integer -> BackendKey SqlBackend
signum :: BackendKey SqlBackend -> BackendKey SqlBackend
$csignum :: BackendKey SqlBackend -> BackendKey SqlBackend
abs :: BackendKey SqlBackend -> BackendKey SqlBackend
$cabs :: BackendKey SqlBackend -> BackendKey SqlBackend
negate :: BackendKey SqlBackend -> BackendKey SqlBackend
$cnegate :: 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
$c+ :: BackendKey SqlBackend
-> BackendKey SqlBackend -> 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
toInteger :: BackendKey SqlBackend -> Integer
$ctoInteger :: BackendKey SqlBackend -> Integer
divMod :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
$cdivMod :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
quotRem :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
$cquotRem :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> (BackendKey SqlBackend, BackendKey SqlBackend)
mod :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cmod :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
div :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cdiv :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
rem :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$crem :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
quot :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cquot :: BackendKey SqlBackend
-> BackendKey SqlBackend -> BackendKey SqlBackend
$cp2Integral :: Enum (BackendKey SqlBackend)
$cp1Integral :: Real (BackendKey SqlBackend)
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
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlBackend)
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlBackend)
toPersistValue :: BackendKey SqlBackend -> PersistValue
$ctoPersistValue :: BackendKey SqlBackend -> PersistValue
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
sqlType :: Proxy (BackendKey SqlBackend) -> SqlType
$csqlType :: Proxy (BackendKey SqlBackend) -> SqlType
$cp1PersistFieldSql :: PersistField (BackendKey SqlBackend)
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
toPathPiece :: BackendKey SqlBackend -> Text
$ctoPathPiece :: BackendKey SqlBackend -> Text
fromPathPiece :: Text -> Maybe (BackendKey SqlBackend)
$cfromPathPiece :: Text -> Maybe (BackendKey SqlBackend)
PathPiece, BackendKey SqlBackend -> ByteString
BackendKey SqlBackend -> Builder
BackendKey SqlBackend -> Text
(BackendKey SqlBackend -> Text)
-> (BackendKey SqlBackend -> Builder)
-> (BackendKey SqlBackend -> ByteString)
-> (BackendKey SqlBackend -> Text)
-> ToHttpApiData (BackendKey SqlBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> ToHttpApiData a
toQueryParam :: BackendKey SqlBackend -> Text
$ctoQueryParam :: BackendKey SqlBackend -> Text
toHeader :: BackendKey SqlBackend -> ByteString
$ctoHeader :: BackendKey SqlBackend -> ByteString
toEncodedUrlPiece :: BackendKey SqlBackend -> Builder
$ctoEncodedUrlPiece :: BackendKey SqlBackend -> Builder
toUrlPiece :: BackendKey SqlBackend -> Text
$ctoUrlPiece :: BackendKey SqlBackend -> Text
ToHttpApiData, ByteString -> Either Text (BackendKey SqlBackend)
Text -> 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
parseQueryParam :: Text -> Either Text (BackendKey SqlBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlBackend)
$cparseUrlPiece :: 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
toRational :: BackendKey SqlBackend -> Rational
$ctoRational :: BackendKey SqlBackend -> Rational
$cp2Real :: Ord (BackendKey SqlBackend)
$cp1Real :: Num (BackendKey SqlBackend)
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
enumFromThenTo :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend]
$cenumFromThenTo :: BackendKey SqlBackend
-> BackendKey SqlBackend
-> BackendKey SqlBackend
-> [BackendKey SqlBackend]
enumFromTo :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFromTo :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
enumFromThen :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFromThen :: BackendKey SqlBackend
-> BackendKey SqlBackend -> [BackendKey SqlBackend]
enumFrom :: BackendKey SqlBackend -> [BackendKey SqlBackend]
$cenumFrom :: BackendKey SqlBackend -> [BackendKey SqlBackend]
fromEnum :: BackendKey SqlBackend -> Int
$cfromEnum :: BackendKey SqlBackend -> Int
toEnum :: Int -> BackendKey SqlBackend
$ctoEnum :: Int -> BackendKey SqlBackend
pred :: BackendKey SqlBackend -> BackendKey SqlBackend
$cpred :: BackendKey SqlBackend -> BackendKey SqlBackend
succ :: BackendKey SqlBackend -> BackendKey SqlBackend
$csucc :: BackendKey SqlBackend -> BackendKey SqlBackend
Enum, BackendKey SqlBackend
BackendKey SqlBackend
-> BackendKey SqlBackend -> Bounded (BackendKey SqlBackend)
forall a. a -> a -> Bounded a
maxBound :: BackendKey SqlBackend
$cmaxBound :: BackendKey SqlBackend
minBound :: BackendKey SqlBackend
$cminBound :: BackendKey SqlBackend
Bounded, [BackendKey SqlBackend] -> Encoding
[BackendKey SqlBackend] -> Value
BackendKey SqlBackend -> Encoding
BackendKey SqlBackend -> Value
(BackendKey SqlBackend -> Value)
-> (BackendKey SqlBackend -> Encoding)
-> ([BackendKey SqlBackend] -> Value)
-> ([BackendKey SqlBackend] -> Encoding)
-> ToJSON (BackendKey SqlBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BackendKey SqlBackend] -> Encoding
$ctoEncodingList :: [BackendKey SqlBackend] -> Encoding
toJSONList :: [BackendKey SqlBackend] -> Value
$ctoJSONList :: [BackendKey SqlBackend] -> Value
toEncoding :: BackendKey SqlBackend -> Encoding
$ctoEncoding :: BackendKey SqlBackend -> Encoding
toJSON :: BackendKey SqlBackend -> Value
$ctoJSON :: BackendKey SqlBackend -> Value
A.ToJSON, Value -> Parser [BackendKey SqlBackend]
Value -> Parser (BackendKey SqlBackend)
(Value -> Parser (BackendKey SqlBackend))
-> (Value -> Parser [BackendKey SqlBackend])
-> FromJSON (BackendKey SqlBackend)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BackendKey SqlBackend]
$cparseJSONList :: Value -> Parser [BackendKey SqlBackend]
parseJSON :: Value -> Parser (BackendKey SqlBackend)
$cparseJSON :: Value -> Parser (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
showList :: [BackendKey SqlReadBackend] -> ShowS
$cshowList :: [BackendKey SqlReadBackend] -> ShowS
show :: BackendKey SqlReadBackend -> String
$cshow :: BackendKey SqlReadBackend -> String
showsPrec :: Int -> BackendKey SqlReadBackend -> ShowS
$cshowsPrec :: Int -> 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
readListPrec :: ReadPrec [BackendKey SqlReadBackend]
$creadListPrec :: ReadPrec [BackendKey SqlReadBackend]
readPrec :: ReadPrec (BackendKey SqlReadBackend)
$creadPrec :: ReadPrec (BackendKey SqlReadBackend)
readList :: ReadS [BackendKey SqlReadBackend]
$creadList :: ReadS [BackendKey SqlReadBackend]
readsPrec :: Int -> ReadS (BackendKey SqlReadBackend)
$creadsPrec :: Int -> ReadS (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
/= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c/= :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
== :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
$c== :: 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
min :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cmin :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
max :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cmax :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
>= :: 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
$c< :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Bool
compare :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Ordering
$ccompare :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend -> Ordering
$cp1Ord :: Eq (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
$cto :: forall x.
Rep (BackendKey SqlReadBackend) x -> BackendKey SqlReadBackend
$cfrom :: forall x.
BackendKey SqlReadBackend -> Rep (BackendKey SqlReadBackend) x
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
fromInteger :: Integer -> BackendKey SqlReadBackend
$cfromInteger :: Integer -> BackendKey SqlReadBackend
signum :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$csignum :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
abs :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cabs :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
negate :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cnegate :: 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
$c+ :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> 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
toInteger :: BackendKey SqlReadBackend -> Integer
$ctoInteger :: BackendKey SqlReadBackend -> Integer
divMod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
$cdivMod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
quotRem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
$cquotRem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> (BackendKey SqlReadBackend, BackendKey SqlReadBackend)
mod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cmod :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
div :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cdiv :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
rem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$crem :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
quot :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cquot :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cp2Integral :: Enum (BackendKey SqlReadBackend)
$cp1Integral :: Real (BackendKey SqlReadBackend)
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
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlReadBackend)
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlReadBackend)
toPersistValue :: BackendKey SqlReadBackend -> PersistValue
$ctoPersistValue :: BackendKey SqlReadBackend -> PersistValue
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
sqlType :: Proxy (BackendKey SqlReadBackend) -> SqlType
$csqlType :: Proxy (BackendKey SqlReadBackend) -> SqlType
$cp1PersistFieldSql :: PersistField (BackendKey SqlReadBackend)
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
toPathPiece :: BackendKey SqlReadBackend -> Text
$ctoPathPiece :: BackendKey SqlReadBackend -> Text
fromPathPiece :: Text -> Maybe (BackendKey SqlReadBackend)
$cfromPathPiece :: Text -> Maybe (BackendKey SqlReadBackend)
PathPiece, BackendKey SqlReadBackend -> ByteString
BackendKey SqlReadBackend -> Builder
BackendKey SqlReadBackend -> Text
(BackendKey SqlReadBackend -> Text)
-> (BackendKey SqlReadBackend -> Builder)
-> (BackendKey SqlReadBackend -> ByteString)
-> (BackendKey SqlReadBackend -> Text)
-> ToHttpApiData (BackendKey SqlReadBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> ToHttpApiData a
toQueryParam :: BackendKey SqlReadBackend -> Text
$ctoQueryParam :: BackendKey SqlReadBackend -> Text
toHeader :: BackendKey SqlReadBackend -> ByteString
$ctoHeader :: BackendKey SqlReadBackend -> ByteString
toEncodedUrlPiece :: BackendKey SqlReadBackend -> Builder
$ctoEncodedUrlPiece :: BackendKey SqlReadBackend -> Builder
toUrlPiece :: BackendKey SqlReadBackend -> Text
$ctoUrlPiece :: BackendKey SqlReadBackend -> Text
ToHttpApiData, ByteString -> Either Text (BackendKey SqlReadBackend)
Text -> 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
parseQueryParam :: Text -> Either Text (BackendKey SqlReadBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlReadBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlReadBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlReadBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlReadBackend)
$cparseUrlPiece :: 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
toRational :: BackendKey SqlReadBackend -> Rational
$ctoRational :: BackendKey SqlReadBackend -> Rational
$cp2Real :: Ord (BackendKey SqlReadBackend)
$cp1Real :: Num (BackendKey SqlReadBackend)
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
enumFromThenTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend]
$cenumFromThenTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> BackendKey SqlReadBackend
-> [BackendKey SqlReadBackend]
enumFromTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFromTo :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
enumFromThen :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFromThen :: BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
enumFrom :: BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
$cenumFrom :: BackendKey SqlReadBackend -> [BackendKey SqlReadBackend]
fromEnum :: BackendKey SqlReadBackend -> Int
$cfromEnum :: BackendKey SqlReadBackend -> Int
toEnum :: Int -> BackendKey SqlReadBackend
$ctoEnum :: Int -> BackendKey SqlReadBackend
pred :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$cpred :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
succ :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
$csucc :: BackendKey SqlReadBackend -> BackendKey SqlReadBackend
Enum, BackendKey SqlReadBackend
BackendKey SqlReadBackend
-> BackendKey SqlReadBackend -> Bounded (BackendKey SqlReadBackend)
forall a. a -> a -> Bounded a
maxBound :: BackendKey SqlReadBackend
$cmaxBound :: BackendKey SqlReadBackend
minBound :: BackendKey SqlReadBackend
$cminBound :: BackendKey SqlReadBackend
Bounded, [BackendKey SqlReadBackend] -> Encoding
[BackendKey SqlReadBackend] -> Value
BackendKey SqlReadBackend -> Encoding
BackendKey SqlReadBackend -> Value
(BackendKey SqlReadBackend -> Value)
-> (BackendKey SqlReadBackend -> Encoding)
-> ([BackendKey SqlReadBackend] -> Value)
-> ([BackendKey SqlReadBackend] -> Encoding)
-> ToJSON (BackendKey SqlReadBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BackendKey SqlReadBackend] -> Encoding
$ctoEncodingList :: [BackendKey SqlReadBackend] -> Encoding
toJSONList :: [BackendKey SqlReadBackend] -> Value
$ctoJSONList :: [BackendKey SqlReadBackend] -> Value
toEncoding :: BackendKey SqlReadBackend -> Encoding
$ctoEncoding :: BackendKey SqlReadBackend -> Encoding
toJSON :: BackendKey SqlReadBackend -> Value
$ctoJSON :: BackendKey SqlReadBackend -> Value
A.ToJSON, Value -> Parser [BackendKey SqlReadBackend]
Value -> Parser (BackendKey SqlReadBackend)
(Value -> Parser (BackendKey SqlReadBackend))
-> (Value -> Parser [BackendKey SqlReadBackend])
-> FromJSON (BackendKey SqlReadBackend)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BackendKey SqlReadBackend]
$cparseJSONList :: Value -> Parser [BackendKey SqlReadBackend]
parseJSON :: Value -> Parser (BackendKey SqlReadBackend)
$cparseJSON :: Value -> Parser (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
showList :: [BackendKey SqlWriteBackend] -> ShowS
$cshowList :: [BackendKey SqlWriteBackend] -> ShowS
show :: BackendKey SqlWriteBackend -> String
$cshow :: BackendKey SqlWriteBackend -> String
showsPrec :: Int -> BackendKey SqlWriteBackend -> ShowS
$cshowsPrec :: Int -> 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
readListPrec :: ReadPrec [BackendKey SqlWriteBackend]
$creadListPrec :: ReadPrec [BackendKey SqlWriteBackend]
readPrec :: ReadPrec (BackendKey SqlWriteBackend)
$creadPrec :: ReadPrec (BackendKey SqlWriteBackend)
readList :: ReadS [BackendKey SqlWriteBackend]
$creadList :: ReadS [BackendKey SqlWriteBackend]
readsPrec :: Int -> ReadS (BackendKey SqlWriteBackend)
$creadsPrec :: Int -> ReadS (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
/= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c/= :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
== :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
$c== :: 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
min :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cmin :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
max :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cmax :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
>= :: 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
$c< :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend -> Bool
compare :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering
$ccompare :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> Ordering
$cp1Ord :: Eq (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
$cto :: forall x.
Rep (BackendKey SqlWriteBackend) x -> BackendKey SqlWriteBackend
$cfrom :: forall x.
BackendKey SqlWriteBackend -> Rep (BackendKey SqlWriteBackend) x
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
fromInteger :: Integer -> BackendKey SqlWriteBackend
$cfromInteger :: Integer -> BackendKey SqlWriteBackend
signum :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$csignum :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
abs :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cabs :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
negate :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cnegate :: 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
$c+ :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> 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
toInteger :: BackendKey SqlWriteBackend -> Integer
$ctoInteger :: BackendKey SqlWriteBackend -> Integer
divMod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
$cdivMod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
quotRem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
$cquotRem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> (BackendKey SqlWriteBackend, BackendKey SqlWriteBackend)
mod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cmod :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
div :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cdiv :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
rem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$crem :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
quot :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cquot :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cp2Integral :: Enum (BackendKey SqlWriteBackend)
$cp1Integral :: Real (BackendKey SqlWriteBackend)
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
fromPersistValue :: PersistValue -> Either Text (BackendKey SqlWriteBackend)
$cfromPersistValue :: PersistValue -> Either Text (BackendKey SqlWriteBackend)
toPersistValue :: BackendKey SqlWriteBackend -> PersistValue
$ctoPersistValue :: BackendKey SqlWriteBackend -> PersistValue
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
sqlType :: Proxy (BackendKey SqlWriteBackend) -> SqlType
$csqlType :: Proxy (BackendKey SqlWriteBackend) -> SqlType
$cp1PersistFieldSql :: PersistField (BackendKey SqlWriteBackend)
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
toPathPiece :: BackendKey SqlWriteBackend -> Text
$ctoPathPiece :: BackendKey SqlWriteBackend -> Text
fromPathPiece :: Text -> Maybe (BackendKey SqlWriteBackend)
$cfromPathPiece :: Text -> Maybe (BackendKey SqlWriteBackend)
PathPiece, BackendKey SqlWriteBackend -> ByteString
BackendKey SqlWriteBackend -> Builder
BackendKey SqlWriteBackend -> Text
(BackendKey SqlWriteBackend -> Text)
-> (BackendKey SqlWriteBackend -> Builder)
-> (BackendKey SqlWriteBackend -> ByteString)
-> (BackendKey SqlWriteBackend -> Text)
-> ToHttpApiData (BackendKey SqlWriteBackend)
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> ToHttpApiData a
toQueryParam :: BackendKey SqlWriteBackend -> Text
$ctoQueryParam :: BackendKey SqlWriteBackend -> Text
toHeader :: BackendKey SqlWriteBackend -> ByteString
$ctoHeader :: BackendKey SqlWriteBackend -> ByteString
toEncodedUrlPiece :: BackendKey SqlWriteBackend -> Builder
$ctoEncodedUrlPiece :: BackendKey SqlWriteBackend -> Builder
toUrlPiece :: BackendKey SqlWriteBackend -> Text
$ctoUrlPiece :: BackendKey SqlWriteBackend -> Text
ToHttpApiData, ByteString -> Either Text (BackendKey SqlWriteBackend)
Text -> 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
parseQueryParam :: Text -> Either Text (BackendKey SqlWriteBackend)
$cparseQueryParam :: Text -> Either Text (BackendKey SqlWriteBackend)
parseHeader :: ByteString -> Either Text (BackendKey SqlWriteBackend)
$cparseHeader :: ByteString -> Either Text (BackendKey SqlWriteBackend)
parseUrlPiece :: Text -> Either Text (BackendKey SqlWriteBackend)
$cparseUrlPiece :: 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
toRational :: BackendKey SqlWriteBackend -> Rational
$ctoRational :: BackendKey SqlWriteBackend -> Rational
$cp2Real :: Ord (BackendKey SqlWriteBackend)
$cp1Real :: Num (BackendKey SqlWriteBackend)
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
enumFromThenTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend]
$cenumFromThenTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> [BackendKey SqlWriteBackend]
enumFromTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFromTo :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
enumFromThen :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFromThen :: BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
enumFrom :: BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
$cenumFrom :: BackendKey SqlWriteBackend -> [BackendKey SqlWriteBackend]
fromEnum :: BackendKey SqlWriteBackend -> Int
$cfromEnum :: BackendKey SqlWriteBackend -> Int
toEnum :: Int -> BackendKey SqlWriteBackend
$ctoEnum :: Int -> BackendKey SqlWriteBackend
pred :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$cpred :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
succ :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
$csucc :: BackendKey SqlWriteBackend -> BackendKey SqlWriteBackend
Enum, BackendKey SqlWriteBackend
BackendKey SqlWriteBackend
-> BackendKey SqlWriteBackend
-> Bounded (BackendKey SqlWriteBackend)
forall a. a -> a -> Bounded a
maxBound :: BackendKey SqlWriteBackend
$cmaxBound :: BackendKey SqlWriteBackend
minBound :: BackendKey SqlWriteBackend
$cminBound :: BackendKey SqlWriteBackend
Bounded, [BackendKey SqlWriteBackend] -> Encoding
[BackendKey SqlWriteBackend] -> Value
BackendKey SqlWriteBackend -> Encoding
BackendKey SqlWriteBackend -> Value
(BackendKey SqlWriteBackend -> Value)
-> (BackendKey SqlWriteBackend -> Encoding)
-> ([BackendKey SqlWriteBackend] -> Value)
-> ([BackendKey SqlWriteBackend] -> Encoding)
-> ToJSON (BackendKey SqlWriteBackend)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BackendKey SqlWriteBackend] -> Encoding
$ctoEncodingList :: [BackendKey SqlWriteBackend] -> Encoding
toJSONList :: [BackendKey SqlWriteBackend] -> Value
$ctoJSONList :: [BackendKey SqlWriteBackend] -> Value
toEncoding :: BackendKey SqlWriteBackend -> Encoding
$ctoEncoding :: BackendKey SqlWriteBackend -> Encoding
toJSON :: BackendKey SqlWriteBackend -> Value
$ctoJSON :: BackendKey SqlWriteBackend -> Value
A.ToJSON, Value -> Parser [BackendKey SqlWriteBackend]
Value -> Parser (BackendKey SqlWriteBackend)
(Value -> Parser (BackendKey SqlWriteBackend))
-> (Value -> Parser [BackendKey SqlWriteBackend])
-> FromJSON (BackendKey SqlWriteBackend)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BackendKey SqlWriteBackend]
$cparseJSONList :: Value -> Parser [BackendKey SqlWriteBackend]
parseJSON :: Value -> Parser (BackendKey SqlWriteBackend)
$cparseJSON :: Value -> Parser (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 :: Key record -> [Update record] -> ReaderT SqlBackend m ()
update Key record
_ [] = () -> ReaderT SqlBackend m ()
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
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 :: 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 (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 (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 (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 (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 (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 (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 (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 (m :: * -> *) a. Monad m => a -> m a
return Key record
key
where
tshow :: Show a => a -> Text
tshow :: 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 (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
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 :: [record] -> ReaderT SqlBackend m [Key record]
insertMany [] = [Key record] -> ReaderT SqlBackend m [Key record]
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)
mapM record -> ReaderT SqlBackend m (Key record)
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
record -> ReaderT backend 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
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_ :: [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 (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
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 (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 :: 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
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 :: 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 :: [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
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 (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 :: Key record -> record -> ReaderT SqlBackend m ()
repsert Key record
key record
value = do
Maybe record
mExisting <- 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)
get Key record
key
case Maybe record
mExisting of
Maybe record
Nothing -> Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
insertKey Key record
key record
value
Just record
_ -> Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
replace Key record
key record
value
repsertMany :: [(Key record, record)] -> ReaderT SqlBackend m ()
repsertMany [] = () -> ReaderT SqlBackend m ()
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 (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
entityDef [record]
rs
let nr :: Int
nr = [(Key record, record)] -> 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 ())
-> (Key record, record) -> ReaderT SqlBackend m ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Key record -> record -> ReaderT SqlBackend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> record -> ReaderT backend m ()
repsert) [(Key record, record)]
krs
delete :: 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
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 :: 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) =>
record -> ReaderT backend m (Key record)
insert record
v
insertMany :: [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) =>
[record] -> ReaderT backend m [Key record]
insertMany [record]
vs
insertMany_ :: [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) =>
[record] -> ReaderT backend m ()
insertMany_ [record]
vs
insertEntityMany :: [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 ()
insertEntityMany [Entity record]
vs
insertKey :: 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 ()
insertKey Key record
k record
v
repsert :: 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 ()
repsert Key record
k record
v
replace :: 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 ()
replace Key record
k record
v
delete :: 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 ()
delete Key record
k
update :: 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 ()
update Key record
k [Update record]
upds
repsertMany :: [(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 ()
repsertMany [(Key record, record)]
krs
instance PersistStoreRead SqlBackend where
get :: 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)
getMany [Key record
k]
Maybe record -> ReaderT SqlBackend m (Maybe record)
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 :: [Key record] -> ReaderT SqlBackend m (Map (Key record) record)
getMany [] = Map (Key record) record
-> ReaderT SqlBackend m (Map (Key record) record)
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
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 (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 (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 (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 (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 ()
-> ConduitM (Entity record) Void IO [Entity record]
-> ConduitM [PersistValue] Void IO [Entity record]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ConduitM (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 (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 (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 :: 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)
get Key record
k
getMany :: [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)
getMany [Key record]
ks
instance PersistStoreRead SqlWriteBackend where
get :: 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)
get Key record
k
getMany :: [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)
getMany [Key record]
ks
dummyFromKey :: Key record -> Maybe record
dummyFromKey :: 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 :: 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 :: Text -> [Entity val] -> ReaderT SqlBackend m ()
insrepHelper Text
_ [] = () -> ReaderT SqlBackend m ()
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 (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
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 (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 (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 (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 :: Int
-> ([a] -> ReaderT SqlBackend m ())
-> [a]
-> ReaderT SqlBackend m ()
runChunked Int
_ [a] -> ReaderT SqlBackend m ()
_ [] = () -> ReaderT SqlBackend m ()
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 :: 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