{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
module Database.Groundhog.Core
(
PersistEntity (..),
PersistValue (..),
PersistField (..),
SinglePersistField (..),
PurePersistField (..),
PrimitivePersistField (..),
Embedded (..),
Projection (..),
Projection',
RestrictionHolder,
Unique,
KeyForBackend (..),
BackendSpecific,
ConstructorMarker,
UniqueMarker,
HFalse,
HTrue,
ZT (..),
Utf8 (..),
fromUtf8,
delim,
Cond (..),
ExprRelation (..),
Update (..),
(~>),
FieldLike (..),
Assignable,
SubField (..),
AutoKeyField (..),
FieldChain,
NeverNull,
UntypedExpr (..),
Expr (..),
Order (..),
HasSelectOptions (..),
SelectOptions (..),
limitTo,
offsetBy,
orderBy,
distinct,
DbTypePrimitive' (..),
DbTypePrimitive,
DbType (..),
EntityDef' (..),
EntityDef,
EmbeddedDef' (..),
EmbeddedDef,
OtherTypeDef' (..),
OtherTypeDef,
ConstructorDef' (..),
ConstructorDef,
Constructor (..),
EntityConstr (..),
IsUniqueKey (..),
UniqueDef' (..),
UniqueDef,
UniqueType (..),
ReferenceActionType (..),
ParentTableReference,
SingleMigration,
NamedMigrations,
Migration,
PersistBackend (..),
PersistBackendConn (..),
Action,
TryAction,
RowStream,
DbDescriptor (..),
ExtractConnection (..),
ConnectionManager (..),
TryConnectionManager (..),
Savepoint (..),
withSavepoint,
runDb,
runDbConn,
runTryDbConn,
runTryDbConn',
runDb',
runDbConn',
)
where
import Control.Exception.Safe (Exception, MonadCatch, SomeException (..), tryAny)
import Control.Monad.Fail (MonadFail)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Reader (MonadReader (..))
import Control.Monad.Trans.Control (MonadBaseControl (..))
import Control.Monad.Trans.Except (ExceptT, runExceptT)
import Control.Monad.Trans.Reader (ReaderT (..), runReaderT)
import Control.Monad.Trans.State (StateT (..))
import Data.Acquire (Acquire)
import Data.ByteString.Char8 (ByteString)
import Data.ByteString.Lazy (toStrict)
import Data.Int (Int64)
import Data.Kind (Constraint, Type)
import Data.Map (Map)
import Data.Semigroup (Semigroup)
import Data.String (IsString)
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
import Data.Text.Lazy.Encoding (encodeUtf8)
import Data.Time (Day, TimeOfDay, UTCTime)
import Data.Time.LocalTime (ZonedTime, zonedTimeToLocalTime, zonedTimeToUTC, zonedTimeZone)
class (PurePersistField (AutoKey v), PurePersistField (DefaultKey v)) => PersistEntity v where
data Field v :: ((Type -> Type) -> Type) -> Type -> Type
data Key v :: Type -> Type
type AutoKey v
type DefaultKey v
type IsSumType v
entityDef :: DbDescriptor db => proxy db -> v -> EntityDef
toEntityPersistValues :: PersistBackend m => v -> m ([PersistValue] -> [PersistValue])
fromEntityPersistValues :: PersistBackend m => [PersistValue] -> m (v, [PersistValue])
getUniques :: v -> (Int, [(String, [PersistValue] -> [PersistValue])])
entityFieldChain :: DbDescriptor db => proxy db -> Field v c a -> FieldChain
data Unique (u :: (Type -> Type) -> Type)
data BackendSpecific
data ConstructorMarker v a
data UniqueMarker v a
data KeyForBackend db v = (DbDescriptor db, PersistEntity v) => KeyForBackend (AutoKeyType db)
data HFalse
data HTrue
data Cond db r
= And (Cond db r) (Cond db r)
| Or (Cond db r) (Cond db r)
| Not (Cond db r)
| Compare ExprRelation (UntypedExpr db r) (UntypedExpr db r)
| CondRaw (QueryRaw db r)
| CondEmpty
data ExprRelation = Eq | Ne | Gt | Lt | Ge | Le deriving (Int -> ExprRelation -> ShowS
[ExprRelation] -> ShowS
ExprRelation -> String
(Int -> ExprRelation -> ShowS)
-> (ExprRelation -> String)
-> ([ExprRelation] -> ShowS)
-> Show ExprRelation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExprRelation] -> ShowS
$cshowList :: [ExprRelation] -> ShowS
show :: ExprRelation -> String
$cshow :: ExprRelation -> String
showsPrec :: Int -> ExprRelation -> ShowS
$cshowsPrec :: Int -> ExprRelation -> ShowS
Show)
data Update db r = forall f a. (Assignable f a, Projection' f db r a) => Update f (UntypedExpr db r)
data Order db r
= forall a f. (Projection' f db r a) => Asc f
| forall a f. (Projection' f db r a) => Desc f
type FieldChain = ((String, DbType), [(String, EmbeddedDef)])
class Projection p a | p -> a where
type ProjectionDb p db :: Constraint
type ProjectionRestriction p r :: Constraint
projectionExprs :: (DbDescriptor db, ProjectionDb p db, ProjectionRestriction p r) => p -> [UntypedExpr db r] -> [UntypedExpr db r]
projectionResult :: PersistBackend m => p -> [PersistValue] -> m (a, [PersistValue])
class (Projection p a, ProjectionDb p db, ProjectionRestriction p r) => Projection' p db r a
instance (Projection p a, ProjectionDb p db, ProjectionRestriction p r) => Projection' p db r a
class Projection f a => Assignable f a | f -> a
class Assignable f a => FieldLike f a | f -> a where
fieldChain :: (DbDescriptor db, ProjectionDb f db) => proxy db -> f -> FieldChain
class PersistField v => Embedded v where
data Selector v :: Type -> Type
selectorNum :: Selector v a -> Int
infixl 5 ~>
(~>) :: (EntityConstr v c, FieldLike f a, DbDescriptor db, Projection' f db (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField db v c a'
f
field ~> :: f -> Selector a a' -> SubField db v c a'
~> Selector a a'
sel = SubField db v c a'
subField
where
subField :: SubField db v c a'
subField = case Any db -> f -> FieldChain
forall f a db (proxy :: * -> *).
(FieldLike f a, DbDescriptor db, ProjectionDb f db) =>
proxy db -> f -> FieldChain
fieldChain Any db
db f
field of
((String
name, DbType
typ), [(String, EmbeddedDef)]
prefix) -> case DbType
typ of
DbEmbedded emb :: EmbeddedDef
emb@(EmbeddedDef Bool
_ [(String, DbType)]
ts) Maybe ParentTableReference
_ -> FieldChain -> SubField db v c a'
forall db v (c :: (* -> *) -> *) a. FieldChain -> SubField db v c a
SubField ([(String, DbType)]
ts [(String, DbType)] -> Int -> (String, DbType)
forall a. [a] -> Int -> a
!! Selector a a' -> Int
forall v a. Embedded v => Selector v a -> Int
selectorNum Selector a a'
sel, (String
name, EmbeddedDef
emb) (String, EmbeddedDef)
-> [(String, EmbeddedDef)] -> [(String, EmbeddedDef)]
forall a. a -> [a] -> [a]
: [(String, EmbeddedDef)]
prefix)
DbType
other -> String -> SubField db v c a'
forall a. HasCallStack => String -> a
error (String -> SubField db v c a') -> String -> SubField db v c a'
forall a b. (a -> b) -> a -> b
$ String
"(~>): cannot get subfield of non-embedded type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ DbType -> String
forall a. Show a => a -> String
show DbType
other
db :: Any db
db = (forall db v (c :: (* -> *) -> *) a' (proxy :: * -> *).
SubField db v c a' -> proxy db
forall a. HasCallStack => a
undefined :: SubField db v c a' -> proxy db) SubField db v c a'
subField
newtype SubField db v (c :: (Type -> Type) -> Type) a = SubField FieldChain
data AutoKeyField v (c :: (Type -> Type) -> Type) where
AutoKeyField :: AutoKeyField v c
data RestrictionHolder v (c :: (Type -> Type) -> Type)
data SelectOptions db r hasLimit hasOffset hasOrder hasDistinct = SelectOptions
{ SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> Cond db r
condOptions :: Cond db r,
SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> Maybe Int
limitOptions :: Maybe Int,
SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> Maybe Int
offsetOptions :: Maybe Int,
SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> [Order db r]
orderOptions :: [Order db r],
SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> Bool
distinctOptions :: Bool,
SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> [(String, QueryRaw db r)]
dbSpecificOptions :: [(String, QueryRaw db r)]
}
class HasSelectOptions a db r | a -> db r where
type HasLimit a
type HasOffset a
type HasOrder a
type HasDistinct a
getSelectOptions :: a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
instance db' ~ db => HasSelectOptions (Cond db r) db' r where
type HasLimit (Cond db r) = HFalse
type HasOffset (Cond db r) = HFalse
type HasOrder (Cond db r) = HFalse
type HasDistinct (Cond db r) = HFalse
getSelectOptions :: Cond db r
-> SelectOptions
db'
r
(HasLimit (Cond db r))
(HasOffset (Cond db r))
(HasOrder (Cond db r))
(HasDistinct (Cond db r))
getSelectOptions Cond db r
a = Cond db r
-> Maybe Int
-> Maybe Int
-> [Order db r]
-> Bool
-> [(String, QueryRaw db r)]
-> SelectOptions db r HFalse HFalse HFalse HFalse
forall db r hasLimit hasOffset hasOrder hasDistinct.
Cond db r
-> Maybe Int
-> Maybe Int
-> [Order db r]
-> Bool
-> [(String, QueryRaw db r)]
-> SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
SelectOptions Cond db r
a Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing [] Bool
False []
instance db' ~ db => HasSelectOptions (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r where
type HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasLimit
type HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasOffset
type HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasOrder
type HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasDistinct
getSelectOptions :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> SelectOptions
db'
r
(HasLimit
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasOffset
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasOrder
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasDistinct
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
getSelectOptions = SelectOptions db r hasLimit hasOffset hasOrder hasDistinct
-> SelectOptions
db'
r
(HasLimit
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasOffset
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasOrder
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
(HasDistinct
(SelectOptions db r hasLimit hasOffset hasOrder hasDistinct))
forall a. a -> a
id
limitTo :: (HasSelectOptions a db r, HasLimit a ~ HFalse) => a -> Int -> SelectOptions db r HTrue (HasOffset a) (HasOrder a) (HasDistinct a)
limitTo :: a
-> Int
-> SelectOptions
db r HTrue (HasOffset a) (HasOrder a) (HasDistinct a)
limitTo a
opts Int
lim = (a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
forall a db r.
HasSelectOptions a db r =>
a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
getSelectOptions a
opts) {limitOptions :: Maybe Int
limitOptions = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
lim}
offsetBy :: (HasSelectOptions a db r, HasOffset a ~ HFalse) => a -> Int -> SelectOptions db r (HasLimit a) HTrue (HasOrder a) (HasDistinct a)
offsetBy :: a
-> Int
-> SelectOptions
db r (HasLimit a) HTrue (HasOrder a) (HasDistinct a)
offsetBy a
opts Int
off = (a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
forall a db r.
HasSelectOptions a db r =>
a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
getSelectOptions a
opts) {offsetOptions :: Maybe Int
offsetOptions = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
off}
orderBy :: (HasSelectOptions a db r, HasOrder a ~ HFalse) => a -> [Order db r] -> SelectOptions db r (HasLimit a) (HasOffset a) HTrue (HasDistinct a)
orderBy :: a
-> [Order db r]
-> SelectOptions
db r (HasLimit a) (HasOffset a) HTrue (HasDistinct a)
orderBy a
opts [Order db r]
ord = (a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
forall a db r.
HasSelectOptions a db r =>
a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
getSelectOptions a
opts) {orderOptions :: [Order db r]
orderOptions = [Order db r]
ord}
distinct :: (HasSelectOptions a db r, HasDistinct a ~ HFalse) => a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) HTrue
distinct :: a
-> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) HTrue
distinct a
opts = (a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
forall a db r.
HasSelectOptions a db r =>
a
-> SelectOptions
db r (HasLimit a) (HasOffset a) (HasOrder a) (HasDistinct a)
getSelectOptions a
opts) {distinctOptions :: Bool
distinctOptions = Bool
True}
class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where
type AutoKeyType db
type QueryRaw db :: Type -> Type
backendName :: proxy db -> String
class (DbDescriptor conn, ConnectionManager conn) => PersistBackendConn conn where
insert :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (AutoKey v)
insert_ :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()
insertBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m (Either (AutoKey v) (AutoKey v))
insertByAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (Either (AutoKey v) (AutoKey v))
replace :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> v -> m ()
replaceBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m ()
select ::
(PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) =>
opts ->
m [v]
selectStream ::
(PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) =>
opts ->
m (RowStream v)
selectAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => m [(AutoKey v, v)]
selectAllStream :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => m (RowStream (AutoKey v, v))
get :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m (Maybe v)
getBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => Key v (Unique u) -> m (Maybe v)
update :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => [Update conn (RestrictionHolder v c)] -> Cond conn (RestrictionHolder v c) -> m ()
delete :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m ()
deleteBy :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m ()
deleteAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m ()
count :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m Int
countAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m Int
project ::
(PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) =>
p ->
opts ->
m [a]
projectStream ::
(PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) =>
p ->
opts ->
m (RowStream a)
migrate :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m
executeRaw ::
(PersistBackend m, Conn m ~ conn) =>
Bool ->
String ->
[PersistValue] ->
m ()
queryRaw ::
(PersistBackend m, Conn m ~ conn) =>
Bool ->
String ->
[PersistValue] ->
m (RowStream [PersistValue])
insertList :: (PersistField a, PersistBackend m, Conn m ~ conn) => [a] -> m Int64
getList :: (PersistField a, PersistBackend m, Conn m ~ conn) => Int64 -> m [a]
type Action conn = ReaderT conn IO
type TryAction e m conn = ReaderT conn (ExceptT e m)
type RowStream a = Acquire (IO (Maybe a))
type Migration m = StateT NamedMigrations m ()
type NamedMigrations = Map String SingleMigration
type SingleMigration = Either [String] [(Bool, Int, String)]
data EntityDef' str dbType = EntityDef
{
EntityDef' str dbType -> str
entityName :: str,
EntityDef' str dbType -> Maybe str
entitySchema :: Maybe str,
EntityDef' str dbType -> [dbType]
typeParams :: [dbType],
EntityDef' str dbType -> [ConstructorDef' str dbType]
constructors :: [ConstructorDef' str dbType]
}
deriving (Int -> EntityDef' str dbType -> ShowS
[EntityDef' str dbType] -> ShowS
EntityDef' str dbType -> String
(Int -> EntityDef' str dbType -> ShowS)
-> (EntityDef' str dbType -> String)
-> ([EntityDef' str dbType] -> ShowS)
-> Show (EntityDef' str dbType)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall str dbType.
(Show str, Show dbType) =>
Int -> EntityDef' str dbType -> ShowS
forall str dbType.
(Show str, Show dbType) =>
[EntityDef' str dbType] -> ShowS
forall str dbType.
(Show str, Show dbType) =>
EntityDef' str dbType -> String
showList :: [EntityDef' str dbType] -> ShowS
$cshowList :: forall str dbType.
(Show str, Show dbType) =>
[EntityDef' str dbType] -> ShowS
show :: EntityDef' str dbType -> String
$cshow :: forall str dbType.
(Show str, Show dbType) =>
EntityDef' str dbType -> String
showsPrec :: Int -> EntityDef' str dbType -> ShowS
$cshowsPrec :: forall str dbType.
(Show str, Show dbType) =>
Int -> EntityDef' str dbType -> ShowS
Show, EntityDef' str dbType -> EntityDef' str dbType -> Bool
(EntityDef' str dbType -> EntityDef' str dbType -> Bool)
-> (EntityDef' str dbType -> EntityDef' str dbType -> Bool)
-> Eq (EntityDef' str dbType)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall str dbType.
(Eq str, Eq dbType) =>
EntityDef' str dbType -> EntityDef' str dbType -> Bool
/= :: EntityDef' str dbType -> EntityDef' str dbType -> Bool
$c/= :: forall str dbType.
(Eq str, Eq dbType) =>
EntityDef' str dbType -> EntityDef' str dbType -> Bool
== :: EntityDef' str dbType -> EntityDef' str dbType -> Bool
$c== :: forall str dbType.
(Eq str, Eq dbType) =>
EntityDef' str dbType -> EntityDef' str dbType -> Bool
Eq)
type EntityDef = EntityDef' String DbType
data ConstructorDef' str dbType = ConstructorDef
{
ConstructorDef' str dbType -> str
constrName :: str,
ConstructorDef' str dbType -> Maybe str
constrAutoKeyName :: Maybe str,
ConstructorDef' str dbType -> [(str, dbType)]
constrParams :: [(str, dbType)],
ConstructorDef' str dbType
-> [UniqueDef' str (Either (str, dbType) str)]
constrUniques :: [UniqueDef' str (Either (str, dbType) str)]
}
deriving (Int -> ConstructorDef' str dbType -> ShowS
[ConstructorDef' str dbType] -> ShowS
ConstructorDef' str dbType -> String
(Int -> ConstructorDef' str dbType -> ShowS)
-> (ConstructorDef' str dbType -> String)
-> ([ConstructorDef' str dbType] -> ShowS)
-> Show (ConstructorDef' str dbType)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall str dbType.
(Show str, Show dbType) =>
Int -> ConstructorDef' str dbType -> ShowS
forall str dbType.
(Show str, Show dbType) =>
[ConstructorDef' str dbType] -> ShowS
forall str dbType.
(Show str, Show dbType) =>
ConstructorDef' str dbType -> String
showList :: [ConstructorDef' str dbType] -> ShowS
$cshowList :: forall str dbType.
(Show str, Show dbType) =>
[ConstructorDef' str dbType] -> ShowS
show :: ConstructorDef' str dbType -> String
$cshow :: forall str dbType.
(Show str, Show dbType) =>
ConstructorDef' str dbType -> String
showsPrec :: Int -> ConstructorDef' str dbType -> ShowS
$cshowsPrec :: forall str dbType.
(Show str, Show dbType) =>
Int -> ConstructorDef' str dbType -> ShowS
Show, ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
(ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool)
-> (ConstructorDef' str dbType
-> ConstructorDef' str dbType -> Bool)
-> Eq (ConstructorDef' str dbType)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall str dbType.
(Eq str, Eq dbType) =>
ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
/= :: ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
$c/= :: forall str dbType.
(Eq str, Eq dbType) =>
ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
== :: ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
$c== :: forall str dbType.
(Eq str, Eq dbType) =>
ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool
Eq)
type ConstructorDef = ConstructorDef' String DbType
class Constructor c where
phantomConstrNum :: c (a :: Type -> Type) -> Int
class PersistEntity v => EntityConstr v c where
entityConstrNum :: proxy v -> c (a :: Type -> Type) -> Int
class PurePersistField uKey => IsUniqueKey uKey where
:: uKey ~ Key v u => v -> uKey
uniqueNum :: uKey -> Int
data UniqueDef' str field = UniqueDef
{ UniqueDef' str field -> Maybe str
uniqueDefName :: Maybe str,
UniqueDef' str field -> UniqueType
uniqueDefType :: UniqueType,
UniqueDef' str field -> [field]
uniqueDefFields :: [field]
}
deriving (Int -> UniqueDef' str field -> ShowS
[UniqueDef' str field] -> ShowS
UniqueDef' str field -> String
(Int -> UniqueDef' str field -> ShowS)
-> (UniqueDef' str field -> String)
-> ([UniqueDef' str field] -> ShowS)
-> Show (UniqueDef' str field)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall str field.
(Show str, Show field) =>
Int -> UniqueDef' str field -> ShowS
forall str field.
(Show str, Show field) =>
[UniqueDef' str field] -> ShowS
forall str field.
(Show str, Show field) =>
UniqueDef' str field -> String
showList :: [UniqueDef' str field] -> ShowS
$cshowList :: forall str field.
(Show str, Show field) =>
[UniqueDef' str field] -> ShowS
show :: UniqueDef' str field -> String
$cshow :: forall str field.
(Show str, Show field) =>
UniqueDef' str field -> String
showsPrec :: Int -> UniqueDef' str field -> ShowS
$cshowsPrec :: forall str field.
(Show str, Show field) =>
Int -> UniqueDef' str field -> ShowS
Show, UniqueDef' str field -> UniqueDef' str field -> Bool
(UniqueDef' str field -> UniqueDef' str field -> Bool)
-> (UniqueDef' str field -> UniqueDef' str field -> Bool)
-> Eq (UniqueDef' str field)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall str field.
(Eq str, Eq field) =>
UniqueDef' str field -> UniqueDef' str field -> Bool
/= :: UniqueDef' str field -> UniqueDef' str field -> Bool
$c/= :: forall str field.
(Eq str, Eq field) =>
UniqueDef' str field -> UniqueDef' str field -> Bool
== :: UniqueDef' str field -> UniqueDef' str field -> Bool
$c== :: forall str field.
(Eq str, Eq field) =>
UniqueDef' str field -> UniqueDef' str field -> Bool
Eq)
type UniqueDef = UniqueDef' String (Either (String, DbType) String)
data UniqueType
= UniqueConstraint
| UniqueIndex
|
UniquePrimary Bool
deriving (Int -> UniqueType -> ShowS
[UniqueType] -> ShowS
UniqueType -> String
(Int -> UniqueType -> ShowS)
-> (UniqueType -> String)
-> ([UniqueType] -> ShowS)
-> Show UniqueType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniqueType] -> ShowS
$cshowList :: [UniqueType] -> ShowS
show :: UniqueType -> String
$cshow :: UniqueType -> String
showsPrec :: Int -> UniqueType -> ShowS
$cshowsPrec :: Int -> UniqueType -> ShowS
Show, UniqueType -> UniqueType -> Bool
(UniqueType -> UniqueType -> Bool)
-> (UniqueType -> UniqueType -> Bool) -> Eq UniqueType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniqueType -> UniqueType -> Bool
$c/= :: UniqueType -> UniqueType -> Bool
== :: UniqueType -> UniqueType -> Bool
$c== :: UniqueType -> UniqueType -> Bool
Eq, Eq UniqueType
Eq UniqueType
-> (UniqueType -> UniqueType -> Ordering)
-> (UniqueType -> UniqueType -> Bool)
-> (UniqueType -> UniqueType -> Bool)
-> (UniqueType -> UniqueType -> Bool)
-> (UniqueType -> UniqueType -> Bool)
-> (UniqueType -> UniqueType -> UniqueType)
-> (UniqueType -> UniqueType -> UniqueType)
-> Ord UniqueType
UniqueType -> UniqueType -> Bool
UniqueType -> UniqueType -> Ordering
UniqueType -> UniqueType -> UniqueType
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 :: UniqueType -> UniqueType -> UniqueType
$cmin :: UniqueType -> UniqueType -> UniqueType
max :: UniqueType -> UniqueType -> UniqueType
$cmax :: UniqueType -> UniqueType -> UniqueType
>= :: UniqueType -> UniqueType -> Bool
$c>= :: UniqueType -> UniqueType -> Bool
> :: UniqueType -> UniqueType -> Bool
$c> :: UniqueType -> UniqueType -> Bool
<= :: UniqueType -> UniqueType -> Bool
$c<= :: UniqueType -> UniqueType -> Bool
< :: UniqueType -> UniqueType -> Bool
$c< :: UniqueType -> UniqueType -> Bool
compare :: UniqueType -> UniqueType -> Ordering
$ccompare :: UniqueType -> UniqueType -> Ordering
$cp1Ord :: Eq UniqueType
Ord)
data ReferenceActionType
= NoAction
| Restrict
| Cascade
| SetNull
| SetDefault
deriving (ReferenceActionType -> ReferenceActionType -> Bool
(ReferenceActionType -> ReferenceActionType -> Bool)
-> (ReferenceActionType -> ReferenceActionType -> Bool)
-> Eq ReferenceActionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReferenceActionType -> ReferenceActionType -> Bool
$c/= :: ReferenceActionType -> ReferenceActionType -> Bool
== :: ReferenceActionType -> ReferenceActionType -> Bool
$c== :: ReferenceActionType -> ReferenceActionType -> Bool
Eq, Int -> ReferenceActionType -> ShowS
[ReferenceActionType] -> ShowS
ReferenceActionType -> String
(Int -> ReferenceActionType -> ShowS)
-> (ReferenceActionType -> String)
-> ([ReferenceActionType] -> ShowS)
-> Show ReferenceActionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReferenceActionType] -> ShowS
$cshowList :: [ReferenceActionType] -> ShowS
show :: ReferenceActionType -> String
$cshow :: ReferenceActionType -> String
showsPrec :: Int -> ReferenceActionType -> ShowS
$cshowsPrec :: Int -> ReferenceActionType -> ShowS
Show)
data DbTypePrimitive' str
= DbString
| DbInt32
| DbInt64
| DbReal
| DbBool
| DbDay
| DbTime
| DbDayTime
| DbDayTimeZoned
|
DbBlob
| DbOther (OtherTypeDef' str)
deriving (DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
(DbTypePrimitive' str -> DbTypePrimitive' str -> Bool)
-> (DbTypePrimitive' str -> DbTypePrimitive' str -> Bool)
-> Eq (DbTypePrimitive' str)
forall str.
Eq str =>
DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
$c/= :: forall str.
Eq str =>
DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
== :: DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
$c== :: forall str.
Eq str =>
DbTypePrimitive' str -> DbTypePrimitive' str -> Bool
Eq, Int -> DbTypePrimitive' str -> ShowS
[DbTypePrimitive' str] -> ShowS
DbTypePrimitive' str -> String
(Int -> DbTypePrimitive' str -> ShowS)
-> (DbTypePrimitive' str -> String)
-> ([DbTypePrimitive' str] -> ShowS)
-> Show (DbTypePrimitive' str)
forall str. Show str => Int -> DbTypePrimitive' str -> ShowS
forall str. Show str => [DbTypePrimitive' str] -> ShowS
forall str. Show str => DbTypePrimitive' str -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DbTypePrimitive' str] -> ShowS
$cshowList :: forall str. Show str => [DbTypePrimitive' str] -> ShowS
show :: DbTypePrimitive' str -> String
$cshow :: forall str. Show str => DbTypePrimitive' str -> String
showsPrec :: Int -> DbTypePrimitive' str -> ShowS
$cshowsPrec :: forall str. Show str => Int -> DbTypePrimitive' str -> ShowS
Show)
type DbTypePrimitive = DbTypePrimitive' String
data DbType
=
DbTypePrimitive DbTypePrimitive Bool (Maybe String) (Maybe ParentTableReference)
| DbEmbedded EmbeddedDef (Maybe ParentTableReference)
|
DbList String DbType
deriving (DbType -> DbType -> Bool
(DbType -> DbType -> Bool)
-> (DbType -> DbType -> Bool) -> Eq DbType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DbType -> DbType -> Bool
$c/= :: DbType -> DbType -> Bool
== :: DbType -> DbType -> Bool
$c== :: DbType -> DbType -> Bool
Eq, Int -> DbType -> ShowS
[DbType] -> ShowS
DbType -> String
(Int -> DbType -> ShowS)
-> (DbType -> String) -> ([DbType] -> ShowS) -> Show DbType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DbType] -> ShowS
$cshowList :: [DbType] -> ShowS
show :: DbType -> String
$cshow :: DbType -> String
showsPrec :: Int -> DbType -> ShowS
$cshowsPrec :: Int -> DbType -> ShowS
Show)
type ParentTableReference = (Either (EntityDef, Maybe String) ((Maybe String, String), [String]), Maybe ReferenceActionType, Maybe ReferenceActionType)
newtype OtherTypeDef' str = OtherTypeDef [Either str (DbTypePrimitive' str)] deriving (OtherTypeDef' str -> OtherTypeDef' str -> Bool
(OtherTypeDef' str -> OtherTypeDef' str -> Bool)
-> (OtherTypeDef' str -> OtherTypeDef' str -> Bool)
-> Eq (OtherTypeDef' str)
forall str.
Eq str =>
OtherTypeDef' str -> OtherTypeDef' str -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OtherTypeDef' str -> OtherTypeDef' str -> Bool
$c/= :: forall str.
Eq str =>
OtherTypeDef' str -> OtherTypeDef' str -> Bool
== :: OtherTypeDef' str -> OtherTypeDef' str -> Bool
$c== :: forall str.
Eq str =>
OtherTypeDef' str -> OtherTypeDef' str -> Bool
Eq, Int -> OtherTypeDef' str -> ShowS
[OtherTypeDef' str] -> ShowS
OtherTypeDef' str -> String
(Int -> OtherTypeDef' str -> ShowS)
-> (OtherTypeDef' str -> String)
-> ([OtherTypeDef' str] -> ShowS)
-> Show (OtherTypeDef' str)
forall str. Show str => Int -> OtherTypeDef' str -> ShowS
forall str. Show str => [OtherTypeDef' str] -> ShowS
forall str. Show str => OtherTypeDef' str -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OtherTypeDef' str] -> ShowS
$cshowList :: forall str. Show str => [OtherTypeDef' str] -> ShowS
show :: OtherTypeDef' str -> String
$cshow :: forall str. Show str => OtherTypeDef' str -> String
showsPrec :: Int -> OtherTypeDef' str -> ShowS
$cshowsPrec :: forall str. Show str => Int -> OtherTypeDef' str -> ShowS
Show)
type OtherTypeDef = OtherTypeDef' String
data EmbeddedDef' str dbType = EmbeddedDef Bool [(str, dbType)] deriving (EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
(EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool)
-> (EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool)
-> Eq (EmbeddedDef' str dbType)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall str dbType.
(Eq str, Eq dbType) =>
EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
/= :: EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
$c/= :: forall str dbType.
(Eq str, Eq dbType) =>
EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
== :: EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
$c== :: forall str dbType.
(Eq str, Eq dbType) =>
EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool
Eq, Int -> EmbeddedDef' str dbType -> ShowS
[EmbeddedDef' str dbType] -> ShowS
EmbeddedDef' str dbType -> String
(Int -> EmbeddedDef' str dbType -> ShowS)
-> (EmbeddedDef' str dbType -> String)
-> ([EmbeddedDef' str dbType] -> ShowS)
-> Show (EmbeddedDef' str dbType)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall str dbType.
(Show str, Show dbType) =>
Int -> EmbeddedDef' str dbType -> ShowS
forall str dbType.
(Show str, Show dbType) =>
[EmbeddedDef' str dbType] -> ShowS
forall str dbType.
(Show str, Show dbType) =>
EmbeddedDef' str dbType -> String
showList :: [EmbeddedDef' str dbType] -> ShowS
$cshowList :: forall str dbType.
(Show str, Show dbType) =>
[EmbeddedDef' str dbType] -> ShowS
show :: EmbeddedDef' str dbType -> String
$cshow :: forall str dbType.
(Show str, Show dbType) =>
EmbeddedDef' str dbType -> String
showsPrec :: Int -> EmbeddedDef' str dbType -> ShowS
$cshowsPrec :: forall str dbType.
(Show str, Show dbType) =>
Int -> EmbeddedDef' str dbType -> ShowS
Show)
type EmbeddedDef = EmbeddedDef' String DbType
newtype Utf8 = Utf8 Builder
deriving (Utf8 -> Utf8 -> Bool
(Utf8 -> Utf8 -> Bool) -> (Utf8 -> Utf8 -> Bool) -> Eq Utf8
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Utf8 -> Utf8 -> Bool
$c/= :: Utf8 -> Utf8 -> Bool
== :: Utf8 -> Utf8 -> Bool
$c== :: Utf8 -> Utf8 -> Bool
Eq, Eq Utf8
Eq Utf8
-> (Utf8 -> Utf8 -> Ordering)
-> (Utf8 -> Utf8 -> Bool)
-> (Utf8 -> Utf8 -> Bool)
-> (Utf8 -> Utf8 -> Bool)
-> (Utf8 -> Utf8 -> Bool)
-> (Utf8 -> Utf8 -> Utf8)
-> (Utf8 -> Utf8 -> Utf8)
-> Ord Utf8
Utf8 -> Utf8 -> Bool
Utf8 -> Utf8 -> Ordering
Utf8 -> Utf8 -> Utf8
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 :: Utf8 -> Utf8 -> Utf8
$cmin :: Utf8 -> Utf8 -> Utf8
max :: Utf8 -> Utf8 -> Utf8
$cmax :: Utf8 -> Utf8 -> Utf8
>= :: Utf8 -> Utf8 -> Bool
$c>= :: Utf8 -> Utf8 -> Bool
> :: Utf8 -> Utf8 -> Bool
$c> :: Utf8 -> Utf8 -> Bool
<= :: Utf8 -> Utf8 -> Bool
$c<= :: Utf8 -> Utf8 -> Bool
< :: Utf8 -> Utf8 -> Bool
$c< :: Utf8 -> Utf8 -> Bool
compare :: Utf8 -> Utf8 -> Ordering
$ccompare :: Utf8 -> Utf8 -> Ordering
$cp1Ord :: Eq Utf8
Ord, Int -> Utf8 -> ShowS
[Utf8] -> ShowS
Utf8 -> String
(Int -> Utf8 -> ShowS)
-> (Utf8 -> String) -> ([Utf8] -> ShowS) -> Show Utf8
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Utf8] -> ShowS
$cshowList :: [Utf8] -> ShowS
show :: Utf8 -> String
$cshow :: Utf8 -> String
showsPrec :: Int -> Utf8 -> ShowS
$cshowsPrec :: Int -> Utf8 -> ShowS
Show, b -> Utf8 -> Utf8
NonEmpty Utf8 -> Utf8
Utf8 -> Utf8 -> Utf8
(Utf8 -> Utf8 -> Utf8)
-> (NonEmpty Utf8 -> Utf8)
-> (forall b. Integral b => b -> Utf8 -> Utf8)
-> Semigroup Utf8
forall b. Integral b => b -> Utf8 -> Utf8
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> Utf8 -> Utf8
$cstimes :: forall b. Integral b => b -> Utf8 -> Utf8
sconcat :: NonEmpty Utf8 -> Utf8
$csconcat :: NonEmpty Utf8 -> Utf8
<> :: Utf8 -> Utf8 -> Utf8
$c<> :: Utf8 -> Utf8 -> Utf8
Semigroup, Semigroup Utf8
Utf8
Semigroup Utf8
-> Utf8
-> (Utf8 -> Utf8 -> Utf8)
-> ([Utf8] -> Utf8)
-> Monoid Utf8
[Utf8] -> Utf8
Utf8 -> Utf8 -> Utf8
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [Utf8] -> Utf8
$cmconcat :: [Utf8] -> Utf8
mappend :: Utf8 -> Utf8 -> Utf8
$cmappend :: Utf8 -> Utf8 -> Utf8
mempty :: Utf8
$cmempty :: Utf8
$cp1Monoid :: Semigroup Utf8
Monoid, String -> Utf8
(String -> Utf8) -> IsString Utf8
forall a. (String -> a) -> IsString a
fromString :: String -> Utf8
$cfromString :: String -> Utf8
IsString)
fromUtf8 :: Utf8 -> ByteString
fromUtf8 :: Utf8 -> ByteString
fromUtf8 (Utf8 Builder
s) = ByteString -> ByteString
toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ Builder -> Text
toLazyText Builder
s
instance Read Utf8 where
readsPrec :: Int -> ReadS Utf8
readsPrec Int
prec String
str = ((Text, String) -> (Utf8, String))
-> [(Text, String)] -> [(Utf8, String)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Text
a, String
b) -> (Builder -> Utf8
Utf8 (Builder -> Utf8) -> Builder -> Utf8
forall a b. (a -> b) -> a -> b
$ Text -> Builder
fromText Text
a, String
b)) ([(Text, String)] -> [(Utf8, String)])
-> [(Text, String)] -> [(Utf8, String)]
forall a b. (a -> b) -> a -> b
$ Int -> ReadS Text
forall a. Read a => Int -> ReadS a
readsPrec Int
prec String
str
data PersistValue
= PersistString String
| PersistText Text
| PersistByteString ByteString
| PersistInt64 Int64
| PersistDouble Double
| PersistBool Bool
| PersistDay Day
| PersistTimeOfDay TimeOfDay
| PersistUTCTime UTCTime
| PersistZonedTime ZT
| PersistNull
|
PersistCustom Utf8 [PersistValue]
deriving (PersistValue -> PersistValue -> Bool
(PersistValue -> PersistValue -> Bool)
-> (PersistValue -> PersistValue -> Bool) -> Eq PersistValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PersistValue -> PersistValue -> Bool
$c/= :: PersistValue -> PersistValue -> Bool
== :: PersistValue -> PersistValue -> Bool
$c== :: PersistValue -> PersistValue -> Bool
Eq, Int -> PersistValue -> ShowS
[PersistValue] -> ShowS
PersistValue -> String
(Int -> PersistValue -> ShowS)
-> (PersistValue -> String)
-> ([PersistValue] -> ShowS)
-> Show PersistValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PersistValue] -> ShowS
$cshowList :: [PersistValue] -> ShowS
show :: PersistValue -> String
$cshow :: PersistValue -> String
showsPrec :: Int -> PersistValue -> ShowS
$cshowsPrec :: Int -> PersistValue -> ShowS
Show, ReadPrec [PersistValue]
ReadPrec PersistValue
Int -> ReadS PersistValue
ReadS [PersistValue]
(Int -> ReadS PersistValue)
-> ReadS [PersistValue]
-> ReadPrec PersistValue
-> ReadPrec [PersistValue]
-> Read PersistValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PersistValue]
$creadListPrec :: ReadPrec [PersistValue]
readPrec :: ReadPrec PersistValue
$creadPrec :: ReadPrec PersistValue
readList :: ReadS [PersistValue]
$creadList :: ReadS [PersistValue]
readsPrec :: Int -> ReadS PersistValue
$creadsPrec :: Int -> ReadS PersistValue
Read)
newtype ZT = ZT ZonedTime deriving (Int -> ZT -> ShowS
[ZT] -> ShowS
ZT -> String
(Int -> ZT -> ShowS)
-> (ZT -> String) -> ([ZT] -> ShowS) -> Show ZT
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ZT] -> ShowS
$cshowList :: [ZT] -> ShowS
show :: ZT -> String
$cshow :: ZT -> String
showsPrec :: Int -> ZT -> ShowS
$cshowsPrec :: Int -> ZT -> ShowS
Show, ReadPrec [ZT]
ReadPrec ZT
Int -> ReadS ZT
ReadS [ZT]
(Int -> ReadS ZT)
-> ReadS [ZT] -> ReadPrec ZT -> ReadPrec [ZT] -> Read ZT
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ZT]
$creadListPrec :: ReadPrec [ZT]
readPrec :: ReadPrec ZT
$creadPrec :: ReadPrec ZT
readList :: ReadS [ZT]
$creadList :: ReadS [ZT]
readsPrec :: Int -> ReadS ZT
$creadsPrec :: Int -> ReadS ZT
Read)
instance Eq ZT where
ZT ZonedTime
a == :: ZT -> ZT -> Bool
== ZT ZonedTime
b = ZonedTime -> LocalTime
zonedTimeToLocalTime ZonedTime
a LocalTime -> LocalTime -> Bool
forall a. Eq a => a -> a -> Bool
== ZonedTime -> LocalTime
zonedTimeToLocalTime ZonedTime
b Bool -> Bool -> Bool
&& ZonedTime -> TimeZone
zonedTimeZone ZonedTime
a TimeZone -> TimeZone -> Bool
forall a. Eq a => a -> a -> Bool
== ZonedTime -> TimeZone
zonedTimeZone ZonedTime
b
instance Ord ZT where
ZT ZonedTime
a compare :: ZT -> ZT -> Ordering
`compare` ZT ZonedTime
b = ZonedTime -> UTCTime
zonedTimeToUTC ZonedTime
a UTCTime -> UTCTime -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` ZonedTime -> UTCTime
zonedTimeToUTC ZonedTime
b
class NeverNull a
data UntypedExpr db r where
ExprRaw :: DbType -> QueryRaw db r -> UntypedExpr db r
ExprField :: FieldChain -> UntypedExpr db r
ExprPure :: forall db r a. PurePersistField a => a -> UntypedExpr db r
ExprCond :: Cond db r -> UntypedExpr db r
newtype Expr db r a = Expr (UntypedExpr db r)
instance Show (Expr db r a) where show :: Expr db r a -> String
show Expr db r a
_ = String
"Expr"
instance Eq (Expr db r a) where == :: Expr db r a -> Expr db r a -> Bool
(==) = String -> Expr db r a -> Expr db r a -> Bool
forall a. HasCallStack => String -> a
error String
"(==): this instance Eq (Expr db r a) is made only for Num superclass constraint"
class PersistField a where
persistName :: a -> String
toPersistValues :: PersistBackend m => a -> m ([PersistValue] -> [PersistValue])
fromPersistValues :: PersistBackend m => [PersistValue] -> m (a, [PersistValue])
dbType :: DbDescriptor db => proxy db -> a -> DbType
class PersistField a => SinglePersistField a where
toSinglePersistValue :: PersistBackend m => a -> m PersistValue
fromSinglePersistValue :: PersistBackend m => PersistValue -> m a
class PersistField a => PurePersistField a where
toPurePersistValues :: a -> ([PersistValue] -> [PersistValue])
fromPurePersistValues :: [PersistValue] -> (a, [PersistValue])
class PersistField a => PrimitivePersistField a where
toPrimitivePersistValue :: a -> PersistValue
fromPrimitivePersistValue :: PersistValue -> a
delim :: Char
delim :: Char
delim = Char
'#'
class cm conn | cm -> conn where
:: (MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> cm -> m a
class ConnectionManager conn where
withConn :: (MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> conn -> m a
class TryConnectionManager conn where
tryWithConn :: (MonadBaseControl IO m, MonadIO m, MonadCatch m) => (conn -> n a) -> (n a -> m (Either SomeException a)) -> conn -> m (Either SomeException a)
class Savepoint conn where
withConnSavepoint :: (MonadBaseControl IO m, MonadIO m) => String -> m a -> conn -> m a
class (Monad m, MonadIO m, MonadFail m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where
type Conn m
getConnection :: m (Conn m)
instance (Monad m, MonadIO m, MonadFail m, PersistBackendConn conn) => PersistBackend (ReaderT conn m) where
type Conn (ReaderT conn m) = conn
getConnection :: ReaderT conn m (Conn (ReaderT conn m))
getConnection = ReaderT conn m (Conn (ReaderT conn m))
forall r (m :: * -> *). MonadReader r m => m r
ask
runDb :: PersistBackend m => Action (Conn m) a -> m a
runDb :: Action (Conn m) a -> m a
runDb Action (Conn m) a
f = m (Conn m)
forall (m :: * -> *). PersistBackend m => m (Conn m)
getConnection m (Conn m) -> (Conn m -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (Conn m -> IO a) -> Conn m -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Conn m -> IO a) -> Conn m -> IO a
forall conn (m :: * -> *) a.
(ConnectionManager conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> conn -> m a
withConn (Action (Conn m) a -> Conn m -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Action (Conn m) a
f)
runDbConn :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a
runDbConn :: Action conn a -> cm -> m a
runDbConn Action conn a
f = (conn -> m a) -> cm -> m a
forall cm conn (m :: * -> *) a.
(ExtractConnection cm conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> cm -> m a
extractConn (IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (conn -> IO a) -> conn -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (conn -> IO a) -> conn -> IO a
forall conn (m :: * -> *) a.
(ConnectionManager conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> conn -> m a
withConn (Action conn a -> conn -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Action conn a
f))
runTryDbConn :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn, Exception e) => TryAction e m conn a -> cm -> m (Either SomeException a)
runTryDbConn :: TryAction e m conn a -> cm -> m (Either SomeException a)
runTryDbConn TryAction e m conn a
f = (conn -> m (Either SomeException a))
-> cm -> m (Either SomeException a)
forall cm conn (m :: * -> *) a.
(ExtractConnection cm conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> cm -> m a
extractConn ((conn -> ExceptT e m a)
-> (ExceptT e m a -> m (Either SomeException a))
-> conn
-> m (Either SomeException a)
forall conn (m :: * -> *) (n :: * -> *) a.
(TryConnectionManager conn, MonadBaseControl IO m, MonadIO m,
MonadCatch m) =>
(conn -> n a)
-> (n a -> m (Either SomeException a))
-> conn
-> m (Either SomeException a)
tryWithConn (TryAction e m conn a -> conn -> ExceptT e m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT TryAction e m conn a
f) ExceptT e m a -> m (Either SomeException a)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
ExceptT e m a -> m (Either SomeException a)
tryExceptT)
runTryDbConn' :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m (Either SomeException a)
runTryDbConn' :: Action conn a -> cm -> m (Either SomeException a)
runTryDbConn' Action conn a
f = (conn -> m (Either SomeException a))
-> cm -> m (Either SomeException a)
forall cm conn (m :: * -> *) a.
(ExtractConnection cm conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> cm -> m a
extractConn (IO (Either SomeException a) -> m (Either SomeException a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SomeException a) -> m (Either SomeException a))
-> (conn -> IO (Either SomeException a))
-> conn
-> m (Either SomeException a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (conn -> IO a)
-> (IO a -> IO (Either SomeException a))
-> conn
-> IO (Either SomeException a)
forall conn (m :: * -> *) (n :: * -> *) a.
(TryConnectionManager conn, MonadBaseControl IO m, MonadIO m,
MonadCatch m) =>
(conn -> n a)
-> (n a -> m (Either SomeException a))
-> conn
-> m (Either SomeException a)
tryWithConn (Action conn a -> conn -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Action conn a
f) IO a -> IO (Either SomeException a)
forall (m :: * -> *) a.
MonadCatch m =>
m a -> m (Either SomeException a)
tryAny)
runDb' :: PersistBackend m => Action (Conn m) a -> m a
runDb' :: Action (Conn m) a -> m a
runDb' Action (Conn m) a
f = m (Conn m)
forall (m :: * -> *). PersistBackend m => m (Conn m)
getConnection m (Conn m) -> (Conn m -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (Conn m -> IO a) -> Conn m -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Action (Conn m) a -> Conn m -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Action (Conn m) a
f
runDbConn' :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a
runDbConn' :: Action conn a -> cm -> m a
runDbConn' Action conn a
f = (conn -> m a) -> cm -> m a
forall cm conn (m :: * -> *) a.
(ExtractConnection cm conn, MonadBaseControl IO m, MonadIO m) =>
(conn -> m a) -> cm -> m a
extractConn (IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (conn -> IO a) -> conn -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Action conn a -> conn -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Action conn a
f)
withSavepoint :: (PersistBackend m, MonadBaseControl IO m, MonadIO m, Savepoint (Conn m)) => String -> m a -> m a
withSavepoint :: String -> m a -> m a
withSavepoint String
name m a
m = m (Conn m)
forall (m :: * -> *). PersistBackend m => m (Conn m)
getConnection m (Conn m) -> (Conn m -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> m a -> Conn m -> m a
forall conn (m :: * -> *) a.
(Savepoint conn, MonadBaseControl IO m, MonadIO m) =>
String -> m a -> conn -> m a
withConnSavepoint String
name m a
m
tryExceptT ::
( MonadCatch m,
Exception e
) =>
ExceptT e m a ->
m (Either SomeException a)
tryExceptT :: ExceptT e m a -> m (Either SomeException a)
tryExceptT ExceptT e m a
e = do
Either SomeException (Either e a)
outside <- m (Either e a) -> m (Either SomeException (Either e a))
forall (m :: * -> *) a.
MonadCatch m =>
m a -> m (Either SomeException a)
tryAny (m (Either e a) -> m (Either SomeException (Either e a)))
-> m (Either e a) -> m (Either SomeException (Either e a))
forall a b. (a -> b) -> a -> b
$ ExceptT e m a -> m (Either e a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT e m a
e
case Either SomeException (Either e a)
outside of
Left SomeException
outsideErr -> Either SomeException a -> m (Either SomeException a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SomeException a -> m (Either SomeException a))
-> (SomeException -> Either SomeException a)
-> SomeException
-> m (Either SomeException a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeException -> Either SomeException a
forall a b. a -> Either a b
Left (SomeException -> m (Either SomeException a))
-> SomeException -> m (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ SomeException
outsideErr
Right Either e a
inside -> case Either e a
inside of
Left e
insideErr -> Either SomeException a -> m (Either SomeException a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SomeException a -> m (Either SomeException a))
-> (e -> Either SomeException a) -> e -> m (Either SomeException a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeException -> Either SomeException a
forall a b. a -> Either a b
Left (SomeException -> Either SomeException a)
-> (e -> SomeException) -> e -> Either SomeException a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> SomeException
forall e. Exception e => e -> SomeException
SomeException (e -> m (Either SomeException a))
-> e -> m (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ e
insideErr
Right a
y -> Either SomeException a -> m (Either SomeException a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SomeException a -> m (Either SomeException a))
-> Either SomeException a -> m (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ a -> Either SomeException a
forall a b. b -> Either a b
Right a
y