{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Database.Persist.Types.Base
( module Database.Persist.Types.Base
, PersistValue(..)
, fromPersistValueText
, LiteralType(..)
) where
import Control.Exception (Exception)
import Data.Char (isSpace)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NEL
import Data.Map (Map)
import Data.Maybe (isNothing)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Word (Word32)
import Language.Haskell.TH.Syntax (Lift(..))
import Web.HttpApiData
( FromHttpApiData(..)
, ToHttpApiData(..)
, parseBoundedTextData
, showTextData
)
import Web.PathPieces (PathPiece(..))
import Instances.TH.Lift ()
import Database.Persist.Names
import Database.Persist.PersistValue
data Checkmark = Active
| Inactive
deriving (Checkmark -> Checkmark -> Bool
(Checkmark -> Checkmark -> Bool)
-> (Checkmark -> Checkmark -> Bool) -> Eq Checkmark
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Checkmark -> Checkmark -> Bool
== :: Checkmark -> Checkmark -> Bool
$c/= :: Checkmark -> Checkmark -> Bool
/= :: Checkmark -> Checkmark -> Bool
Eq, Eq Checkmark
Eq Checkmark =>
(Checkmark -> Checkmark -> Ordering)
-> (Checkmark -> Checkmark -> Bool)
-> (Checkmark -> Checkmark -> Bool)
-> (Checkmark -> Checkmark -> Bool)
-> (Checkmark -> Checkmark -> Bool)
-> (Checkmark -> Checkmark -> Checkmark)
-> (Checkmark -> Checkmark -> Checkmark)
-> Ord Checkmark
Checkmark -> Checkmark -> Bool
Checkmark -> Checkmark -> Ordering
Checkmark -> Checkmark -> Checkmark
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Checkmark -> Checkmark -> Ordering
compare :: Checkmark -> Checkmark -> Ordering
$c< :: Checkmark -> Checkmark -> Bool
< :: Checkmark -> Checkmark -> Bool
$c<= :: Checkmark -> Checkmark -> Bool
<= :: Checkmark -> Checkmark -> Bool
$c> :: Checkmark -> Checkmark -> Bool
> :: Checkmark -> Checkmark -> Bool
$c>= :: Checkmark -> Checkmark -> Bool
>= :: Checkmark -> Checkmark -> Bool
$cmax :: Checkmark -> Checkmark -> Checkmark
max :: Checkmark -> Checkmark -> Checkmark
$cmin :: Checkmark -> Checkmark -> Checkmark
min :: Checkmark -> Checkmark -> Checkmark
Ord, ReadPrec [Checkmark]
ReadPrec Checkmark
Int -> ReadS Checkmark
ReadS [Checkmark]
(Int -> ReadS Checkmark)
-> ReadS [Checkmark]
-> ReadPrec Checkmark
-> ReadPrec [Checkmark]
-> Read Checkmark
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Checkmark
readsPrec :: Int -> ReadS Checkmark
$creadList :: ReadS [Checkmark]
readList :: ReadS [Checkmark]
$creadPrec :: ReadPrec Checkmark
readPrec :: ReadPrec Checkmark
$creadListPrec :: ReadPrec [Checkmark]
readListPrec :: ReadPrec [Checkmark]
Read, Int -> Checkmark -> ShowS
[Checkmark] -> ShowS
Checkmark -> [Char]
(Int -> Checkmark -> ShowS)
-> (Checkmark -> [Char])
-> ([Checkmark] -> ShowS)
-> Show Checkmark
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Checkmark -> ShowS
showsPrec :: Int -> Checkmark -> ShowS
$cshow :: Checkmark -> [Char]
show :: Checkmark -> [Char]
$cshowList :: [Checkmark] -> ShowS
showList :: [Checkmark] -> ShowS
Show, Int -> Checkmark
Checkmark -> Int
Checkmark -> [Checkmark]
Checkmark -> Checkmark
Checkmark -> Checkmark -> [Checkmark]
Checkmark -> Checkmark -> Checkmark -> [Checkmark]
(Checkmark -> Checkmark)
-> (Checkmark -> Checkmark)
-> (Int -> Checkmark)
-> (Checkmark -> Int)
-> (Checkmark -> [Checkmark])
-> (Checkmark -> Checkmark -> [Checkmark])
-> (Checkmark -> Checkmark -> [Checkmark])
-> (Checkmark -> Checkmark -> Checkmark -> [Checkmark])
-> Enum Checkmark
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Checkmark -> Checkmark
succ :: Checkmark -> Checkmark
$cpred :: Checkmark -> Checkmark
pred :: Checkmark -> Checkmark
$ctoEnum :: Int -> Checkmark
toEnum :: Int -> Checkmark
$cfromEnum :: Checkmark -> Int
fromEnum :: Checkmark -> Int
$cenumFrom :: Checkmark -> [Checkmark]
enumFrom :: Checkmark -> [Checkmark]
$cenumFromThen :: Checkmark -> Checkmark -> [Checkmark]
enumFromThen :: Checkmark -> Checkmark -> [Checkmark]
$cenumFromTo :: Checkmark -> Checkmark -> [Checkmark]
enumFromTo :: Checkmark -> Checkmark -> [Checkmark]
$cenumFromThenTo :: Checkmark -> Checkmark -> Checkmark -> [Checkmark]
enumFromThenTo :: Checkmark -> Checkmark -> Checkmark -> [Checkmark]
Enum, Checkmark
Checkmark -> Checkmark -> Bounded Checkmark
forall a. a -> a -> Bounded a
$cminBound :: Checkmark
minBound :: Checkmark
$cmaxBound :: Checkmark
maxBound :: Checkmark
Bounded)
instance ToHttpApiData Checkmark where
toUrlPiece :: Checkmark -> Text
toUrlPiece = Checkmark -> Text
forall a. Show a => a -> Text
showTextData
instance FromHttpApiData Checkmark where
parseUrlPiece :: Text -> Either Text Checkmark
parseUrlPiece = Text -> Either Text Checkmark
forall a. (Show a, Bounded a, Enum a) => Text -> Either Text a
parseBoundedTextData
instance PathPiece Checkmark where
toPathPiece :: Checkmark -> Text
toPathPiece Checkmark
Active = Text
"active"
toPathPiece Checkmark
Inactive = Text
"inactive"
fromPathPiece :: Text -> Maybe Checkmark
fromPathPiece Text
"active" = Checkmark -> Maybe Checkmark
forall a. a -> Maybe a
Just Checkmark
Active
fromPathPiece Text
"inactive" = Checkmark -> Maybe Checkmark
forall a. a -> Maybe a
Just Checkmark
Inactive
fromPathPiece Text
_ = Maybe Checkmark
forall a. Maybe a
Nothing
data IsNullable
= Nullable !WhyNullable
| NotNullable
deriving (IsNullable -> IsNullable -> Bool
(IsNullable -> IsNullable -> Bool)
-> (IsNullable -> IsNullable -> Bool) -> Eq IsNullable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsNullable -> IsNullable -> Bool
== :: IsNullable -> IsNullable -> Bool
$c/= :: IsNullable -> IsNullable -> Bool
/= :: IsNullable -> IsNullable -> Bool
Eq, Int -> IsNullable -> ShowS
[IsNullable] -> ShowS
IsNullable -> [Char]
(Int -> IsNullable -> ShowS)
-> (IsNullable -> [Char])
-> ([IsNullable] -> ShowS)
-> Show IsNullable
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsNullable -> ShowS
showsPrec :: Int -> IsNullable -> ShowS
$cshow :: IsNullable -> [Char]
show :: IsNullable -> [Char]
$cshowList :: [IsNullable] -> ShowS
showList :: [IsNullable] -> ShowS
Show)
fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable
fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable
fieldAttrsContainsNullable [FieldAttr]
s
| FieldAttr
FieldAttrMaybe FieldAttr -> [FieldAttr] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [FieldAttr]
s = WhyNullable -> IsNullable
Nullable WhyNullable
ByMaybeAttr
| FieldAttr
FieldAttrNullable FieldAttr -> [FieldAttr] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [FieldAttr]
s = WhyNullable -> IsNullable
Nullable WhyNullable
ByNullableAttr
| Bool
otherwise = IsNullable
NotNullable
data WhyNullable = ByMaybeAttr
| ByNullableAttr
deriving (WhyNullable -> WhyNullable -> Bool
(WhyNullable -> WhyNullable -> Bool)
-> (WhyNullable -> WhyNullable -> Bool) -> Eq WhyNullable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WhyNullable -> WhyNullable -> Bool
== :: WhyNullable -> WhyNullable -> Bool
$c/= :: WhyNullable -> WhyNullable -> Bool
/= :: WhyNullable -> WhyNullable -> Bool
Eq, Int -> WhyNullable -> ShowS
[WhyNullable] -> ShowS
WhyNullable -> [Char]
(Int -> WhyNullable -> ShowS)
-> (WhyNullable -> [Char])
-> ([WhyNullable] -> ShowS)
-> Show WhyNullable
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WhyNullable -> ShowS
showsPrec :: Int -> WhyNullable -> ShowS
$cshow :: WhyNullable -> [Char]
show :: WhyNullable -> [Char]
$cshowList :: [WhyNullable] -> ShowS
showList :: [WhyNullable] -> ShowS
Show)
data EntityDef = EntityDef
{ EntityDef -> EntityNameHS
entityHaskell :: !EntityNameHS
, EntityDef -> EntityNameDB
entityDB :: !EntityNameDB
, EntityDef -> EntityIdDef
entityId :: !EntityIdDef
, EntityDef -> [Text]
entityAttrs :: ![Attr]
, EntityDef -> [FieldDef]
entityFields :: ![FieldDef]
, EntityDef -> [UniqueDef]
entityUniques :: ![UniqueDef]
, EntityDef -> [ForeignDef]
entityForeigns:: ![ForeignDef]
, EntityDef -> [Text]
entityDerives :: ![Text]
, :: !(Map Text [ExtraLine])
, EntityDef -> Bool
entitySum :: !Bool
, :: !(Maybe Text)
}
deriving (Int -> EntityDef -> ShowS
[EntityDef] -> ShowS
EntityDef -> [Char]
(Int -> EntityDef -> ShowS)
-> (EntityDef -> [Char])
-> ([EntityDef] -> ShowS)
-> Show EntityDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntityDef -> ShowS
showsPrec :: Int -> EntityDef -> ShowS
$cshow :: EntityDef -> [Char]
show :: EntityDef -> [Char]
$cshowList :: [EntityDef] -> ShowS
showList :: [EntityDef] -> ShowS
Show, EntityDef -> EntityDef -> Bool
(EntityDef -> EntityDef -> Bool)
-> (EntityDef -> EntityDef -> Bool) -> Eq EntityDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntityDef -> EntityDef -> Bool
== :: EntityDef -> EntityDef -> Bool
$c/= :: EntityDef -> EntityDef -> Bool
/= :: EntityDef -> EntityDef -> Bool
Eq, ReadPrec [EntityDef]
ReadPrec EntityDef
Int -> ReadS EntityDef
ReadS [EntityDef]
(Int -> ReadS EntityDef)
-> ReadS [EntityDef]
-> ReadPrec EntityDef
-> ReadPrec [EntityDef]
-> Read EntityDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EntityDef
readsPrec :: Int -> ReadS EntityDef
$creadList :: ReadS [EntityDef]
readList :: ReadS [EntityDef]
$creadPrec :: ReadPrec EntityDef
readPrec :: ReadPrec EntityDef
$creadListPrec :: ReadPrec [EntityDef]
readListPrec :: ReadPrec [EntityDef]
Read, Eq EntityDef
Eq EntityDef =>
(EntityDef -> EntityDef -> Ordering)
-> (EntityDef -> EntityDef -> Bool)
-> (EntityDef -> EntityDef -> Bool)
-> (EntityDef -> EntityDef -> Bool)
-> (EntityDef -> EntityDef -> Bool)
-> (EntityDef -> EntityDef -> EntityDef)
-> (EntityDef -> EntityDef -> EntityDef)
-> Ord EntityDef
EntityDef -> EntityDef -> Bool
EntityDef -> EntityDef -> Ordering
EntityDef -> EntityDef -> EntityDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EntityDef -> EntityDef -> Ordering
compare :: EntityDef -> EntityDef -> Ordering
$c< :: EntityDef -> EntityDef -> Bool
< :: EntityDef -> EntityDef -> Bool
$c<= :: EntityDef -> EntityDef -> Bool
<= :: EntityDef -> EntityDef -> Bool
$c> :: EntityDef -> EntityDef -> Bool
> :: EntityDef -> EntityDef -> Bool
$c>= :: EntityDef -> EntityDef -> Bool
>= :: EntityDef -> EntityDef -> Bool
$cmax :: EntityDef -> EntityDef -> EntityDef
max :: EntityDef -> EntityDef -> EntityDef
$cmin :: EntityDef -> EntityDef -> EntityDef
min :: EntityDef -> EntityDef -> EntityDef
Ord, (forall (m :: * -> *). Quote m => EntityDef -> m Exp)
-> (forall (m :: * -> *). Quote m => EntityDef -> Code m EntityDef)
-> Lift EntityDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => EntityDef -> m Exp
forall (m :: * -> *). Quote m => EntityDef -> Code m EntityDef
$clift :: forall (m :: * -> *). Quote m => EntityDef -> m Exp
lift :: forall (m :: * -> *). Quote m => EntityDef -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => EntityDef -> Code m EntityDef
liftTyped :: forall (m :: * -> *). Quote m => EntityDef -> Code m EntityDef
Lift)
data EntityIdDef
= EntityIdField !FieldDef
| EntityIdNaturalKey !CompositeDef
deriving (Int -> EntityIdDef -> ShowS
[EntityIdDef] -> ShowS
EntityIdDef -> [Char]
(Int -> EntityIdDef -> ShowS)
-> (EntityIdDef -> [Char])
-> ([EntityIdDef] -> ShowS)
-> Show EntityIdDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntityIdDef -> ShowS
showsPrec :: Int -> EntityIdDef -> ShowS
$cshow :: EntityIdDef -> [Char]
show :: EntityIdDef -> [Char]
$cshowList :: [EntityIdDef] -> ShowS
showList :: [EntityIdDef] -> ShowS
Show, EntityIdDef -> EntityIdDef -> Bool
(EntityIdDef -> EntityIdDef -> Bool)
-> (EntityIdDef -> EntityIdDef -> Bool) -> Eq EntityIdDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntityIdDef -> EntityIdDef -> Bool
== :: EntityIdDef -> EntityIdDef -> Bool
$c/= :: EntityIdDef -> EntityIdDef -> Bool
/= :: EntityIdDef -> EntityIdDef -> Bool
Eq, ReadPrec [EntityIdDef]
ReadPrec EntityIdDef
Int -> ReadS EntityIdDef
ReadS [EntityIdDef]
(Int -> ReadS EntityIdDef)
-> ReadS [EntityIdDef]
-> ReadPrec EntityIdDef
-> ReadPrec [EntityIdDef]
-> Read EntityIdDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EntityIdDef
readsPrec :: Int -> ReadS EntityIdDef
$creadList :: ReadS [EntityIdDef]
readList :: ReadS [EntityIdDef]
$creadPrec :: ReadPrec EntityIdDef
readPrec :: ReadPrec EntityIdDef
$creadListPrec :: ReadPrec [EntityIdDef]
readListPrec :: ReadPrec [EntityIdDef]
Read, Eq EntityIdDef
Eq EntityIdDef =>
(EntityIdDef -> EntityIdDef -> Ordering)
-> (EntityIdDef -> EntityIdDef -> Bool)
-> (EntityIdDef -> EntityIdDef -> Bool)
-> (EntityIdDef -> EntityIdDef -> Bool)
-> (EntityIdDef -> EntityIdDef -> Bool)
-> (EntityIdDef -> EntityIdDef -> EntityIdDef)
-> (EntityIdDef -> EntityIdDef -> EntityIdDef)
-> Ord EntityIdDef
EntityIdDef -> EntityIdDef -> Bool
EntityIdDef -> EntityIdDef -> Ordering
EntityIdDef -> EntityIdDef -> EntityIdDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EntityIdDef -> EntityIdDef -> Ordering
compare :: EntityIdDef -> EntityIdDef -> Ordering
$c< :: EntityIdDef -> EntityIdDef -> Bool
< :: EntityIdDef -> EntityIdDef -> Bool
$c<= :: EntityIdDef -> EntityIdDef -> Bool
<= :: EntityIdDef -> EntityIdDef -> Bool
$c> :: EntityIdDef -> EntityIdDef -> Bool
> :: EntityIdDef -> EntityIdDef -> Bool
$c>= :: EntityIdDef -> EntityIdDef -> Bool
>= :: EntityIdDef -> EntityIdDef -> Bool
$cmax :: EntityIdDef -> EntityIdDef -> EntityIdDef
max :: EntityIdDef -> EntityIdDef -> EntityIdDef
$cmin :: EntityIdDef -> EntityIdDef -> EntityIdDef
min :: EntityIdDef -> EntityIdDef -> EntityIdDef
Ord, (forall (m :: * -> *). Quote m => EntityIdDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
EntityIdDef -> Code m EntityIdDef)
-> Lift EntityIdDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => EntityIdDef -> m Exp
forall (m :: * -> *). Quote m => EntityIdDef -> Code m EntityIdDef
$clift :: forall (m :: * -> *). Quote m => EntityIdDef -> m Exp
lift :: forall (m :: * -> *). Quote m => EntityIdDef -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => EntityIdDef -> Code m EntityIdDef
liftTyped :: forall (m :: * -> *). Quote m => EntityIdDef -> Code m EntityIdDef
Lift)
entitiesPrimary :: EntityDef -> NonEmpty FieldDef
entitiesPrimary :: EntityDef -> NonEmpty FieldDef
entitiesPrimary EntityDef
t =
case EntityDef -> EntityIdDef
entityId EntityDef
t of
EntityIdNaturalKey CompositeDef
fds ->
CompositeDef -> NonEmpty FieldDef
compositeFields CompositeDef
fds
EntityIdField FieldDef
fd ->
FieldDef -> NonEmpty FieldDef
forall a. a -> NonEmpty a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FieldDef
fd
entityPrimary :: EntityDef -> Maybe CompositeDef
entityPrimary :: EntityDef -> Maybe CompositeDef
entityPrimary EntityDef
t =
case EntityDef -> EntityIdDef
entityId EntityDef
t of
EntityIdNaturalKey CompositeDef
c ->
CompositeDef -> Maybe CompositeDef
forall a. a -> Maybe a
Just CompositeDef
c
EntityIdDef
_ ->
Maybe CompositeDef
forall a. Maybe a
Nothing
entityKeyFields :: EntityDef -> NonEmpty FieldDef
entityKeyFields :: EntityDef -> NonEmpty FieldDef
entityKeyFields =
EntityDef -> NonEmpty FieldDef
entitiesPrimary
keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
keyAndEntityFields EntityDef
ent =
EntityIdDef -> [FieldDef] -> NonEmpty FieldDef
keyWithFields (EntityDef -> EntityIdDef
entityId EntityDef
ent) [FieldDef]
fields
where
fields :: [FieldDef]
fields = (FieldDef -> Bool) -> [FieldDef] -> [FieldDef]
forall a. (a -> Bool) -> [a] -> [a]
filter FieldDef -> Bool
isHaskellField ([FieldDef] -> [FieldDef]) -> [FieldDef] -> [FieldDef]
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
entityFields EntityDef
ent
keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef
keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef
keyAndEntityFieldsDatabase EntityDef
ent =
EntityIdDef -> [FieldDef] -> NonEmpty FieldDef
keyWithFields (EntityDef -> EntityIdDef
entityId EntityDef
ent) [FieldDef]
fields
where
fields :: [FieldDef]
fields = EntityDef -> [FieldDef]
entityFields EntityDef
ent
keyWithFields :: EntityIdDef -> [FieldDef] -> NonEmpty FieldDef
keyWithFields :: EntityIdDef -> [FieldDef] -> NonEmpty FieldDef
keyWithFields EntityIdDef
entId [FieldDef]
fields =
case EntityIdDef
entId of
EntityIdField FieldDef
fd ->
FieldDef
fd FieldDef -> [FieldDef] -> NonEmpty FieldDef
forall a. a -> [a] -> NonEmpty a
:| [FieldDef]
fields
EntityIdNaturalKey CompositeDef
_ ->
case [FieldDef] -> Maybe (NonEmpty FieldDef)
forall a. [a] -> Maybe (NonEmpty a)
NEL.nonEmpty [FieldDef]
fields of
Maybe (NonEmpty FieldDef)
Nothing ->
[Char] -> NonEmpty FieldDef
forall a. HasCallStack => [Char] -> a
error ([Char] -> NonEmpty FieldDef) -> [Char] -> NonEmpty FieldDef
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
forall a. Monoid a => [a] -> a
mconcat
[ [Char]
"persistent internal guarantee failed: entity is "
, [Char]
"defined with an entityId = EntityIdNaturalKey, "
, [Char]
"but somehow doesn't have any entity fields."
]
Just NonEmpty FieldDef
xs ->
NonEmpty FieldDef
xs
type = [Text]
type Attr = Text
data FieldAttr
= FieldAttrMaybe
| FieldAttrNullable
| FieldAttrMigrationOnly
| FieldAttrSafeToRemove
| FieldAttrNoreference
| FieldAttrReference Text
| FieldAttrConstraint Text
| FieldAttrDefault Text
| FieldAttrSqltype Text
| FieldAttrMaxlen Integer
| FieldAttrSql Text
| FieldAttrOther Text
deriving (Int -> FieldAttr -> ShowS
[FieldAttr] -> ShowS
FieldAttr -> [Char]
(Int -> FieldAttr -> ShowS)
-> (FieldAttr -> [Char])
-> ([FieldAttr] -> ShowS)
-> Show FieldAttr
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FieldAttr -> ShowS
showsPrec :: Int -> FieldAttr -> ShowS
$cshow :: FieldAttr -> [Char]
show :: FieldAttr -> [Char]
$cshowList :: [FieldAttr] -> ShowS
showList :: [FieldAttr] -> ShowS
Show, FieldAttr -> FieldAttr -> Bool
(FieldAttr -> FieldAttr -> Bool)
-> (FieldAttr -> FieldAttr -> Bool) -> Eq FieldAttr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FieldAttr -> FieldAttr -> Bool
== :: FieldAttr -> FieldAttr -> Bool
$c/= :: FieldAttr -> FieldAttr -> Bool
/= :: FieldAttr -> FieldAttr -> Bool
Eq, ReadPrec [FieldAttr]
ReadPrec FieldAttr
Int -> ReadS FieldAttr
ReadS [FieldAttr]
(Int -> ReadS FieldAttr)
-> ReadS [FieldAttr]
-> ReadPrec FieldAttr
-> ReadPrec [FieldAttr]
-> Read FieldAttr
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FieldAttr
readsPrec :: Int -> ReadS FieldAttr
$creadList :: ReadS [FieldAttr]
readList :: ReadS [FieldAttr]
$creadPrec :: ReadPrec FieldAttr
readPrec :: ReadPrec FieldAttr
$creadListPrec :: ReadPrec [FieldAttr]
readListPrec :: ReadPrec [FieldAttr]
Read, Eq FieldAttr
Eq FieldAttr =>
(FieldAttr -> FieldAttr -> Ordering)
-> (FieldAttr -> FieldAttr -> Bool)
-> (FieldAttr -> FieldAttr -> Bool)
-> (FieldAttr -> FieldAttr -> Bool)
-> (FieldAttr -> FieldAttr -> Bool)
-> (FieldAttr -> FieldAttr -> FieldAttr)
-> (FieldAttr -> FieldAttr -> FieldAttr)
-> Ord FieldAttr
FieldAttr -> FieldAttr -> Bool
FieldAttr -> FieldAttr -> Ordering
FieldAttr -> FieldAttr -> FieldAttr
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FieldAttr -> FieldAttr -> Ordering
compare :: FieldAttr -> FieldAttr -> Ordering
$c< :: FieldAttr -> FieldAttr -> Bool
< :: FieldAttr -> FieldAttr -> Bool
$c<= :: FieldAttr -> FieldAttr -> Bool
<= :: FieldAttr -> FieldAttr -> Bool
$c> :: FieldAttr -> FieldAttr -> Bool
> :: FieldAttr -> FieldAttr -> Bool
$c>= :: FieldAttr -> FieldAttr -> Bool
>= :: FieldAttr -> FieldAttr -> Bool
$cmax :: FieldAttr -> FieldAttr -> FieldAttr
max :: FieldAttr -> FieldAttr -> FieldAttr
$cmin :: FieldAttr -> FieldAttr -> FieldAttr
min :: FieldAttr -> FieldAttr -> FieldAttr
Ord, (forall (m :: * -> *). Quote m => FieldAttr -> m Exp)
-> (forall (m :: * -> *). Quote m => FieldAttr -> Code m FieldAttr)
-> Lift FieldAttr
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FieldAttr -> m Exp
forall (m :: * -> *). Quote m => FieldAttr -> Code m FieldAttr
$clift :: forall (m :: * -> *). Quote m => FieldAttr -> m Exp
lift :: forall (m :: * -> *). Quote m => FieldAttr -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => FieldAttr -> Code m FieldAttr
liftTyped :: forall (m :: * -> *). Quote m => FieldAttr -> Code m FieldAttr
Lift)
parseFieldAttrs :: [Text] -> [FieldAttr]
parseFieldAttrs :: [Text] -> [FieldAttr]
parseFieldAttrs = (Text -> FieldAttr) -> [Text] -> [FieldAttr]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text -> FieldAttr) -> [Text] -> [FieldAttr])
-> (Text -> FieldAttr) -> [Text] -> [FieldAttr]
forall a b. (a -> b) -> a -> b
$ \case
Text
"Maybe" -> FieldAttr
FieldAttrMaybe
Text
"nullable" -> FieldAttr
FieldAttrNullable
Text
"MigrationOnly" -> FieldAttr
FieldAttrMigrationOnly
Text
"SafeToRemove" -> FieldAttr
FieldAttrSafeToRemove
Text
"noreference" -> FieldAttr
FieldAttrNoreference
Text
raw
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"reference=" Text
raw -> Text -> FieldAttr
FieldAttrReference Text
x
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"constraint=" Text
raw -> Text -> FieldAttr
FieldAttrConstraint Text
x
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"default=" Text
raw -> Text -> FieldAttr
FieldAttrDefault Text
x
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"sqltype=" Text
raw -> Text -> FieldAttr
FieldAttrSqltype Text
x
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"maxlen=" Text
raw -> case ReadS Integer
forall a. Read a => ReadS a
reads (Text -> [Char]
T.unpack Text
x) of
[(Integer
n, [Char]
s)] | (Char -> Bool) -> [Char] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace [Char]
s -> Integer -> FieldAttr
FieldAttrMaxlen Integer
n
[(Integer, [Char])]
_ -> [Char] -> FieldAttr
forall a. HasCallStack => [Char] -> a
error ([Char] -> FieldAttr) -> [Char] -> FieldAttr
forall a b. (a -> b) -> a -> b
$ [Char]
"Could not parse maxlen field with value " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
forall a. Show a => a -> [Char]
show Text
raw
| Just Text
x <- Text -> Text -> Maybe Text
T.stripPrefix Text
"sql=" Text
raw ->
Text -> FieldAttr
FieldAttrSql Text
x
| Bool
otherwise -> Text -> FieldAttr
FieldAttrOther Text
raw
data FieldType
= FTTypeCon (Maybe Text) Text
| FTLit FieldTypeLit
| FTTypePromoted Text
| FTApp FieldType FieldType
| FTList FieldType
deriving (Int -> FieldType -> ShowS
[FieldType] -> ShowS
FieldType -> [Char]
(Int -> FieldType -> ShowS)
-> (FieldType -> [Char])
-> ([FieldType] -> ShowS)
-> Show FieldType
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FieldType -> ShowS
showsPrec :: Int -> FieldType -> ShowS
$cshow :: FieldType -> [Char]
show :: FieldType -> [Char]
$cshowList :: [FieldType] -> ShowS
showList :: [FieldType] -> ShowS
Show, FieldType -> FieldType -> Bool
(FieldType -> FieldType -> Bool)
-> (FieldType -> FieldType -> Bool) -> Eq FieldType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FieldType -> FieldType -> Bool
== :: FieldType -> FieldType -> Bool
$c/= :: FieldType -> FieldType -> Bool
/= :: FieldType -> FieldType -> Bool
Eq, ReadPrec [FieldType]
ReadPrec FieldType
Int -> ReadS FieldType
ReadS [FieldType]
(Int -> ReadS FieldType)
-> ReadS [FieldType]
-> ReadPrec FieldType
-> ReadPrec [FieldType]
-> Read FieldType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FieldType
readsPrec :: Int -> ReadS FieldType
$creadList :: ReadS [FieldType]
readList :: ReadS [FieldType]
$creadPrec :: ReadPrec FieldType
readPrec :: ReadPrec FieldType
$creadListPrec :: ReadPrec [FieldType]
readListPrec :: ReadPrec [FieldType]
Read, Eq FieldType
Eq FieldType =>
(FieldType -> FieldType -> Ordering)
-> (FieldType -> FieldType -> Bool)
-> (FieldType -> FieldType -> Bool)
-> (FieldType -> FieldType -> Bool)
-> (FieldType -> FieldType -> Bool)
-> (FieldType -> FieldType -> FieldType)
-> (FieldType -> FieldType -> FieldType)
-> Ord FieldType
FieldType -> FieldType -> Bool
FieldType -> FieldType -> Ordering
FieldType -> FieldType -> FieldType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FieldType -> FieldType -> Ordering
compare :: FieldType -> FieldType -> Ordering
$c< :: FieldType -> FieldType -> Bool
< :: FieldType -> FieldType -> Bool
$c<= :: FieldType -> FieldType -> Bool
<= :: FieldType -> FieldType -> Bool
$c> :: FieldType -> FieldType -> Bool
> :: FieldType -> FieldType -> Bool
$c>= :: FieldType -> FieldType -> Bool
>= :: FieldType -> FieldType -> Bool
$cmax :: FieldType -> FieldType -> FieldType
max :: FieldType -> FieldType -> FieldType
$cmin :: FieldType -> FieldType -> FieldType
min :: FieldType -> FieldType -> FieldType
Ord, (forall (m :: * -> *). Quote m => FieldType -> m Exp)
-> (forall (m :: * -> *). Quote m => FieldType -> Code m FieldType)
-> Lift FieldType
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FieldType -> m Exp
forall (m :: * -> *). Quote m => FieldType -> Code m FieldType
$clift :: forall (m :: * -> *). Quote m => FieldType -> m Exp
lift :: forall (m :: * -> *). Quote m => FieldType -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => FieldType -> Code m FieldType
liftTyped :: forall (m :: * -> *). Quote m => FieldType -> Code m FieldType
Lift)
data FieldTypeLit
= IntTypeLit Integer
| TextTypeLit Text
deriving (Int -> FieldTypeLit -> ShowS
[FieldTypeLit] -> ShowS
FieldTypeLit -> [Char]
(Int -> FieldTypeLit -> ShowS)
-> (FieldTypeLit -> [Char])
-> ([FieldTypeLit] -> ShowS)
-> Show FieldTypeLit
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FieldTypeLit -> ShowS
showsPrec :: Int -> FieldTypeLit -> ShowS
$cshow :: FieldTypeLit -> [Char]
show :: FieldTypeLit -> [Char]
$cshowList :: [FieldTypeLit] -> ShowS
showList :: [FieldTypeLit] -> ShowS
Show, FieldTypeLit -> FieldTypeLit -> Bool
(FieldTypeLit -> FieldTypeLit -> Bool)
-> (FieldTypeLit -> FieldTypeLit -> Bool) -> Eq FieldTypeLit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FieldTypeLit -> FieldTypeLit -> Bool
== :: FieldTypeLit -> FieldTypeLit -> Bool
$c/= :: FieldTypeLit -> FieldTypeLit -> Bool
/= :: FieldTypeLit -> FieldTypeLit -> Bool
Eq, ReadPrec [FieldTypeLit]
ReadPrec FieldTypeLit
Int -> ReadS FieldTypeLit
ReadS [FieldTypeLit]
(Int -> ReadS FieldTypeLit)
-> ReadS [FieldTypeLit]
-> ReadPrec FieldTypeLit
-> ReadPrec [FieldTypeLit]
-> Read FieldTypeLit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FieldTypeLit
readsPrec :: Int -> ReadS FieldTypeLit
$creadList :: ReadS [FieldTypeLit]
readList :: ReadS [FieldTypeLit]
$creadPrec :: ReadPrec FieldTypeLit
readPrec :: ReadPrec FieldTypeLit
$creadListPrec :: ReadPrec [FieldTypeLit]
readListPrec :: ReadPrec [FieldTypeLit]
Read, Eq FieldTypeLit
Eq FieldTypeLit =>
(FieldTypeLit -> FieldTypeLit -> Ordering)
-> (FieldTypeLit -> FieldTypeLit -> Bool)
-> (FieldTypeLit -> FieldTypeLit -> Bool)
-> (FieldTypeLit -> FieldTypeLit -> Bool)
-> (FieldTypeLit -> FieldTypeLit -> Bool)
-> (FieldTypeLit -> FieldTypeLit -> FieldTypeLit)
-> (FieldTypeLit -> FieldTypeLit -> FieldTypeLit)
-> Ord FieldTypeLit
FieldTypeLit -> FieldTypeLit -> Bool
FieldTypeLit -> FieldTypeLit -> Ordering
FieldTypeLit -> FieldTypeLit -> FieldTypeLit
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FieldTypeLit -> FieldTypeLit -> Ordering
compare :: FieldTypeLit -> FieldTypeLit -> Ordering
$c< :: FieldTypeLit -> FieldTypeLit -> Bool
< :: FieldTypeLit -> FieldTypeLit -> Bool
$c<= :: FieldTypeLit -> FieldTypeLit -> Bool
<= :: FieldTypeLit -> FieldTypeLit -> Bool
$c> :: FieldTypeLit -> FieldTypeLit -> Bool
> :: FieldTypeLit -> FieldTypeLit -> Bool
$c>= :: FieldTypeLit -> FieldTypeLit -> Bool
>= :: FieldTypeLit -> FieldTypeLit -> Bool
$cmax :: FieldTypeLit -> FieldTypeLit -> FieldTypeLit
max :: FieldTypeLit -> FieldTypeLit -> FieldTypeLit
$cmin :: FieldTypeLit -> FieldTypeLit -> FieldTypeLit
min :: FieldTypeLit -> FieldTypeLit -> FieldTypeLit
Ord, (forall (m :: * -> *). Quote m => FieldTypeLit -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
FieldTypeLit -> Code m FieldTypeLit)
-> Lift FieldTypeLit
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FieldTypeLit -> m Exp
forall (m :: * -> *).
Quote m =>
FieldTypeLit -> Code m FieldTypeLit
$clift :: forall (m :: * -> *). Quote m => FieldTypeLit -> m Exp
lift :: forall (m :: * -> *). Quote m => FieldTypeLit -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
FieldTypeLit -> Code m FieldTypeLit
liftTyped :: forall (m :: * -> *).
Quote m =>
FieldTypeLit -> Code m FieldTypeLit
Lift)
isFieldNotGenerated :: FieldDef -> Bool
isFieldNotGenerated :: FieldDef -> Bool
isFieldNotGenerated = Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe Text -> Bool)
-> (FieldDef -> Maybe Text) -> FieldDef -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> Maybe Text
fieldGenerated
data ReferenceDef
= NoReference
| ForeignRef !EntityNameHS
| EmbedRef EntityNameHS
| SelfReference
deriving (Int -> ReferenceDef -> ShowS
[ReferenceDef] -> ShowS
ReferenceDef -> [Char]
(Int -> ReferenceDef -> ShowS)
-> (ReferenceDef -> [Char])
-> ([ReferenceDef] -> ShowS)
-> Show ReferenceDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReferenceDef -> ShowS
showsPrec :: Int -> ReferenceDef -> ShowS
$cshow :: ReferenceDef -> [Char]
show :: ReferenceDef -> [Char]
$cshowList :: [ReferenceDef] -> ShowS
showList :: [ReferenceDef] -> ShowS
Show, ReferenceDef -> ReferenceDef -> Bool
(ReferenceDef -> ReferenceDef -> Bool)
-> (ReferenceDef -> ReferenceDef -> Bool) -> Eq ReferenceDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReferenceDef -> ReferenceDef -> Bool
== :: ReferenceDef -> ReferenceDef -> Bool
$c/= :: ReferenceDef -> ReferenceDef -> Bool
/= :: ReferenceDef -> ReferenceDef -> Bool
Eq, ReadPrec [ReferenceDef]
ReadPrec ReferenceDef
Int -> ReadS ReferenceDef
ReadS [ReferenceDef]
(Int -> ReadS ReferenceDef)
-> ReadS [ReferenceDef]
-> ReadPrec ReferenceDef
-> ReadPrec [ReferenceDef]
-> Read ReferenceDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ReferenceDef
readsPrec :: Int -> ReadS ReferenceDef
$creadList :: ReadS [ReferenceDef]
readList :: ReadS [ReferenceDef]
$creadPrec :: ReadPrec ReferenceDef
readPrec :: ReadPrec ReferenceDef
$creadListPrec :: ReadPrec [ReferenceDef]
readListPrec :: ReadPrec [ReferenceDef]
Read, Eq ReferenceDef
Eq ReferenceDef =>
(ReferenceDef -> ReferenceDef -> Ordering)
-> (ReferenceDef -> ReferenceDef -> Bool)
-> (ReferenceDef -> ReferenceDef -> Bool)
-> (ReferenceDef -> ReferenceDef -> Bool)
-> (ReferenceDef -> ReferenceDef -> Bool)
-> (ReferenceDef -> ReferenceDef -> ReferenceDef)
-> (ReferenceDef -> ReferenceDef -> ReferenceDef)
-> Ord ReferenceDef
ReferenceDef -> ReferenceDef -> Bool
ReferenceDef -> ReferenceDef -> Ordering
ReferenceDef -> ReferenceDef -> ReferenceDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ReferenceDef -> ReferenceDef -> Ordering
compare :: ReferenceDef -> ReferenceDef -> Ordering
$c< :: ReferenceDef -> ReferenceDef -> Bool
< :: ReferenceDef -> ReferenceDef -> Bool
$c<= :: ReferenceDef -> ReferenceDef -> Bool
<= :: ReferenceDef -> ReferenceDef -> Bool
$c> :: ReferenceDef -> ReferenceDef -> Bool
> :: ReferenceDef -> ReferenceDef -> Bool
$c>= :: ReferenceDef -> ReferenceDef -> Bool
>= :: ReferenceDef -> ReferenceDef -> Bool
$cmax :: ReferenceDef -> ReferenceDef -> ReferenceDef
max :: ReferenceDef -> ReferenceDef -> ReferenceDef
$cmin :: ReferenceDef -> ReferenceDef -> ReferenceDef
min :: ReferenceDef -> ReferenceDef -> ReferenceDef
Ord, (forall (m :: * -> *). Quote m => ReferenceDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
ReferenceDef -> Code m ReferenceDef)
-> Lift ReferenceDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => ReferenceDef -> m Exp
forall (m :: * -> *).
Quote m =>
ReferenceDef -> Code m ReferenceDef
$clift :: forall (m :: * -> *). Quote m => ReferenceDef -> m Exp
lift :: forall (m :: * -> *). Quote m => ReferenceDef -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
ReferenceDef -> Code m ReferenceDef
liftTyped :: forall (m :: * -> *).
Quote m =>
ReferenceDef -> Code m ReferenceDef
Lift)
data EmbedEntityDef = EmbedEntityDef
{ EmbedEntityDef -> EntityNameHS
embeddedHaskell :: EntityNameHS
, EmbedEntityDef -> [EmbedFieldDef]
embeddedFields :: [EmbedFieldDef]
} deriving (Int -> EmbedEntityDef -> ShowS
[EmbedEntityDef] -> ShowS
EmbedEntityDef -> [Char]
(Int -> EmbedEntityDef -> ShowS)
-> (EmbedEntityDef -> [Char])
-> ([EmbedEntityDef] -> ShowS)
-> Show EmbedEntityDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmbedEntityDef -> ShowS
showsPrec :: Int -> EmbedEntityDef -> ShowS
$cshow :: EmbedEntityDef -> [Char]
show :: EmbedEntityDef -> [Char]
$cshowList :: [EmbedEntityDef] -> ShowS
showList :: [EmbedEntityDef] -> ShowS
Show, EmbedEntityDef -> EmbedEntityDef -> Bool
(EmbedEntityDef -> EmbedEntityDef -> Bool)
-> (EmbedEntityDef -> EmbedEntityDef -> Bool) -> Eq EmbedEntityDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmbedEntityDef -> EmbedEntityDef -> Bool
== :: EmbedEntityDef -> EmbedEntityDef -> Bool
$c/= :: EmbedEntityDef -> EmbedEntityDef -> Bool
/= :: EmbedEntityDef -> EmbedEntityDef -> Bool
Eq, ReadPrec [EmbedEntityDef]
ReadPrec EmbedEntityDef
Int -> ReadS EmbedEntityDef
ReadS [EmbedEntityDef]
(Int -> ReadS EmbedEntityDef)
-> ReadS [EmbedEntityDef]
-> ReadPrec EmbedEntityDef
-> ReadPrec [EmbedEntityDef]
-> Read EmbedEntityDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EmbedEntityDef
readsPrec :: Int -> ReadS EmbedEntityDef
$creadList :: ReadS [EmbedEntityDef]
readList :: ReadS [EmbedEntityDef]
$creadPrec :: ReadPrec EmbedEntityDef
readPrec :: ReadPrec EmbedEntityDef
$creadListPrec :: ReadPrec [EmbedEntityDef]
readListPrec :: ReadPrec [EmbedEntityDef]
Read, Eq EmbedEntityDef
Eq EmbedEntityDef =>
(EmbedEntityDef -> EmbedEntityDef -> Ordering)
-> (EmbedEntityDef -> EmbedEntityDef -> Bool)
-> (EmbedEntityDef -> EmbedEntityDef -> Bool)
-> (EmbedEntityDef -> EmbedEntityDef -> Bool)
-> (EmbedEntityDef -> EmbedEntityDef -> Bool)
-> (EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef)
-> (EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef)
-> Ord EmbedEntityDef
EmbedEntityDef -> EmbedEntityDef -> Bool
EmbedEntityDef -> EmbedEntityDef -> Ordering
EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EmbedEntityDef -> EmbedEntityDef -> Ordering
compare :: EmbedEntityDef -> EmbedEntityDef -> Ordering
$c< :: EmbedEntityDef -> EmbedEntityDef -> Bool
< :: EmbedEntityDef -> EmbedEntityDef -> Bool
$c<= :: EmbedEntityDef -> EmbedEntityDef -> Bool
<= :: EmbedEntityDef -> EmbedEntityDef -> Bool
$c> :: EmbedEntityDef -> EmbedEntityDef -> Bool
> :: EmbedEntityDef -> EmbedEntityDef -> Bool
$c>= :: EmbedEntityDef -> EmbedEntityDef -> Bool
>= :: EmbedEntityDef -> EmbedEntityDef -> Bool
$cmax :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef
max :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef
$cmin :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef
min :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef
Ord, (forall (m :: * -> *). Quote m => EmbedEntityDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
EmbedEntityDef -> Code m EmbedEntityDef)
-> Lift EmbedEntityDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => EmbedEntityDef -> m Exp
forall (m :: * -> *).
Quote m =>
EmbedEntityDef -> Code m EmbedEntityDef
$clift :: forall (m :: * -> *). Quote m => EmbedEntityDef -> m Exp
lift :: forall (m :: * -> *). Quote m => EmbedEntityDef -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
EmbedEntityDef -> Code m EmbedEntityDef
liftTyped :: forall (m :: * -> *).
Quote m =>
EmbedEntityDef -> Code m EmbedEntityDef
Lift)
data EmbedFieldDef = EmbedFieldDef
{ EmbedFieldDef -> FieldNameDB
emFieldDB :: FieldNameDB
, EmbedFieldDef -> Maybe (Either SelfEmbed EntityNameHS)
emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)
}
deriving (Int -> EmbedFieldDef -> ShowS
[EmbedFieldDef] -> ShowS
EmbedFieldDef -> [Char]
(Int -> EmbedFieldDef -> ShowS)
-> (EmbedFieldDef -> [Char])
-> ([EmbedFieldDef] -> ShowS)
-> Show EmbedFieldDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmbedFieldDef -> ShowS
showsPrec :: Int -> EmbedFieldDef -> ShowS
$cshow :: EmbedFieldDef -> [Char]
show :: EmbedFieldDef -> [Char]
$cshowList :: [EmbedFieldDef] -> ShowS
showList :: [EmbedFieldDef] -> ShowS
Show, EmbedFieldDef -> EmbedFieldDef -> Bool
(EmbedFieldDef -> EmbedFieldDef -> Bool)
-> (EmbedFieldDef -> EmbedFieldDef -> Bool) -> Eq EmbedFieldDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmbedFieldDef -> EmbedFieldDef -> Bool
== :: EmbedFieldDef -> EmbedFieldDef -> Bool
$c/= :: EmbedFieldDef -> EmbedFieldDef -> Bool
/= :: EmbedFieldDef -> EmbedFieldDef -> Bool
Eq, ReadPrec [EmbedFieldDef]
ReadPrec EmbedFieldDef
Int -> ReadS EmbedFieldDef
ReadS [EmbedFieldDef]
(Int -> ReadS EmbedFieldDef)
-> ReadS [EmbedFieldDef]
-> ReadPrec EmbedFieldDef
-> ReadPrec [EmbedFieldDef]
-> Read EmbedFieldDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EmbedFieldDef
readsPrec :: Int -> ReadS EmbedFieldDef
$creadList :: ReadS [EmbedFieldDef]
readList :: ReadS [EmbedFieldDef]
$creadPrec :: ReadPrec EmbedFieldDef
readPrec :: ReadPrec EmbedFieldDef
$creadListPrec :: ReadPrec [EmbedFieldDef]
readListPrec :: ReadPrec [EmbedFieldDef]
Read, Eq EmbedFieldDef
Eq EmbedFieldDef =>
(EmbedFieldDef -> EmbedFieldDef -> Ordering)
-> (EmbedFieldDef -> EmbedFieldDef -> Bool)
-> (EmbedFieldDef -> EmbedFieldDef -> Bool)
-> (EmbedFieldDef -> EmbedFieldDef -> Bool)
-> (EmbedFieldDef -> EmbedFieldDef -> Bool)
-> (EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef)
-> (EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef)
-> Ord EmbedFieldDef
EmbedFieldDef -> EmbedFieldDef -> Bool
EmbedFieldDef -> EmbedFieldDef -> Ordering
EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EmbedFieldDef -> EmbedFieldDef -> Ordering
compare :: EmbedFieldDef -> EmbedFieldDef -> Ordering
$c< :: EmbedFieldDef -> EmbedFieldDef -> Bool
< :: EmbedFieldDef -> EmbedFieldDef -> Bool
$c<= :: EmbedFieldDef -> EmbedFieldDef -> Bool
<= :: EmbedFieldDef -> EmbedFieldDef -> Bool
$c> :: EmbedFieldDef -> EmbedFieldDef -> Bool
> :: EmbedFieldDef -> EmbedFieldDef -> Bool
$c>= :: EmbedFieldDef -> EmbedFieldDef -> Bool
>= :: EmbedFieldDef -> EmbedFieldDef -> Bool
$cmax :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef
max :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef
$cmin :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef
min :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef
Ord, (forall (m :: * -> *). Quote m => EmbedFieldDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
EmbedFieldDef -> Code m EmbedFieldDef)
-> Lift EmbedFieldDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => EmbedFieldDef -> m Exp
forall (m :: * -> *).
Quote m =>
EmbedFieldDef -> Code m EmbedFieldDef
$clift :: forall (m :: * -> *). Quote m => EmbedFieldDef -> m Exp
lift :: forall (m :: * -> *). Quote m => EmbedFieldDef -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
EmbedFieldDef -> Code m EmbedFieldDef
liftTyped :: forall (m :: * -> *).
Quote m =>
EmbedFieldDef -> Code m EmbedFieldDef
Lift)
data SelfEmbed = SelfEmbed
deriving (Int -> SelfEmbed -> ShowS
[SelfEmbed] -> ShowS
SelfEmbed -> [Char]
(Int -> SelfEmbed -> ShowS)
-> (SelfEmbed -> [Char])
-> ([SelfEmbed] -> ShowS)
-> Show SelfEmbed
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SelfEmbed -> ShowS
showsPrec :: Int -> SelfEmbed -> ShowS
$cshow :: SelfEmbed -> [Char]
show :: SelfEmbed -> [Char]
$cshowList :: [SelfEmbed] -> ShowS
showList :: [SelfEmbed] -> ShowS
Show, SelfEmbed -> SelfEmbed -> Bool
(SelfEmbed -> SelfEmbed -> Bool)
-> (SelfEmbed -> SelfEmbed -> Bool) -> Eq SelfEmbed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SelfEmbed -> SelfEmbed -> Bool
== :: SelfEmbed -> SelfEmbed -> Bool
$c/= :: SelfEmbed -> SelfEmbed -> Bool
/= :: SelfEmbed -> SelfEmbed -> Bool
Eq, ReadPrec [SelfEmbed]
ReadPrec SelfEmbed
Int -> ReadS SelfEmbed
ReadS [SelfEmbed]
(Int -> ReadS SelfEmbed)
-> ReadS [SelfEmbed]
-> ReadPrec SelfEmbed
-> ReadPrec [SelfEmbed]
-> Read SelfEmbed
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SelfEmbed
readsPrec :: Int -> ReadS SelfEmbed
$creadList :: ReadS [SelfEmbed]
readList :: ReadS [SelfEmbed]
$creadPrec :: ReadPrec SelfEmbed
readPrec :: ReadPrec SelfEmbed
$creadListPrec :: ReadPrec [SelfEmbed]
readListPrec :: ReadPrec [SelfEmbed]
Read, Eq SelfEmbed
Eq SelfEmbed =>
(SelfEmbed -> SelfEmbed -> Ordering)
-> (SelfEmbed -> SelfEmbed -> Bool)
-> (SelfEmbed -> SelfEmbed -> Bool)
-> (SelfEmbed -> SelfEmbed -> Bool)
-> (SelfEmbed -> SelfEmbed -> Bool)
-> (SelfEmbed -> SelfEmbed -> SelfEmbed)
-> (SelfEmbed -> SelfEmbed -> SelfEmbed)
-> Ord SelfEmbed
SelfEmbed -> SelfEmbed -> Bool
SelfEmbed -> SelfEmbed -> Ordering
SelfEmbed -> SelfEmbed -> SelfEmbed
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SelfEmbed -> SelfEmbed -> Ordering
compare :: SelfEmbed -> SelfEmbed -> Ordering
$c< :: SelfEmbed -> SelfEmbed -> Bool
< :: SelfEmbed -> SelfEmbed -> Bool
$c<= :: SelfEmbed -> SelfEmbed -> Bool
<= :: SelfEmbed -> SelfEmbed -> Bool
$c> :: SelfEmbed -> SelfEmbed -> Bool
> :: SelfEmbed -> SelfEmbed -> Bool
$c>= :: SelfEmbed -> SelfEmbed -> Bool
>= :: SelfEmbed -> SelfEmbed -> Bool
$cmax :: SelfEmbed -> SelfEmbed -> SelfEmbed
max :: SelfEmbed -> SelfEmbed -> SelfEmbed
$cmin :: SelfEmbed -> SelfEmbed -> SelfEmbed
min :: SelfEmbed -> SelfEmbed -> SelfEmbed
Ord, (forall (m :: * -> *). Quote m => SelfEmbed -> m Exp)
-> (forall (m :: * -> *). Quote m => SelfEmbed -> Code m SelfEmbed)
-> Lift SelfEmbed
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => SelfEmbed -> m Exp
forall (m :: * -> *). Quote m => SelfEmbed -> Code m SelfEmbed
$clift :: forall (m :: * -> *). Quote m => SelfEmbed -> m Exp
lift :: forall (m :: * -> *). Quote m => SelfEmbed -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => SelfEmbed -> Code m SelfEmbed
liftTyped :: forall (m :: * -> *). Quote m => SelfEmbed -> Code m SelfEmbed
Lift)
isHaskellField :: FieldDef -> Bool
isHaskellField :: FieldDef -> Bool
isHaskellField FieldDef
fd =
FieldAttr
FieldAttrMigrationOnly FieldAttr -> [FieldAttr] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` FieldDef -> [FieldAttr]
fieldAttrs FieldDef
fd Bool -> Bool -> Bool
&&
FieldAttr
FieldAttrSafeToRemove FieldAttr -> [FieldAttr] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` FieldDef -> [FieldAttr]
fieldAttrs FieldDef
fd
toEmbedEntityDef :: EntityDef -> EmbedEntityDef
toEmbedEntityDef :: EntityDef -> EmbedEntityDef
toEmbedEntityDef EntityDef
ent = EmbedEntityDef
embDef
where
embDef :: EmbedEntityDef
embDef = EmbedEntityDef
{ embeddedHaskell :: EntityNameHS
embeddedHaskell = EntityDef -> EntityNameHS
entityHaskell EntityDef
ent
, embeddedFields :: [EmbedFieldDef]
embeddedFields =
(FieldDef -> EmbedFieldDef) -> [FieldDef] -> [EmbedFieldDef]
forall a b. (a -> b) -> [a] -> [b]
map FieldDef -> EmbedFieldDef
toEmbedFieldDef
([FieldDef] -> [EmbedFieldDef]) -> [FieldDef] -> [EmbedFieldDef]
forall a b. (a -> b) -> a -> b
$ (FieldDef -> Bool) -> [FieldDef] -> [FieldDef]
forall a. (a -> Bool) -> [a] -> [a]
filter FieldDef -> Bool
isHaskellField
([FieldDef] -> [FieldDef]) -> [FieldDef] -> [FieldDef]
forall a b. (a -> b) -> a -> b
$ EntityDef -> [FieldDef]
entityFields EntityDef
ent
}
toEmbedFieldDef :: FieldDef -> EmbedFieldDef
toEmbedFieldDef :: FieldDef -> EmbedFieldDef
toEmbedFieldDef FieldDef
field =
EmbedFieldDef
{ emFieldDB :: FieldNameDB
emFieldDB =
FieldDef -> FieldNameDB
fieldDB FieldDef
field
, emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)
emFieldEmbed =
case FieldDef -> ReferenceDef
fieldReference FieldDef
field of
EmbedRef EntityNameHS
em ->
Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS)
forall a. a -> Maybe a
Just (Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS))
-> Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS)
forall a b. (a -> b) -> a -> b
$ EntityNameHS -> Either SelfEmbed EntityNameHS
forall a b. b -> Either a b
Right EntityNameHS
em
ReferenceDef
SelfReference -> Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS)
forall a. a -> Maybe a
Just (Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS))
-> Either SelfEmbed EntityNameHS
-> Maybe (Either SelfEmbed EntityNameHS)
forall a b. (a -> b) -> a -> b
$ SelfEmbed -> Either SelfEmbed EntityNameHS
forall a b. a -> Either a b
Left SelfEmbed
SelfEmbed
ReferenceDef
_ -> Maybe (Either SelfEmbed EntityNameHS)
forall a. Maybe a
Nothing
}
data UniqueDef = UniqueDef
{ UniqueDef -> ConstraintNameHS
uniqueHaskell :: !ConstraintNameHS
, UniqueDef -> ConstraintNameDB
uniqueDBName :: !ConstraintNameDB
, UniqueDef -> NonEmpty (FieldNameHS, FieldNameDB)
uniqueFields :: !(NonEmpty (FieldNameHS, FieldNameDB))
, UniqueDef -> [Text]
uniqueAttrs :: ![Attr]
}
deriving (Int -> UniqueDef -> ShowS
[UniqueDef] -> ShowS
UniqueDef -> [Char]
(Int -> UniqueDef -> ShowS)
-> (UniqueDef -> [Char])
-> ([UniqueDef] -> ShowS)
-> Show UniqueDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UniqueDef -> ShowS
showsPrec :: Int -> UniqueDef -> ShowS
$cshow :: UniqueDef -> [Char]
show :: UniqueDef -> [Char]
$cshowList :: [UniqueDef] -> ShowS
showList :: [UniqueDef] -> ShowS
Show, UniqueDef -> UniqueDef -> Bool
(UniqueDef -> UniqueDef -> Bool)
-> (UniqueDef -> UniqueDef -> Bool) -> Eq UniqueDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UniqueDef -> UniqueDef -> Bool
== :: UniqueDef -> UniqueDef -> Bool
$c/= :: UniqueDef -> UniqueDef -> Bool
/= :: UniqueDef -> UniqueDef -> Bool
Eq, ReadPrec [UniqueDef]
ReadPrec UniqueDef
Int -> ReadS UniqueDef
ReadS [UniqueDef]
(Int -> ReadS UniqueDef)
-> ReadS [UniqueDef]
-> ReadPrec UniqueDef
-> ReadPrec [UniqueDef]
-> Read UniqueDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS UniqueDef
readsPrec :: Int -> ReadS UniqueDef
$creadList :: ReadS [UniqueDef]
readList :: ReadS [UniqueDef]
$creadPrec :: ReadPrec UniqueDef
readPrec :: ReadPrec UniqueDef
$creadListPrec :: ReadPrec [UniqueDef]
readListPrec :: ReadPrec [UniqueDef]
Read, Eq UniqueDef
Eq UniqueDef =>
(UniqueDef -> UniqueDef -> Ordering)
-> (UniqueDef -> UniqueDef -> Bool)
-> (UniqueDef -> UniqueDef -> Bool)
-> (UniqueDef -> UniqueDef -> Bool)
-> (UniqueDef -> UniqueDef -> Bool)
-> (UniqueDef -> UniqueDef -> UniqueDef)
-> (UniqueDef -> UniqueDef -> UniqueDef)
-> Ord UniqueDef
UniqueDef -> UniqueDef -> Bool
UniqueDef -> UniqueDef -> Ordering
UniqueDef -> UniqueDef -> UniqueDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UniqueDef -> UniqueDef -> Ordering
compare :: UniqueDef -> UniqueDef -> Ordering
$c< :: UniqueDef -> UniqueDef -> Bool
< :: UniqueDef -> UniqueDef -> Bool
$c<= :: UniqueDef -> UniqueDef -> Bool
<= :: UniqueDef -> UniqueDef -> Bool
$c> :: UniqueDef -> UniqueDef -> Bool
> :: UniqueDef -> UniqueDef -> Bool
$c>= :: UniqueDef -> UniqueDef -> Bool
>= :: UniqueDef -> UniqueDef -> Bool
$cmax :: UniqueDef -> UniqueDef -> UniqueDef
max :: UniqueDef -> UniqueDef -> UniqueDef
$cmin :: UniqueDef -> UniqueDef -> UniqueDef
min :: UniqueDef -> UniqueDef -> UniqueDef
Ord, (forall (m :: * -> *). Quote m => UniqueDef -> m Exp)
-> (forall (m :: * -> *). Quote m => UniqueDef -> Code m UniqueDef)
-> Lift UniqueDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => UniqueDef -> m Exp
forall (m :: * -> *). Quote m => UniqueDef -> Code m UniqueDef
$clift :: forall (m :: * -> *). Quote m => UniqueDef -> m Exp
lift :: forall (m :: * -> *). Quote m => UniqueDef -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => UniqueDef -> Code m UniqueDef
liftTyped :: forall (m :: * -> *). Quote m => UniqueDef -> Code m UniqueDef
Lift)
data CompositeDef = CompositeDef
{ CompositeDef -> NonEmpty FieldDef
compositeFields :: !(NonEmpty FieldDef)
, CompositeDef -> [Text]
compositeAttrs :: ![Attr]
}
deriving (Int -> CompositeDef -> ShowS
[CompositeDef] -> ShowS
CompositeDef -> [Char]
(Int -> CompositeDef -> ShowS)
-> (CompositeDef -> [Char])
-> ([CompositeDef] -> ShowS)
-> Show CompositeDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompositeDef -> ShowS
showsPrec :: Int -> CompositeDef -> ShowS
$cshow :: CompositeDef -> [Char]
show :: CompositeDef -> [Char]
$cshowList :: [CompositeDef] -> ShowS
showList :: [CompositeDef] -> ShowS
Show, CompositeDef -> CompositeDef -> Bool
(CompositeDef -> CompositeDef -> Bool)
-> (CompositeDef -> CompositeDef -> Bool) -> Eq CompositeDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompositeDef -> CompositeDef -> Bool
== :: CompositeDef -> CompositeDef -> Bool
$c/= :: CompositeDef -> CompositeDef -> Bool
/= :: CompositeDef -> CompositeDef -> Bool
Eq, ReadPrec [CompositeDef]
ReadPrec CompositeDef
Int -> ReadS CompositeDef
ReadS [CompositeDef]
(Int -> ReadS CompositeDef)
-> ReadS [CompositeDef]
-> ReadPrec CompositeDef
-> ReadPrec [CompositeDef]
-> Read CompositeDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CompositeDef
readsPrec :: Int -> ReadS CompositeDef
$creadList :: ReadS [CompositeDef]
readList :: ReadS [CompositeDef]
$creadPrec :: ReadPrec CompositeDef
readPrec :: ReadPrec CompositeDef
$creadListPrec :: ReadPrec [CompositeDef]
readListPrec :: ReadPrec [CompositeDef]
Read, Eq CompositeDef
Eq CompositeDef =>
(CompositeDef -> CompositeDef -> Ordering)
-> (CompositeDef -> CompositeDef -> Bool)
-> (CompositeDef -> CompositeDef -> Bool)
-> (CompositeDef -> CompositeDef -> Bool)
-> (CompositeDef -> CompositeDef -> Bool)
-> (CompositeDef -> CompositeDef -> CompositeDef)
-> (CompositeDef -> CompositeDef -> CompositeDef)
-> Ord CompositeDef
CompositeDef -> CompositeDef -> Bool
CompositeDef -> CompositeDef -> Ordering
CompositeDef -> CompositeDef -> CompositeDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CompositeDef -> CompositeDef -> Ordering
compare :: CompositeDef -> CompositeDef -> Ordering
$c< :: CompositeDef -> CompositeDef -> Bool
< :: CompositeDef -> CompositeDef -> Bool
$c<= :: CompositeDef -> CompositeDef -> Bool
<= :: CompositeDef -> CompositeDef -> Bool
$c> :: CompositeDef -> CompositeDef -> Bool
> :: CompositeDef -> CompositeDef -> Bool
$c>= :: CompositeDef -> CompositeDef -> Bool
>= :: CompositeDef -> CompositeDef -> Bool
$cmax :: CompositeDef -> CompositeDef -> CompositeDef
max :: CompositeDef -> CompositeDef -> CompositeDef
$cmin :: CompositeDef -> CompositeDef -> CompositeDef
min :: CompositeDef -> CompositeDef -> CompositeDef
Ord, (forall (m :: * -> *). Quote m => CompositeDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
CompositeDef -> Code m CompositeDef)
-> Lift CompositeDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => CompositeDef -> m Exp
forall (m :: * -> *).
Quote m =>
CompositeDef -> Code m CompositeDef
$clift :: forall (m :: * -> *). Quote m => CompositeDef -> m Exp
lift :: forall (m :: * -> *). Quote m => CompositeDef -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
CompositeDef -> Code m CompositeDef
liftTyped :: forall (m :: * -> *).
Quote m =>
CompositeDef -> Code m CompositeDef
Lift)
type ForeignFieldDef = (FieldNameHS, FieldNameDB)
data ForeignDef = ForeignDef
{ ForeignDef -> EntityNameHS
foreignRefTableHaskell :: !EntityNameHS
, ForeignDef -> EntityNameDB
foreignRefTableDBName :: !EntityNameDB
, ForeignDef -> ConstraintNameHS
foreignConstraintNameHaskell :: !ConstraintNameHS
, ForeignDef -> ConstraintNameDB
foreignConstraintNameDBName :: !ConstraintNameDB
, ForeignDef -> FieldCascade
foreignFieldCascade :: !FieldCascade
, ForeignDef
-> [((FieldNameHS, FieldNameDB), (FieldNameHS, FieldNameDB))]
foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
, ForeignDef -> [Text]
foreignAttrs :: ![Attr]
, ForeignDef -> Bool
foreignNullable :: Bool
, ForeignDef -> Bool
foreignToPrimary :: Bool
}
deriving (Int -> ForeignDef -> ShowS
[ForeignDef] -> ShowS
ForeignDef -> [Char]
(Int -> ForeignDef -> ShowS)
-> (ForeignDef -> [Char])
-> ([ForeignDef] -> ShowS)
-> Show ForeignDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ForeignDef -> ShowS
showsPrec :: Int -> ForeignDef -> ShowS
$cshow :: ForeignDef -> [Char]
show :: ForeignDef -> [Char]
$cshowList :: [ForeignDef] -> ShowS
showList :: [ForeignDef] -> ShowS
Show, ForeignDef -> ForeignDef -> Bool
(ForeignDef -> ForeignDef -> Bool)
-> (ForeignDef -> ForeignDef -> Bool) -> Eq ForeignDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ForeignDef -> ForeignDef -> Bool
== :: ForeignDef -> ForeignDef -> Bool
$c/= :: ForeignDef -> ForeignDef -> Bool
/= :: ForeignDef -> ForeignDef -> Bool
Eq, ReadPrec [ForeignDef]
ReadPrec ForeignDef
Int -> ReadS ForeignDef
ReadS [ForeignDef]
(Int -> ReadS ForeignDef)
-> ReadS [ForeignDef]
-> ReadPrec ForeignDef
-> ReadPrec [ForeignDef]
-> Read ForeignDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ForeignDef
readsPrec :: Int -> ReadS ForeignDef
$creadList :: ReadS [ForeignDef]
readList :: ReadS [ForeignDef]
$creadPrec :: ReadPrec ForeignDef
readPrec :: ReadPrec ForeignDef
$creadListPrec :: ReadPrec [ForeignDef]
readListPrec :: ReadPrec [ForeignDef]
Read, Eq ForeignDef
Eq ForeignDef =>
(ForeignDef -> ForeignDef -> Ordering)
-> (ForeignDef -> ForeignDef -> Bool)
-> (ForeignDef -> ForeignDef -> Bool)
-> (ForeignDef -> ForeignDef -> Bool)
-> (ForeignDef -> ForeignDef -> Bool)
-> (ForeignDef -> ForeignDef -> ForeignDef)
-> (ForeignDef -> ForeignDef -> ForeignDef)
-> Ord ForeignDef
ForeignDef -> ForeignDef -> Bool
ForeignDef -> ForeignDef -> Ordering
ForeignDef -> ForeignDef -> ForeignDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ForeignDef -> ForeignDef -> Ordering
compare :: ForeignDef -> ForeignDef -> Ordering
$c< :: ForeignDef -> ForeignDef -> Bool
< :: ForeignDef -> ForeignDef -> Bool
$c<= :: ForeignDef -> ForeignDef -> Bool
<= :: ForeignDef -> ForeignDef -> Bool
$c> :: ForeignDef -> ForeignDef -> Bool
> :: ForeignDef -> ForeignDef -> Bool
$c>= :: ForeignDef -> ForeignDef -> Bool
>= :: ForeignDef -> ForeignDef -> Bool
$cmax :: ForeignDef -> ForeignDef -> ForeignDef
max :: ForeignDef -> ForeignDef -> ForeignDef
$cmin :: ForeignDef -> ForeignDef -> ForeignDef
min :: ForeignDef -> ForeignDef -> ForeignDef
Ord, (forall (m :: * -> *). Quote m => ForeignDef -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
ForeignDef -> Code m ForeignDef)
-> Lift ForeignDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => ForeignDef -> m Exp
forall (m :: * -> *). Quote m => ForeignDef -> Code m ForeignDef
$clift :: forall (m :: * -> *). Quote m => ForeignDef -> m Exp
lift :: forall (m :: * -> *). Quote m => ForeignDef -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => ForeignDef -> Code m ForeignDef
liftTyped :: forall (m :: * -> *). Quote m => ForeignDef -> Code m ForeignDef
Lift)
data FieldCascade = FieldCascade
{ FieldCascade -> Maybe CascadeAction
fcOnUpdate :: !(Maybe CascadeAction)
, FieldCascade -> Maybe CascadeAction
fcOnDelete :: !(Maybe CascadeAction)
}
deriving (Int -> FieldCascade -> ShowS
[FieldCascade] -> ShowS
FieldCascade -> [Char]
(Int -> FieldCascade -> ShowS)
-> (FieldCascade -> [Char])
-> ([FieldCascade] -> ShowS)
-> Show FieldCascade
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FieldCascade -> ShowS
showsPrec :: Int -> FieldCascade -> ShowS
$cshow :: FieldCascade -> [Char]
show :: FieldCascade -> [Char]
$cshowList :: [FieldCascade] -> ShowS
showList :: [FieldCascade] -> ShowS
Show, FieldCascade -> FieldCascade -> Bool
(FieldCascade -> FieldCascade -> Bool)
-> (FieldCascade -> FieldCascade -> Bool) -> Eq FieldCascade
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FieldCascade -> FieldCascade -> Bool
== :: FieldCascade -> FieldCascade -> Bool
$c/= :: FieldCascade -> FieldCascade -> Bool
/= :: FieldCascade -> FieldCascade -> Bool
Eq, ReadPrec [FieldCascade]
ReadPrec FieldCascade
Int -> ReadS FieldCascade
ReadS [FieldCascade]
(Int -> ReadS FieldCascade)
-> ReadS [FieldCascade]
-> ReadPrec FieldCascade
-> ReadPrec [FieldCascade]
-> Read FieldCascade
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FieldCascade
readsPrec :: Int -> ReadS FieldCascade
$creadList :: ReadS [FieldCascade]
readList :: ReadS [FieldCascade]
$creadPrec :: ReadPrec FieldCascade
readPrec :: ReadPrec FieldCascade
$creadListPrec :: ReadPrec [FieldCascade]
readListPrec :: ReadPrec [FieldCascade]
Read, Eq FieldCascade
Eq FieldCascade =>
(FieldCascade -> FieldCascade -> Ordering)
-> (FieldCascade -> FieldCascade -> Bool)
-> (FieldCascade -> FieldCascade -> Bool)
-> (FieldCascade -> FieldCascade -> Bool)
-> (FieldCascade -> FieldCascade -> Bool)
-> (FieldCascade -> FieldCascade -> FieldCascade)
-> (FieldCascade -> FieldCascade -> FieldCascade)
-> Ord FieldCascade
FieldCascade -> FieldCascade -> Bool
FieldCascade -> FieldCascade -> Ordering
FieldCascade -> FieldCascade -> FieldCascade
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FieldCascade -> FieldCascade -> Ordering
compare :: FieldCascade -> FieldCascade -> Ordering
$c< :: FieldCascade -> FieldCascade -> Bool
< :: FieldCascade -> FieldCascade -> Bool
$c<= :: FieldCascade -> FieldCascade -> Bool
<= :: FieldCascade -> FieldCascade -> Bool
$c> :: FieldCascade -> FieldCascade -> Bool
> :: FieldCascade -> FieldCascade -> Bool
$c>= :: FieldCascade -> FieldCascade -> Bool
>= :: FieldCascade -> FieldCascade -> Bool
$cmax :: FieldCascade -> FieldCascade -> FieldCascade
max :: FieldCascade -> FieldCascade -> FieldCascade
$cmin :: FieldCascade -> FieldCascade -> FieldCascade
min :: FieldCascade -> FieldCascade -> FieldCascade
Ord, (forall (m :: * -> *). Quote m => FieldCascade -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
FieldCascade -> Code m FieldCascade)
-> Lift FieldCascade
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FieldCascade -> m Exp
forall (m :: * -> *).
Quote m =>
FieldCascade -> Code m FieldCascade
$clift :: forall (m :: * -> *). Quote m => FieldCascade -> m Exp
lift :: forall (m :: * -> *). Quote m => FieldCascade -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
FieldCascade -> Code m FieldCascade
liftTyped :: forall (m :: * -> *).
Quote m =>
FieldCascade -> Code m FieldCascade
Lift)
noCascade :: FieldCascade
noCascade :: FieldCascade
noCascade = Maybe CascadeAction -> Maybe CascadeAction -> FieldCascade
FieldCascade Maybe CascadeAction
forall a. Maybe a
Nothing Maybe CascadeAction
forall a. Maybe a
Nothing
renderFieldCascade :: FieldCascade -> Text
renderFieldCascade :: FieldCascade -> Text
renderFieldCascade (FieldCascade Maybe CascadeAction
onUpdate Maybe CascadeAction
onDelete) =
[Text] -> Text
T.unwords
[ (CascadeAction -> Text) -> Maybe CascadeAction -> Text
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend Text
" ON DELETE " (Text -> Text) -> (CascadeAction -> Text) -> CascadeAction -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CascadeAction -> Text
renderCascadeAction) Maybe CascadeAction
onDelete
, (CascadeAction -> Text) -> Maybe CascadeAction -> Text
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend Text
" ON UPDATE " (Text -> Text) -> (CascadeAction -> Text) -> CascadeAction -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CascadeAction -> Text
renderCascadeAction) Maybe CascadeAction
onUpdate
]
data CascadeAction = Cascade | Restrict | SetNull | SetDefault
deriving (Int -> CascadeAction -> ShowS
[CascadeAction] -> ShowS
CascadeAction -> [Char]
(Int -> CascadeAction -> ShowS)
-> (CascadeAction -> [Char])
-> ([CascadeAction] -> ShowS)
-> Show CascadeAction
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CascadeAction -> ShowS
showsPrec :: Int -> CascadeAction -> ShowS
$cshow :: CascadeAction -> [Char]
show :: CascadeAction -> [Char]
$cshowList :: [CascadeAction] -> ShowS
showList :: [CascadeAction] -> ShowS
Show, CascadeAction -> CascadeAction -> Bool
(CascadeAction -> CascadeAction -> Bool)
-> (CascadeAction -> CascadeAction -> Bool) -> Eq CascadeAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CascadeAction -> CascadeAction -> Bool
== :: CascadeAction -> CascadeAction -> Bool
$c/= :: CascadeAction -> CascadeAction -> Bool
/= :: CascadeAction -> CascadeAction -> Bool
Eq, ReadPrec [CascadeAction]
ReadPrec CascadeAction
Int -> ReadS CascadeAction
ReadS [CascadeAction]
(Int -> ReadS CascadeAction)
-> ReadS [CascadeAction]
-> ReadPrec CascadeAction
-> ReadPrec [CascadeAction]
-> Read CascadeAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CascadeAction
readsPrec :: Int -> ReadS CascadeAction
$creadList :: ReadS [CascadeAction]
readList :: ReadS [CascadeAction]
$creadPrec :: ReadPrec CascadeAction
readPrec :: ReadPrec CascadeAction
$creadListPrec :: ReadPrec [CascadeAction]
readListPrec :: ReadPrec [CascadeAction]
Read, Eq CascadeAction
Eq CascadeAction =>
(CascadeAction -> CascadeAction -> Ordering)
-> (CascadeAction -> CascadeAction -> Bool)
-> (CascadeAction -> CascadeAction -> Bool)
-> (CascadeAction -> CascadeAction -> Bool)
-> (CascadeAction -> CascadeAction -> Bool)
-> (CascadeAction -> CascadeAction -> CascadeAction)
-> (CascadeAction -> CascadeAction -> CascadeAction)
-> Ord CascadeAction
CascadeAction -> CascadeAction -> Bool
CascadeAction -> CascadeAction -> Ordering
CascadeAction -> CascadeAction -> CascadeAction
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CascadeAction -> CascadeAction -> Ordering
compare :: CascadeAction -> CascadeAction -> Ordering
$c< :: CascadeAction -> CascadeAction -> Bool
< :: CascadeAction -> CascadeAction -> Bool
$c<= :: CascadeAction -> CascadeAction -> Bool
<= :: CascadeAction -> CascadeAction -> Bool
$c> :: CascadeAction -> CascadeAction -> Bool
> :: CascadeAction -> CascadeAction -> Bool
$c>= :: CascadeAction -> CascadeAction -> Bool
>= :: CascadeAction -> CascadeAction -> Bool
$cmax :: CascadeAction -> CascadeAction -> CascadeAction
max :: CascadeAction -> CascadeAction -> CascadeAction
$cmin :: CascadeAction -> CascadeAction -> CascadeAction
min :: CascadeAction -> CascadeAction -> CascadeAction
Ord, (forall (m :: * -> *). Quote m => CascadeAction -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
CascadeAction -> Code m CascadeAction)
-> Lift CascadeAction
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => CascadeAction -> m Exp
forall (m :: * -> *).
Quote m =>
CascadeAction -> Code m CascadeAction
$clift :: forall (m :: * -> *). Quote m => CascadeAction -> m Exp
lift :: forall (m :: * -> *). Quote m => CascadeAction -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
CascadeAction -> Code m CascadeAction
liftTyped :: forall (m :: * -> *).
Quote m =>
CascadeAction -> Code m CascadeAction
Lift)
renderCascadeAction :: CascadeAction -> Text
renderCascadeAction :: CascadeAction -> Text
renderCascadeAction CascadeAction
action = case CascadeAction
action of
CascadeAction
Cascade -> Text
"CASCADE"
CascadeAction
Restrict -> Text
"RESTRICT"
CascadeAction
SetNull -> Text
"SET NULL"
CascadeAction
SetDefault -> Text
"SET DEFAULT"
data PersistException
= PersistError Text
| PersistMarshalError Text
| PersistInvalidField Text
| PersistForeignConstraintUnmet Text
| PersistMongoDBError Text
| PersistMongoDBUnsupported Text
deriving Int -> PersistException -> ShowS
[PersistException] -> ShowS
PersistException -> [Char]
(Int -> PersistException -> ShowS)
-> (PersistException -> [Char])
-> ([PersistException] -> ShowS)
-> Show PersistException
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PersistException -> ShowS
showsPrec :: Int -> PersistException -> ShowS
$cshow :: PersistException -> [Char]
show :: PersistException -> [Char]
$cshowList :: [PersistException] -> ShowS
showList :: [PersistException] -> ShowS
Show
instance Exception PersistException
data SqlType = SqlString
| SqlInt32
| SqlInt64
| SqlReal
| SqlNumeric Word32 Word32
| SqlBool
| SqlDay
| SqlTime
| SqlDayTime
| SqlBlob
| SqlOther T.Text
deriving (Int -> SqlType -> ShowS
[SqlType] -> ShowS
SqlType -> [Char]
(Int -> SqlType -> ShowS)
-> (SqlType -> [Char]) -> ([SqlType] -> ShowS) -> Show SqlType
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SqlType -> ShowS
showsPrec :: Int -> SqlType -> ShowS
$cshow :: SqlType -> [Char]
show :: SqlType -> [Char]
$cshowList :: [SqlType] -> ShowS
showList :: [SqlType] -> ShowS
Show, ReadPrec [SqlType]
ReadPrec SqlType
Int -> ReadS SqlType
ReadS [SqlType]
(Int -> ReadS SqlType)
-> ReadS [SqlType]
-> ReadPrec SqlType
-> ReadPrec [SqlType]
-> Read SqlType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SqlType
readsPrec :: Int -> ReadS SqlType
$creadList :: ReadS [SqlType]
readList :: ReadS [SqlType]
$creadPrec :: ReadPrec SqlType
readPrec :: ReadPrec SqlType
$creadListPrec :: ReadPrec [SqlType]
readListPrec :: ReadPrec [SqlType]
Read, SqlType -> SqlType -> Bool
(SqlType -> SqlType -> Bool)
-> (SqlType -> SqlType -> Bool) -> Eq SqlType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SqlType -> SqlType -> Bool
== :: SqlType -> SqlType -> Bool
$c/= :: SqlType -> SqlType -> Bool
/= :: SqlType -> SqlType -> Bool
Eq, Eq SqlType
Eq SqlType =>
(SqlType -> SqlType -> Ordering)
-> (SqlType -> SqlType -> Bool)
-> (SqlType -> SqlType -> Bool)
-> (SqlType -> SqlType -> Bool)
-> (SqlType -> SqlType -> Bool)
-> (SqlType -> SqlType -> SqlType)
-> (SqlType -> SqlType -> SqlType)
-> Ord SqlType
SqlType -> SqlType -> Bool
SqlType -> SqlType -> Ordering
SqlType -> SqlType -> SqlType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SqlType -> SqlType -> Ordering
compare :: SqlType -> SqlType -> Ordering
$c< :: SqlType -> SqlType -> Bool
< :: SqlType -> SqlType -> Bool
$c<= :: SqlType -> SqlType -> Bool
<= :: SqlType -> SqlType -> Bool
$c> :: SqlType -> SqlType -> Bool
> :: SqlType -> SqlType -> Bool
$c>= :: SqlType -> SqlType -> Bool
>= :: SqlType -> SqlType -> Bool
$cmax :: SqlType -> SqlType -> SqlType
max :: SqlType -> SqlType -> SqlType
$cmin :: SqlType -> SqlType -> SqlType
min :: SqlType -> SqlType -> SqlType
Ord, (forall (m :: * -> *). Quote m => SqlType -> m Exp)
-> (forall (m :: * -> *). Quote m => SqlType -> Code m SqlType)
-> Lift SqlType
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => SqlType -> m Exp
forall (m :: * -> *). Quote m => SqlType -> Code m SqlType
$clift :: forall (m :: * -> *). Quote m => SqlType -> m Exp
lift :: forall (m :: * -> *). Quote m => SqlType -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => SqlType -> Code m SqlType
liftTyped :: forall (m :: * -> *). Quote m => SqlType -> Code m SqlType
Lift)
data PersistFilter = Eq | Ne | Gt | Lt | Ge | Le | In | NotIn
| BackendSpecificFilter T.Text
deriving (ReadPrec [PersistFilter]
ReadPrec PersistFilter
Int -> ReadS PersistFilter
ReadS [PersistFilter]
(Int -> ReadS PersistFilter)
-> ReadS [PersistFilter]
-> ReadPrec PersistFilter
-> ReadPrec [PersistFilter]
-> Read PersistFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PersistFilter
readsPrec :: Int -> ReadS PersistFilter
$creadList :: ReadS [PersistFilter]
readList :: ReadS [PersistFilter]
$creadPrec :: ReadPrec PersistFilter
readPrec :: ReadPrec PersistFilter
$creadListPrec :: ReadPrec [PersistFilter]
readListPrec :: ReadPrec [PersistFilter]
Read, Int -> PersistFilter -> ShowS
[PersistFilter] -> ShowS
PersistFilter -> [Char]
(Int -> PersistFilter -> ShowS)
-> (PersistFilter -> [Char])
-> ([PersistFilter] -> ShowS)
-> Show PersistFilter
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PersistFilter -> ShowS
showsPrec :: Int -> PersistFilter -> ShowS
$cshow :: PersistFilter -> [Char]
show :: PersistFilter -> [Char]
$cshowList :: [PersistFilter] -> ShowS
showList :: [PersistFilter] -> ShowS
Show, (forall (m :: * -> *). Quote m => PersistFilter -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
PersistFilter -> Code m PersistFilter)
-> Lift PersistFilter
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => PersistFilter -> m Exp
forall (m :: * -> *).
Quote m =>
PersistFilter -> Code m PersistFilter
$clift :: forall (m :: * -> *). Quote m => PersistFilter -> m Exp
lift :: forall (m :: * -> *). Quote m => PersistFilter -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
PersistFilter -> Code m PersistFilter
liftTyped :: forall (m :: * -> *).
Quote m =>
PersistFilter -> Code m PersistFilter
Lift)
data UpdateException = KeyNotFound String
| UpsertError String
instance Show UpdateException where
show :: UpdateException -> [Char]
show (KeyNotFound [Char]
key) = [Char]
"Key not found during updateGet: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
key
show (UpsertError [Char]
msg) = [Char]
"Error during upsert: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
msg
instance Exception UpdateException
data OnlyUniqueException = OnlyUniqueException String
instance Show OnlyUniqueException where
show :: OnlyUniqueException -> [Char]
show (OnlyUniqueException [Char]
uniqueMsg) =
[Char]
"Expected only one unique key, got " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
uniqueMsg
instance Exception OnlyUniqueException
data PersistUpdate
= Assign | Add | Subtract | Multiply | Divide
| BackendSpecificUpdate T.Text
deriving (ReadPrec [PersistUpdate]
ReadPrec PersistUpdate
Int -> ReadS PersistUpdate
ReadS [PersistUpdate]
(Int -> ReadS PersistUpdate)
-> ReadS [PersistUpdate]
-> ReadPrec PersistUpdate
-> ReadPrec [PersistUpdate]
-> Read PersistUpdate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PersistUpdate
readsPrec :: Int -> ReadS PersistUpdate
$creadList :: ReadS [PersistUpdate]
readList :: ReadS [PersistUpdate]
$creadPrec :: ReadPrec PersistUpdate
readPrec :: ReadPrec PersistUpdate
$creadListPrec :: ReadPrec [PersistUpdate]
readListPrec :: ReadPrec [PersistUpdate]
Read, Int -> PersistUpdate -> ShowS
[PersistUpdate] -> ShowS
PersistUpdate -> [Char]
(Int -> PersistUpdate -> ShowS)
-> (PersistUpdate -> [Char])
-> ([PersistUpdate] -> ShowS)
-> Show PersistUpdate
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PersistUpdate -> ShowS
showsPrec :: Int -> PersistUpdate -> ShowS
$cshow :: PersistUpdate -> [Char]
show :: PersistUpdate -> [Char]
$cshowList :: [PersistUpdate] -> ShowS
showList :: [PersistUpdate] -> ShowS
Show, (forall (m :: * -> *). Quote m => PersistUpdate -> m Exp)
-> (forall (m :: * -> *).
Quote m =>
PersistUpdate -> Code m PersistUpdate)
-> Lift PersistUpdate
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => PersistUpdate -> m Exp
forall (m :: * -> *).
Quote m =>
PersistUpdate -> Code m PersistUpdate
$clift :: forall (m :: * -> *). Quote m => PersistUpdate -> m Exp
lift :: forall (m :: * -> *). Quote m => PersistUpdate -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
PersistUpdate -> Code m PersistUpdate
liftTyped :: forall (m :: * -> *).
Quote m =>
PersistUpdate -> Code m PersistUpdate
Lift)
data FieldDef = FieldDef
{ FieldDef -> FieldNameHS
fieldHaskell :: !FieldNameHS
, FieldDef -> FieldNameDB
fieldDB :: !FieldNameDB
, FieldDef -> FieldType
fieldType :: !FieldType
, FieldDef -> SqlType
fieldSqlType :: !SqlType
, FieldDef -> [FieldAttr]
fieldAttrs :: ![FieldAttr]
, FieldDef -> Bool
fieldStrict :: !Bool
, FieldDef -> ReferenceDef
fieldReference :: !ReferenceDef
, FieldDef -> FieldCascade
fieldCascade :: !FieldCascade
, :: !(Maybe Text)
, FieldDef -> Maybe Text
fieldGenerated :: !(Maybe Text)
, FieldDef -> Bool
fieldIsImplicitIdColumn :: !Bool
}
deriving (Int -> FieldDef -> ShowS
[FieldDef] -> ShowS
FieldDef -> [Char]
(Int -> FieldDef -> ShowS)
-> (FieldDef -> [Char]) -> ([FieldDef] -> ShowS) -> Show FieldDef
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FieldDef -> ShowS
showsPrec :: Int -> FieldDef -> ShowS
$cshow :: FieldDef -> [Char]
show :: FieldDef -> [Char]
$cshowList :: [FieldDef] -> ShowS
showList :: [FieldDef] -> ShowS
Show, FieldDef -> FieldDef -> Bool
(FieldDef -> FieldDef -> Bool)
-> (FieldDef -> FieldDef -> Bool) -> Eq FieldDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FieldDef -> FieldDef -> Bool
== :: FieldDef -> FieldDef -> Bool
$c/= :: FieldDef -> FieldDef -> Bool
/= :: FieldDef -> FieldDef -> Bool
Eq, ReadPrec [FieldDef]
ReadPrec FieldDef
Int -> ReadS FieldDef
ReadS [FieldDef]
(Int -> ReadS FieldDef)
-> ReadS [FieldDef]
-> ReadPrec FieldDef
-> ReadPrec [FieldDef]
-> Read FieldDef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FieldDef
readsPrec :: Int -> ReadS FieldDef
$creadList :: ReadS [FieldDef]
readList :: ReadS [FieldDef]
$creadPrec :: ReadPrec FieldDef
readPrec :: ReadPrec FieldDef
$creadListPrec :: ReadPrec [FieldDef]
readListPrec :: ReadPrec [FieldDef]
Read, Eq FieldDef
Eq FieldDef =>
(FieldDef -> FieldDef -> Ordering)
-> (FieldDef -> FieldDef -> Bool)
-> (FieldDef -> FieldDef -> Bool)
-> (FieldDef -> FieldDef -> Bool)
-> (FieldDef -> FieldDef -> Bool)
-> (FieldDef -> FieldDef -> FieldDef)
-> (FieldDef -> FieldDef -> FieldDef)
-> Ord FieldDef
FieldDef -> FieldDef -> Bool
FieldDef -> FieldDef -> Ordering
FieldDef -> FieldDef -> FieldDef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FieldDef -> FieldDef -> Ordering
compare :: FieldDef -> FieldDef -> Ordering
$c< :: FieldDef -> FieldDef -> Bool
< :: FieldDef -> FieldDef -> Bool
$c<= :: FieldDef -> FieldDef -> Bool
<= :: FieldDef -> FieldDef -> Bool
$c> :: FieldDef -> FieldDef -> Bool
> :: FieldDef -> FieldDef -> Bool
$c>= :: FieldDef -> FieldDef -> Bool
>= :: FieldDef -> FieldDef -> Bool
$cmax :: FieldDef -> FieldDef -> FieldDef
max :: FieldDef -> FieldDef -> FieldDef
$cmin :: FieldDef -> FieldDef -> FieldDef
min :: FieldDef -> FieldDef -> FieldDef
Ord, (forall (m :: * -> *). Quote m => FieldDef -> m Exp)
-> (forall (m :: * -> *). Quote m => FieldDef -> Code m FieldDef)
-> Lift FieldDef
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FieldDef -> m Exp
forall (m :: * -> *). Quote m => FieldDef -> Code m FieldDef
$clift :: forall (m :: * -> *). Quote m => FieldDef -> m Exp
lift :: forall (m :: * -> *). Quote m => FieldDef -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => FieldDef -> Code m FieldDef
liftTyped :: forall (m :: * -> *). Quote m => FieldDef -> Code m FieldDef
Lift)