{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Database.Groundhog.TH.Settings
( PersistDefinitions (..),
THEntityDef (..),
THEmbeddedDef (..),
THPrimitiveDef (..),
THConstructorDef (..),
THFieldDef (..),
THUniqueDef (..),
THUniqueKeyDef (..),
THAutoKeyDef (..),
PSEntityDef (..),
PSEmbeddedDef (..),
PSPrimitiveDef (..),
PSConstructorDef (..),
PSFieldDef (..),
PSUniqueDef (..),
PSUniqueKeyDef (..),
PSAutoKeyDef (..),
)
where
import Control.Applicative
import Control.Monad (forM, mzero, when)
import Data.Aeson
import Data.Aeson.Types (Pair)
import qualified Data.Foldable as Fold
import qualified Data.HashMap.Strict as H
import Data.Maybe (catMaybes)
import Data.Text (Text)
import Database.Groundhog.Core (ReferenceActionType (..), UniqueType (..))
import Database.Groundhog.Generic (PSFieldDef (..))
import Language.Haskell.TH
import Language.Haskell.TH.Syntax (Lift (..))
data PersistDefinitions = PersistDefinitions {PersistDefinitions -> [PSEntityDef]
psEntities :: [PSEntityDef], PersistDefinitions -> [PSEmbeddedDef]
psEmbeddeds :: [PSEmbeddedDef], PersistDefinitions -> [PSPrimitiveDef]
psPrimitives :: [PSPrimitiveDef]}
deriving (Int -> PersistDefinitions -> ShowS
[PersistDefinitions] -> ShowS
PersistDefinitions -> String
(Int -> PersistDefinitions -> ShowS)
-> (PersistDefinitions -> String)
-> ([PersistDefinitions] -> ShowS)
-> Show PersistDefinitions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PersistDefinitions] -> ShowS
$cshowList :: [PersistDefinitions] -> ShowS
show :: PersistDefinitions -> String
$cshow :: PersistDefinitions -> String
showsPrec :: Int -> PersistDefinitions -> ShowS
$cshowsPrec :: Int -> PersistDefinitions -> ShowS
Show, PersistDefinitions -> Q Exp
PersistDefinitions -> Q (TExp PersistDefinitions)
(PersistDefinitions -> Q Exp)
-> (PersistDefinitions -> Q (TExp PersistDefinitions))
-> Lift PersistDefinitions
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PersistDefinitions -> Q (TExp PersistDefinitions)
$cliftTyped :: PersistDefinitions -> Q (TExp PersistDefinitions)
lift :: PersistDefinitions -> Q Exp
$clift :: PersistDefinitions -> Q Exp
Lift)
data THEntityDef = THEntityDef
{ THEntityDef -> Name
thDataName :: Name,
THEntityDef -> String
thDbEntityName :: String,
THEntityDef -> Maybe String
thEntitySchema :: Maybe String,
THEntityDef -> Maybe THAutoKeyDef
thAutoKey :: Maybe THAutoKeyDef,
THEntityDef -> [THUniqueKeyDef]
thUniqueKeys :: [THUniqueKeyDef],
#if MIN_VERSION_template_haskell(2, 17, 0)
thTypeParams :: [TyVarBndr ()],
#else
THEntityDef -> [TyVarBndr]
thTypeParams :: [TyVarBndr],
#endif
THEntityDef -> [THConstructorDef]
thConstructors :: [THConstructorDef]
}
deriving (THEntityDef -> THEntityDef -> Bool
(THEntityDef -> THEntityDef -> Bool)
-> (THEntityDef -> THEntityDef -> Bool) -> Eq THEntityDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THEntityDef -> THEntityDef -> Bool
$c/= :: THEntityDef -> THEntityDef -> Bool
== :: THEntityDef -> THEntityDef -> Bool
$c== :: THEntityDef -> THEntityDef -> Bool
Eq, Int -> THEntityDef -> ShowS
[THEntityDef] -> ShowS
THEntityDef -> String
(Int -> THEntityDef -> ShowS)
-> (THEntityDef -> String)
-> ([THEntityDef] -> ShowS)
-> Show THEntityDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THEntityDef] -> ShowS
$cshowList :: [THEntityDef] -> ShowS
show :: THEntityDef -> String
$cshow :: THEntityDef -> String
showsPrec :: Int -> THEntityDef -> ShowS
$cshowsPrec :: Int -> THEntityDef -> ShowS
Show)
data THAutoKeyDef = THAutoKeyDef
{ THAutoKeyDef -> String
thAutoKeyConstrName :: String,
THAutoKeyDef -> Bool
thAutoKeyIsDef :: Bool
}
deriving (THAutoKeyDef -> THAutoKeyDef -> Bool
(THAutoKeyDef -> THAutoKeyDef -> Bool)
-> (THAutoKeyDef -> THAutoKeyDef -> Bool) -> Eq THAutoKeyDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THAutoKeyDef -> THAutoKeyDef -> Bool
$c/= :: THAutoKeyDef -> THAutoKeyDef -> Bool
== :: THAutoKeyDef -> THAutoKeyDef -> Bool
$c== :: THAutoKeyDef -> THAutoKeyDef -> Bool
Eq, Int -> THAutoKeyDef -> ShowS
[THAutoKeyDef] -> ShowS
THAutoKeyDef -> String
(Int -> THAutoKeyDef -> ShowS)
-> (THAutoKeyDef -> String)
-> ([THAutoKeyDef] -> ShowS)
-> Show THAutoKeyDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THAutoKeyDef] -> ShowS
$cshowList :: [THAutoKeyDef] -> ShowS
show :: THAutoKeyDef -> String
$cshow :: THAutoKeyDef -> String
showsPrec :: Int -> THAutoKeyDef -> ShowS
$cshowsPrec :: Int -> THAutoKeyDef -> ShowS
Show)
data THEmbeddedDef = THEmbeddedDef
{ THEmbeddedDef -> Name
thEmbeddedName :: Name,
THEmbeddedDef -> Name
thEmbeddedConstructorName :: Name,
THEmbeddedDef -> String
thDbEmbeddedName :: String,
#if MIN_VERSION_template_haskell(2, 17, 0)
thEmbeddedTypeParams :: [TyVarBndr ()],
#else
THEmbeddedDef -> [TyVarBndr]
thEmbeddedTypeParams :: [TyVarBndr],
#endif
THEmbeddedDef -> [THFieldDef]
thEmbeddedFields :: [THFieldDef]
}
deriving (THEmbeddedDef -> THEmbeddedDef -> Bool
(THEmbeddedDef -> THEmbeddedDef -> Bool)
-> (THEmbeddedDef -> THEmbeddedDef -> Bool) -> Eq THEmbeddedDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THEmbeddedDef -> THEmbeddedDef -> Bool
$c/= :: THEmbeddedDef -> THEmbeddedDef -> Bool
== :: THEmbeddedDef -> THEmbeddedDef -> Bool
$c== :: THEmbeddedDef -> THEmbeddedDef -> Bool
Eq, Int -> THEmbeddedDef -> ShowS
[THEmbeddedDef] -> ShowS
THEmbeddedDef -> String
(Int -> THEmbeddedDef -> ShowS)
-> (THEmbeddedDef -> String)
-> ([THEmbeddedDef] -> ShowS)
-> Show THEmbeddedDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THEmbeddedDef] -> ShowS
$cshowList :: [THEmbeddedDef] -> ShowS
show :: THEmbeddedDef -> String
$cshow :: THEmbeddedDef -> String
showsPrec :: Int -> THEmbeddedDef -> ShowS
$cshowsPrec :: Int -> THEmbeddedDef -> ShowS
Show)
data THPrimitiveDef = THPrimitiveDef
{ THPrimitiveDef -> Name
thPrimitiveName :: Name,
THPrimitiveDef -> String
thPrimitiveDbName :: String,
THPrimitiveDef -> Name
thPrimitiveConverter :: Name
}
deriving (THPrimitiveDef -> THPrimitiveDef -> Bool
(THPrimitiveDef -> THPrimitiveDef -> Bool)
-> (THPrimitiveDef -> THPrimitiveDef -> Bool) -> Eq THPrimitiveDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THPrimitiveDef -> THPrimitiveDef -> Bool
$c/= :: THPrimitiveDef -> THPrimitiveDef -> Bool
== :: THPrimitiveDef -> THPrimitiveDef -> Bool
$c== :: THPrimitiveDef -> THPrimitiveDef -> Bool
Eq, Int -> THPrimitiveDef -> ShowS
[THPrimitiveDef] -> ShowS
THPrimitiveDef -> String
(Int -> THPrimitiveDef -> ShowS)
-> (THPrimitiveDef -> String)
-> ([THPrimitiveDef] -> ShowS)
-> Show THPrimitiveDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THPrimitiveDef] -> ShowS
$cshowList :: [THPrimitiveDef] -> ShowS
show :: THPrimitiveDef -> String
$cshow :: THPrimitiveDef -> String
showsPrec :: Int -> THPrimitiveDef -> ShowS
$cshowsPrec :: Int -> THPrimitiveDef -> ShowS
Show)
data THConstructorDef = THConstructorDef
{ THConstructorDef -> Name
thConstrName :: Name,
THConstructorDef -> String
thPhantomConstrName :: String,
THConstructorDef -> String
thDbConstrName :: String,
THConstructorDef -> Maybe String
thDbAutoKeyName :: Maybe String,
THConstructorDef -> [THFieldDef]
thConstrFields :: [THFieldDef],
THConstructorDef -> [THUniqueDef]
thConstrUniques :: [THUniqueDef]
}
deriving (THConstructorDef -> THConstructorDef -> Bool
(THConstructorDef -> THConstructorDef -> Bool)
-> (THConstructorDef -> THConstructorDef -> Bool)
-> Eq THConstructorDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THConstructorDef -> THConstructorDef -> Bool
$c/= :: THConstructorDef -> THConstructorDef -> Bool
== :: THConstructorDef -> THConstructorDef -> Bool
$c== :: THConstructorDef -> THConstructorDef -> Bool
Eq, Int -> THConstructorDef -> ShowS
[THConstructorDef] -> ShowS
THConstructorDef -> String
(Int -> THConstructorDef -> ShowS)
-> (THConstructorDef -> String)
-> ([THConstructorDef] -> ShowS)
-> Show THConstructorDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THConstructorDef] -> ShowS
$cshowList :: [THConstructorDef] -> ShowS
show :: THConstructorDef -> String
$cshow :: THConstructorDef -> String
showsPrec :: Int -> THConstructorDef -> ShowS
$cshowsPrec :: Int -> THConstructorDef -> ShowS
Show)
data THFieldDef = THFieldDef
{
THFieldDef -> String
thFieldName :: String,
THFieldDef -> String
thDbFieldName :: String,
THFieldDef -> Maybe String
thDbTypeName :: Maybe String,
THFieldDef -> String
thExprName :: String,
THFieldDef -> Type
thFieldType :: Type,
THFieldDef -> Maybe [PSFieldDef String]
thEmbeddedDef :: Maybe [PSFieldDef String],
THFieldDef -> Maybe String
thDefaultValue :: Maybe String,
THFieldDef
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
thReferenceParent :: Maybe (Maybe ((Maybe String, String), [String]), Maybe ReferenceActionType, Maybe ReferenceActionType),
THFieldDef -> Maybe Name
thFieldConverter :: Maybe Name
}
deriving (THFieldDef -> THFieldDef -> Bool
(THFieldDef -> THFieldDef -> Bool)
-> (THFieldDef -> THFieldDef -> Bool) -> Eq THFieldDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THFieldDef -> THFieldDef -> Bool
$c/= :: THFieldDef -> THFieldDef -> Bool
== :: THFieldDef -> THFieldDef -> Bool
$c== :: THFieldDef -> THFieldDef -> Bool
Eq, Int -> THFieldDef -> ShowS
[THFieldDef] -> ShowS
THFieldDef -> String
(Int -> THFieldDef -> ShowS)
-> (THFieldDef -> String)
-> ([THFieldDef] -> ShowS)
-> Show THFieldDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THFieldDef] -> ShowS
$cshowList :: [THFieldDef] -> ShowS
show :: THFieldDef -> String
$cshow :: THFieldDef -> String
showsPrec :: Int -> THFieldDef -> ShowS
$cshowsPrec :: Int -> THFieldDef -> ShowS
Show)
data THUniqueDef = THUniqueDef
{ THUniqueDef -> String
thUniqueName :: String,
THUniqueDef -> UniqueType
thUniqueType :: UniqueType,
THUniqueDef -> [Either String String]
thUniqueFields :: [Either String String]
}
deriving (THUniqueDef -> THUniqueDef -> Bool
(THUniqueDef -> THUniqueDef -> Bool)
-> (THUniqueDef -> THUniqueDef -> Bool) -> Eq THUniqueDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THUniqueDef -> THUniqueDef -> Bool
$c/= :: THUniqueDef -> THUniqueDef -> Bool
== :: THUniqueDef -> THUniqueDef -> Bool
$c== :: THUniqueDef -> THUniqueDef -> Bool
Eq, Int -> THUniqueDef -> ShowS
[THUniqueDef] -> ShowS
THUniqueDef -> String
(Int -> THUniqueDef -> ShowS)
-> (THUniqueDef -> String)
-> ([THUniqueDef] -> ShowS)
-> Show THUniqueDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THUniqueDef] -> ShowS
$cshowList :: [THUniqueDef] -> ShowS
show :: THUniqueDef -> String
$cshow :: THUniqueDef -> String
showsPrec :: Int -> THUniqueDef -> ShowS
$cshowsPrec :: Int -> THUniqueDef -> ShowS
Show)
data THUniqueKeyDef = THUniqueKeyDef
{ THUniqueKeyDef -> String
thUniqueKeyName :: String,
THUniqueKeyDef -> String
thUniqueKeyPhantomName :: String,
THUniqueKeyDef -> String
thUniqueKeyConstrName :: String,
THUniqueKeyDef -> String
thUniqueKeyDbName :: String,
THUniqueKeyDef -> [THFieldDef]
thUniqueKeyFields :: [THFieldDef],
THUniqueKeyDef -> Bool
thUniqueKeyMakeEmbedded :: Bool,
THUniqueKeyDef -> Bool
thUniqueKeyIsDef :: Bool
}
deriving (THUniqueKeyDef -> THUniqueKeyDef -> Bool
(THUniqueKeyDef -> THUniqueKeyDef -> Bool)
-> (THUniqueKeyDef -> THUniqueKeyDef -> Bool) -> Eq THUniqueKeyDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: THUniqueKeyDef -> THUniqueKeyDef -> Bool
$c/= :: THUniqueKeyDef -> THUniqueKeyDef -> Bool
== :: THUniqueKeyDef -> THUniqueKeyDef -> Bool
$c== :: THUniqueKeyDef -> THUniqueKeyDef -> Bool
Eq, Int -> THUniqueKeyDef -> ShowS
[THUniqueKeyDef] -> ShowS
THUniqueKeyDef -> String
(Int -> THUniqueKeyDef -> ShowS)
-> (THUniqueKeyDef -> String)
-> ([THUniqueKeyDef] -> ShowS)
-> Show THUniqueKeyDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [THUniqueKeyDef] -> ShowS
$cshowList :: [THUniqueKeyDef] -> ShowS
show :: THUniqueKeyDef -> String
$cshow :: THUniqueKeyDef -> String
showsPrec :: Int -> THUniqueKeyDef -> ShowS
$cshowsPrec :: Int -> THUniqueKeyDef -> ShowS
Show)
data PSEntityDef = PSEntityDef
{ PSEntityDef -> String
psDataName :: String,
PSEntityDef -> Maybe String
psDbEntityName :: Maybe String,
PSEntityDef -> Maybe String
psEntitySchema :: Maybe String,
PSEntityDef -> Maybe (Maybe PSAutoKeyDef)
psAutoKey :: Maybe (Maybe PSAutoKeyDef),
PSEntityDef -> Maybe [PSUniqueKeyDef]
psUniqueKeys :: Maybe [PSUniqueKeyDef],
PSEntityDef -> Maybe [PSConstructorDef]
psConstructors :: Maybe [PSConstructorDef]
}
deriving (PSEntityDef -> PSEntityDef -> Bool
(PSEntityDef -> PSEntityDef -> Bool)
-> (PSEntityDef -> PSEntityDef -> Bool) -> Eq PSEntityDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSEntityDef -> PSEntityDef -> Bool
$c/= :: PSEntityDef -> PSEntityDef -> Bool
== :: PSEntityDef -> PSEntityDef -> Bool
$c== :: PSEntityDef -> PSEntityDef -> Bool
Eq, Int -> PSEntityDef -> ShowS
[PSEntityDef] -> ShowS
PSEntityDef -> String
(Int -> PSEntityDef -> ShowS)
-> (PSEntityDef -> String)
-> ([PSEntityDef] -> ShowS)
-> Show PSEntityDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSEntityDef] -> ShowS
$cshowList :: [PSEntityDef] -> ShowS
show :: PSEntityDef -> String
$cshow :: PSEntityDef -> String
showsPrec :: Int -> PSEntityDef -> ShowS
$cshowsPrec :: Int -> PSEntityDef -> ShowS
Show, PSEntityDef -> Q Exp
PSEntityDef -> Q (TExp PSEntityDef)
(PSEntityDef -> Q Exp)
-> (PSEntityDef -> Q (TExp PSEntityDef)) -> Lift PSEntityDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSEntityDef -> Q (TExp PSEntityDef)
$cliftTyped :: PSEntityDef -> Q (TExp PSEntityDef)
lift :: PSEntityDef -> Q Exp
$clift :: PSEntityDef -> Q Exp
Lift)
data PSEmbeddedDef = PSEmbeddedDef
{ PSEmbeddedDef -> String
psEmbeddedName :: String,
PSEmbeddedDef -> Maybe String
psDbEmbeddedName :: Maybe String,
PSEmbeddedDef -> Maybe [PSFieldDef String]
psEmbeddedFields :: Maybe [PSFieldDef String]
}
deriving (PSEmbeddedDef -> PSEmbeddedDef -> Bool
(PSEmbeddedDef -> PSEmbeddedDef -> Bool)
-> (PSEmbeddedDef -> PSEmbeddedDef -> Bool) -> Eq PSEmbeddedDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSEmbeddedDef -> PSEmbeddedDef -> Bool
$c/= :: PSEmbeddedDef -> PSEmbeddedDef -> Bool
== :: PSEmbeddedDef -> PSEmbeddedDef -> Bool
$c== :: PSEmbeddedDef -> PSEmbeddedDef -> Bool
Eq, Int -> PSEmbeddedDef -> ShowS
[PSEmbeddedDef] -> ShowS
PSEmbeddedDef -> String
(Int -> PSEmbeddedDef -> ShowS)
-> (PSEmbeddedDef -> String)
-> ([PSEmbeddedDef] -> ShowS)
-> Show PSEmbeddedDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSEmbeddedDef] -> ShowS
$cshowList :: [PSEmbeddedDef] -> ShowS
show :: PSEmbeddedDef -> String
$cshow :: PSEmbeddedDef -> String
showsPrec :: Int -> PSEmbeddedDef -> ShowS
$cshowsPrec :: Int -> PSEmbeddedDef -> ShowS
Show, PSEmbeddedDef -> Q Exp
PSEmbeddedDef -> Q (TExp PSEmbeddedDef)
(PSEmbeddedDef -> Q Exp)
-> (PSEmbeddedDef -> Q (TExp PSEmbeddedDef)) -> Lift PSEmbeddedDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSEmbeddedDef -> Q (TExp PSEmbeddedDef)
$cliftTyped :: PSEmbeddedDef -> Q (TExp PSEmbeddedDef)
lift :: PSEmbeddedDef -> Q Exp
$clift :: PSEmbeddedDef -> Q Exp
Lift)
data PSPrimitiveDef = PSPrimitiveDef
{ PSPrimitiveDef -> String
psPrimitiveName :: String,
PSPrimitiveDef -> Maybe String
psPrimitiveDbName :: Maybe String,
PSPrimitiveDef -> String
psPrimitiveConverter :: String
}
deriving (PSPrimitiveDef -> PSPrimitiveDef -> Bool
(PSPrimitiveDef -> PSPrimitiveDef -> Bool)
-> (PSPrimitiveDef -> PSPrimitiveDef -> Bool) -> Eq PSPrimitiveDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSPrimitiveDef -> PSPrimitiveDef -> Bool
$c/= :: PSPrimitiveDef -> PSPrimitiveDef -> Bool
== :: PSPrimitiveDef -> PSPrimitiveDef -> Bool
$c== :: PSPrimitiveDef -> PSPrimitiveDef -> Bool
Eq, Int -> PSPrimitiveDef -> ShowS
[PSPrimitiveDef] -> ShowS
PSPrimitiveDef -> String
(Int -> PSPrimitiveDef -> ShowS)
-> (PSPrimitiveDef -> String)
-> ([PSPrimitiveDef] -> ShowS)
-> Show PSPrimitiveDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSPrimitiveDef] -> ShowS
$cshowList :: [PSPrimitiveDef] -> ShowS
show :: PSPrimitiveDef -> String
$cshow :: PSPrimitiveDef -> String
showsPrec :: Int -> PSPrimitiveDef -> ShowS
$cshowsPrec :: Int -> PSPrimitiveDef -> ShowS
Show, PSPrimitiveDef -> Q Exp
PSPrimitiveDef -> Q (TExp PSPrimitiveDef)
(PSPrimitiveDef -> Q Exp)
-> (PSPrimitiveDef -> Q (TExp PSPrimitiveDef))
-> Lift PSPrimitiveDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSPrimitiveDef -> Q (TExp PSPrimitiveDef)
$cliftTyped :: PSPrimitiveDef -> Q (TExp PSPrimitiveDef)
lift :: PSPrimitiveDef -> Q Exp
$clift :: PSPrimitiveDef -> Q Exp
Lift)
data PSConstructorDef = PSConstructorDef
{ PSConstructorDef -> String
psConstrName :: String,
PSConstructorDef -> Maybe String
psPhantomConstrName :: Maybe String,
PSConstructorDef -> Maybe String
psDbConstrName :: Maybe String,
PSConstructorDef -> Maybe String
psDbAutoKeyName :: Maybe String,
PSConstructorDef -> Maybe [PSFieldDef String]
psConstrFields :: Maybe [PSFieldDef String],
PSConstructorDef -> Maybe [PSUniqueDef]
psConstrUniques :: Maybe [PSUniqueDef]
}
deriving (PSConstructorDef -> PSConstructorDef -> Bool
(PSConstructorDef -> PSConstructorDef -> Bool)
-> (PSConstructorDef -> PSConstructorDef -> Bool)
-> Eq PSConstructorDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSConstructorDef -> PSConstructorDef -> Bool
$c/= :: PSConstructorDef -> PSConstructorDef -> Bool
== :: PSConstructorDef -> PSConstructorDef -> Bool
$c== :: PSConstructorDef -> PSConstructorDef -> Bool
Eq, Int -> PSConstructorDef -> ShowS
[PSConstructorDef] -> ShowS
PSConstructorDef -> String
(Int -> PSConstructorDef -> ShowS)
-> (PSConstructorDef -> String)
-> ([PSConstructorDef] -> ShowS)
-> Show PSConstructorDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSConstructorDef] -> ShowS
$cshowList :: [PSConstructorDef] -> ShowS
show :: PSConstructorDef -> String
$cshow :: PSConstructorDef -> String
showsPrec :: Int -> PSConstructorDef -> ShowS
$cshowsPrec :: Int -> PSConstructorDef -> ShowS
Show, PSConstructorDef -> Q Exp
PSConstructorDef -> Q (TExp PSConstructorDef)
(PSConstructorDef -> Q Exp)
-> (PSConstructorDef -> Q (TExp PSConstructorDef))
-> Lift PSConstructorDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSConstructorDef -> Q (TExp PSConstructorDef)
$cliftTyped :: PSConstructorDef -> Q (TExp PSConstructorDef)
lift :: PSConstructorDef -> Q Exp
$clift :: PSConstructorDef -> Q Exp
Lift)
data PSUniqueDef = PSUniqueDef
{ PSUniqueDef -> String
psUniqueName :: String,
PSUniqueDef -> Maybe UniqueType
psUniqueType :: Maybe UniqueType,
PSUniqueDef -> [Either String String]
psUniqueFields :: [Either String String]
}
deriving (PSUniqueDef -> PSUniqueDef -> Bool
(PSUniqueDef -> PSUniqueDef -> Bool)
-> (PSUniqueDef -> PSUniqueDef -> Bool) -> Eq PSUniqueDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSUniqueDef -> PSUniqueDef -> Bool
$c/= :: PSUniqueDef -> PSUniqueDef -> Bool
== :: PSUniqueDef -> PSUniqueDef -> Bool
$c== :: PSUniqueDef -> PSUniqueDef -> Bool
Eq, Int -> PSUniqueDef -> ShowS
[PSUniqueDef] -> ShowS
PSUniqueDef -> String
(Int -> PSUniqueDef -> ShowS)
-> (PSUniqueDef -> String)
-> ([PSUniqueDef] -> ShowS)
-> Show PSUniqueDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSUniqueDef] -> ShowS
$cshowList :: [PSUniqueDef] -> ShowS
show :: PSUniqueDef -> String
$cshow :: PSUniqueDef -> String
showsPrec :: Int -> PSUniqueDef -> ShowS
$cshowsPrec :: Int -> PSUniqueDef -> ShowS
Show, PSUniqueDef -> Q Exp
PSUniqueDef -> Q (TExp PSUniqueDef)
(PSUniqueDef -> Q Exp)
-> (PSUniqueDef -> Q (TExp PSUniqueDef)) -> Lift PSUniqueDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSUniqueDef -> Q (TExp PSUniqueDef)
$cliftTyped :: PSUniqueDef -> Q (TExp PSUniqueDef)
lift :: PSUniqueDef -> Q Exp
$clift :: PSUniqueDef -> Q Exp
Lift)
data PSUniqueKeyDef = PSUniqueKeyDef
{ PSUniqueKeyDef -> String
psUniqueKeyName :: String,
PSUniqueKeyDef -> Maybe String
psUniqueKeyPhantomName :: Maybe String,
PSUniqueKeyDef -> Maybe String
psUniqueKeyConstrName :: Maybe String,
PSUniqueKeyDef -> Maybe String
psUniqueKeyDbName :: Maybe String,
PSUniqueKeyDef -> Maybe [PSFieldDef String]
psUniqueKeyFields :: Maybe [PSFieldDef String],
PSUniqueKeyDef -> Maybe Bool
psUniqueKeyMakeEmbedded :: Maybe Bool,
PSUniqueKeyDef -> Maybe Bool
psUniqueKeyIsDef :: Maybe Bool
}
deriving (PSUniqueKeyDef -> PSUniqueKeyDef -> Bool
(PSUniqueKeyDef -> PSUniqueKeyDef -> Bool)
-> (PSUniqueKeyDef -> PSUniqueKeyDef -> Bool) -> Eq PSUniqueKeyDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSUniqueKeyDef -> PSUniqueKeyDef -> Bool
$c/= :: PSUniqueKeyDef -> PSUniqueKeyDef -> Bool
== :: PSUniqueKeyDef -> PSUniqueKeyDef -> Bool
$c== :: PSUniqueKeyDef -> PSUniqueKeyDef -> Bool
Eq, Int -> PSUniqueKeyDef -> ShowS
[PSUniqueKeyDef] -> ShowS
PSUniqueKeyDef -> String
(Int -> PSUniqueKeyDef -> ShowS)
-> (PSUniqueKeyDef -> String)
-> ([PSUniqueKeyDef] -> ShowS)
-> Show PSUniqueKeyDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSUniqueKeyDef] -> ShowS
$cshowList :: [PSUniqueKeyDef] -> ShowS
show :: PSUniqueKeyDef -> String
$cshow :: PSUniqueKeyDef -> String
showsPrec :: Int -> PSUniqueKeyDef -> ShowS
$cshowsPrec :: Int -> PSUniqueKeyDef -> ShowS
Show, PSUniqueKeyDef -> Q Exp
PSUniqueKeyDef -> Q (TExp PSUniqueKeyDef)
(PSUniqueKeyDef -> Q Exp)
-> (PSUniqueKeyDef -> Q (TExp PSUniqueKeyDef))
-> Lift PSUniqueKeyDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSUniqueKeyDef -> Q (TExp PSUniqueKeyDef)
$cliftTyped :: PSUniqueKeyDef -> Q (TExp PSUniqueKeyDef)
lift :: PSUniqueKeyDef -> Q Exp
$clift :: PSUniqueKeyDef -> Q Exp
Lift)
data PSAutoKeyDef = PSAutoKeyDef
{ PSAutoKeyDef -> Maybe String
psAutoKeyConstrName :: Maybe String,
PSAutoKeyDef -> Maybe Bool
psAutoKeyIsDef :: Maybe Bool
}
deriving (PSAutoKeyDef -> PSAutoKeyDef -> Bool
(PSAutoKeyDef -> PSAutoKeyDef -> Bool)
-> (PSAutoKeyDef -> PSAutoKeyDef -> Bool) -> Eq PSAutoKeyDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PSAutoKeyDef -> PSAutoKeyDef -> Bool
$c/= :: PSAutoKeyDef -> PSAutoKeyDef -> Bool
== :: PSAutoKeyDef -> PSAutoKeyDef -> Bool
$c== :: PSAutoKeyDef -> PSAutoKeyDef -> Bool
Eq, Int -> PSAutoKeyDef -> ShowS
[PSAutoKeyDef] -> ShowS
PSAutoKeyDef -> String
(Int -> PSAutoKeyDef -> ShowS)
-> (PSAutoKeyDef -> String)
-> ([PSAutoKeyDef] -> ShowS)
-> Show PSAutoKeyDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PSAutoKeyDef] -> ShowS
$cshowList :: [PSAutoKeyDef] -> ShowS
show :: PSAutoKeyDef -> String
$cshow :: PSAutoKeyDef -> String
showsPrec :: Int -> PSAutoKeyDef -> ShowS
$cshowsPrec :: Int -> PSAutoKeyDef -> ShowS
Show, PSAutoKeyDef -> Q Exp
PSAutoKeyDef -> Q (TExp PSAutoKeyDef)
(PSAutoKeyDef -> Q Exp)
-> (PSAutoKeyDef -> Q (TExp PSAutoKeyDef)) -> Lift PSAutoKeyDef
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: PSAutoKeyDef -> Q (TExp PSAutoKeyDef)
$cliftTyped :: PSAutoKeyDef -> Q (TExp PSAutoKeyDef)
lift :: PSAutoKeyDef -> Q Exp
$clift :: PSAutoKeyDef -> Q Exp
Lift)
deriving instance Lift a => Lift (PSFieldDef a)
deriving instance Lift UniqueType
deriving instance Lift ReferenceActionType
instance FromJSON PersistDefinitions where
parseJSON :: Value -> Parser PersistDefinitions
parseJSON Value
value =
case Value
value of
Object Object
v -> do
Maybe Value
defs <- Object
v Object -> Text -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"definitions"
case Maybe Value
defs of
Just (Array Array
arr) -> (Value -> PersistDefinitions -> Parser PersistDefinitions)
-> PersistDefinitions -> Array -> Parser PersistDefinitions
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
Fold.foldrM Value -> PersistDefinitions -> Parser PersistDefinitions
go PersistDefinitions
initial Array
arr
Maybe Value
Nothing -> Value -> PersistDefinitions -> Parser PersistDefinitions
go Value
value PersistDefinitions
initial
Just Value
_ -> Parser PersistDefinitions
forall (m :: * -> *) a. MonadPlus m => m a
mzero
Array Array
arr -> (Value -> PersistDefinitions -> Parser PersistDefinitions)
-> PersistDefinitions -> Array -> Parser PersistDefinitions
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
Fold.foldrM Value -> PersistDefinitions -> Parser PersistDefinitions
go PersistDefinitions
initial Array
arr
Value
_ -> Parser PersistDefinitions
forall (m :: * -> *) a. MonadPlus m => m a
mzero
where
initial :: PersistDefinitions
initial = [PSEntityDef]
-> [PSEmbeddedDef] -> [PSPrimitiveDef] -> PersistDefinitions
PersistDefinitions [] [] []
go :: Value -> PersistDefinitions -> Parser PersistDefinitions
go Value
obj p :: PersistDefinitions
p@PersistDefinitions {[PSPrimitiveDef]
[PSEmbeddedDef]
[PSEntityDef]
psPrimitives :: [PSPrimitiveDef]
psEmbeddeds :: [PSEmbeddedDef]
psEntities :: [PSEntityDef]
psPrimitives :: PersistDefinitions -> [PSPrimitiveDef]
psEmbeddeds :: PersistDefinitions -> [PSEmbeddedDef]
psEntities :: PersistDefinitions -> [PSEntityDef]
..} = ((Object -> Parser PersistDefinitions)
-> Value -> Parser PersistDefinitions)
-> Value
-> (Object -> Parser PersistDefinitions)
-> Parser PersistDefinitions
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String
-> (Object -> Parser PersistDefinitions)
-> Value
-> Parser PersistDefinitions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"definition") Value
obj ((Object -> Parser PersistDefinitions)
-> Parser PersistDefinitions)
-> (Object -> Parser PersistDefinitions)
-> Parser PersistDefinitions
forall a b. (a -> b) -> a -> b
$ \Object
v -> case () of
()
_ | Text -> Object -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
H.member Text
"entity" Object
v -> (\PSEntityDef
x -> PersistDefinitions
p {psEntities :: [PSEntityDef]
psEntities = PSEntityDef
x PSEntityDef -> [PSEntityDef] -> [PSEntityDef]
forall a. a -> [a] -> [a]
: [PSEntityDef]
psEntities}) (PSEntityDef -> PersistDefinitions)
-> Parser PSEntityDef -> Parser PersistDefinitions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser PSEntityDef
forall a. FromJSON a => Value -> Parser a
parseJSON Value
obj
()
_ | Text -> Object -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
H.member Text
"embedded" Object
v -> (\PSEmbeddedDef
x -> PersistDefinitions
p {psEmbeddeds :: [PSEmbeddedDef]
psEmbeddeds = PSEmbeddedDef
x PSEmbeddedDef -> [PSEmbeddedDef] -> [PSEmbeddedDef]
forall a. a -> [a] -> [a]
: [PSEmbeddedDef]
psEmbeddeds}) (PSEmbeddedDef -> PersistDefinitions)
-> Parser PSEmbeddedDef -> Parser PersistDefinitions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser PSEmbeddedDef
forall a. FromJSON a => Value -> Parser a
parseJSON Value
obj
()
_ | Text -> Object -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
H.member Text
"primitive" Object
v -> (\PSPrimitiveDef
x -> PersistDefinitions
p {psPrimitives :: [PSPrimitiveDef]
psPrimitives = PSPrimitiveDef
x PSPrimitiveDef -> [PSPrimitiveDef] -> [PSPrimitiveDef]
forall a. a -> [a] -> [a]
: [PSPrimitiveDef]
psPrimitives}) (PSPrimitiveDef -> PersistDefinitions)
-> Parser PSPrimitiveDef -> Parser PersistDefinitions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser PSPrimitiveDef
forall a. FromJSON a => Value -> Parser a
parseJSON Value
obj
()
_ -> String -> Parser PersistDefinitions
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser PersistDefinitions)
-> String -> Parser PersistDefinitions
forall a b. (a -> b) -> a -> b
$ String
"Invalid definition: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Value -> String
forall a. Show a => a -> String
show Value
obj
instance FromJSON PSEntityDef where
parseJSON :: Value -> Parser PSEntityDef
parseJSON = String
-> (Object -> Parser PSEntityDef) -> Value -> Parser PSEntityDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"entity" ((Object -> Parser PSEntityDef) -> Value -> Parser PSEntityDef)
-> (Object -> Parser PSEntityDef) -> Value -> Parser PSEntityDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
String
-> Maybe String
-> Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef
PSEntityDef (String
-> Maybe String
-> Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
-> Parser String
-> Parser
(Maybe String
-> Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"entity" Parser
(Maybe String
-> Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser
(Maybe String
-> Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
-> Parser (Maybe String)
-> Parser
(Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"schema" Parser
(Maybe (Maybe PSAutoKeyDef)
-> Maybe [PSUniqueKeyDef]
-> Maybe [PSConstructorDef]
-> PSEntityDef)
-> Parser (Maybe (Maybe PSAutoKeyDef))
-> Parser
(Maybe [PSUniqueKeyDef] -> Maybe [PSConstructorDef] -> PSEntityDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Maybe PSAutoKeyDef) -> Parser (Maybe (Maybe PSAutoKeyDef))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Object
v Object -> Text -> Parser (Maybe PSAutoKeyDef)
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"autoKey") Parser
(Maybe [PSUniqueKeyDef] -> Maybe [PSConstructorDef] -> PSEntityDef)
-> Parser (Maybe [PSUniqueKeyDef])
-> Parser (Maybe [PSConstructorDef] -> PSEntityDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSUniqueKeyDef])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"keys" Parser (Maybe [PSConstructorDef] -> PSEntityDef)
-> Parser (Maybe [PSConstructorDef]) -> Parser PSEntityDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSConstructorDef])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"constructors"
instance FromJSON PSEmbeddedDef where
parseJSON :: Value -> Parser PSEmbeddedDef
parseJSON = String
-> (Object -> Parser PSEmbeddedDef)
-> Value
-> Parser PSEmbeddedDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"embedded" ((Object -> Parser PSEmbeddedDef) -> Value -> Parser PSEmbeddedDef)
-> (Object -> Parser PSEmbeddedDef)
-> Value
-> Parser PSEmbeddedDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
String
-> Maybe String -> Maybe [PSFieldDef String] -> PSEmbeddedDef
PSEmbeddedDef (String
-> Maybe String -> Maybe [PSFieldDef String] -> PSEmbeddedDef)
-> Parser String
-> Parser
(Maybe String -> Maybe [PSFieldDef String] -> PSEmbeddedDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"embedded" Parser (Maybe String -> Maybe [PSFieldDef String] -> PSEmbeddedDef)
-> Parser (Maybe String)
-> Parser (Maybe [PSFieldDef String] -> PSEmbeddedDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser (Maybe [PSFieldDef String] -> PSEmbeddedDef)
-> Parser (Maybe [PSFieldDef String]) -> Parser PSEmbeddedDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSFieldDef String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"fields"
instance FromJSON PSPrimitiveDef where
parseJSON :: Value -> Parser PSPrimitiveDef
parseJSON = String
-> (Object -> Parser PSPrimitiveDef)
-> Value
-> Parser PSPrimitiveDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"primitive" ((Object -> Parser PSPrimitiveDef)
-> Value -> Parser PSPrimitiveDef)
-> (Object -> Parser PSPrimitiveDef)
-> Value
-> Parser PSPrimitiveDef
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Text -> Object -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
H.member Text
"representation" Object
v) (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ()) -> String -> Parser ()
forall a b. (a -> b) -> a -> b
$ String
"parseJSON: field 'representation' is deprecated. Use 'converter' instead: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Object -> String
forall a. Show a => a -> String
show Object
v
String -> Maybe String -> String -> PSPrimitiveDef
PSPrimitiveDef (String -> Maybe String -> String -> PSPrimitiveDef)
-> Parser String
-> Parser (Maybe String -> String -> PSPrimitiveDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"primitive" Parser (Maybe String -> String -> PSPrimitiveDef)
-> Parser (Maybe String) -> Parser (String -> PSPrimitiveDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser (String -> PSPrimitiveDef)
-> Parser String -> Parser PSPrimitiveDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"converter"
instance FromJSON PSConstructorDef where
parseJSON :: Value -> Parser PSConstructorDef
parseJSON = String
-> (Object -> Parser PSConstructorDef)
-> Value
-> Parser PSConstructorDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"constructor" ((Object -> Parser PSConstructorDef)
-> Value -> Parser PSConstructorDef)
-> (Object -> Parser PSConstructorDef)
-> Value
-> Parser PSConstructorDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef
PSConstructorDef (String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
-> Parser String
-> Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"name" Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"phantomName" Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef]
-> PSConstructorDef)
-> Parser (Maybe String)
-> Parser
(Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef] -> PSConstructorDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"keyDbName" Parser
(Maybe [PSFieldDef String]
-> Maybe [PSUniqueDef] -> PSConstructorDef)
-> Parser (Maybe [PSFieldDef String])
-> Parser (Maybe [PSUniqueDef] -> PSConstructorDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSFieldDef String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"fields" Parser (Maybe [PSUniqueDef] -> PSConstructorDef)
-> Parser (Maybe [PSUniqueDef]) -> Parser PSConstructorDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSUniqueDef])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"uniques"
instance FromJSON PSUniqueDef where
parseJSON :: Value -> Parser PSUniqueDef
parseJSON = String
-> (Object -> Parser PSUniqueDef) -> Value -> Parser PSUniqueDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"unique" ((Object -> Parser PSUniqueDef) -> Value -> Parser PSUniqueDef)
-> (Object -> Parser PSUniqueDef) -> Value -> Parser PSUniqueDef
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
[Value]
fields <- Object
v Object -> Text -> Parser [Value]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"fields"
[Either String String]
fields' <- [Value]
-> (Value -> Parser (Either String String))
-> Parser [Either String String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Value]
fields ((Value -> Parser (Either String String))
-> Parser [Either String String])
-> (Value -> Parser (Either String String))
-> Parser [Either String String]
forall a b. (a -> b) -> a -> b
$ \case
Object Object
expr -> String -> Either String String
forall a b. b -> Either a b
Right (String -> Either String String)
-> Parser String -> Parser (Either String String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
expr Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"expr"
Value
field -> String -> Either String String
forall a b. a -> Either a b
Left (String -> Either String String)
-> Parser String -> Parser (Either String String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser String
forall a. FromJSON a => Value -> Parser a
parseJSON Value
field
String -> Maybe UniqueType -> [Either String String] -> PSUniqueDef
PSUniqueDef (String
-> Maybe UniqueType -> [Either String String] -> PSUniqueDef)
-> Parser String
-> Parser
(Maybe UniqueType -> [Either String String] -> PSUniqueDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"name" Parser (Maybe UniqueType -> [Either String String] -> PSUniqueDef)
-> Parser (Maybe UniqueType)
-> Parser ([Either String String] -> PSUniqueDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe UniqueType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"type" Parser ([Either String String] -> PSUniqueDef)
-> Parser [Either String String] -> Parser PSUniqueDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Either String String] -> Parser [Either String String]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Either String String]
fields'
instance FromJSON UniqueType where
parseJSON :: Value -> Parser UniqueType
parseJSON Value
o = do
String
x <- Value -> Parser String
forall a. FromJSON a => Value -> Parser a
parseJSON Value
o
let vals :: [(String, UniqueType)]
vals = [(String
"constraint", UniqueType
UniqueConstraint), (String
"index", UniqueType
UniqueIndex), (String
"primary", Bool -> UniqueType
UniquePrimary Bool
False)]
case String -> [(String, UniqueType)] -> Maybe UniqueType
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
x [(String, UniqueType)]
vals of
Just UniqueType
a -> UniqueType -> Parser UniqueType
forall (f :: * -> *) a. Applicative f => a -> f a
pure UniqueType
a
Maybe UniqueType
Nothing -> String -> Parser UniqueType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser UniqueType) -> String -> Parser UniqueType
forall a b. (a -> b) -> a -> b
$ String
"parseJSON: UniqueType expected " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall a. Show a => a -> String
show (((String, UniqueType) -> String)
-> [(String, UniqueType)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, UniqueType) -> String
forall a b. (a, b) -> a
fst [(String, UniqueType)]
vals) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
x
instance FromJSON ReferenceActionType where
parseJSON :: Value -> Parser ReferenceActionType
parseJSON Value
o = do
String
x <- Value -> Parser String
forall a. FromJSON a => Value -> Parser a
parseJSON Value
o
let vals :: [(String, ReferenceActionType)]
vals = [(String
"no action", ReferenceActionType
NoAction), (String
"restrict", ReferenceActionType
Restrict), (String
"cascade", ReferenceActionType
Cascade), (String
"set null", ReferenceActionType
SetNull), (String
"set default", ReferenceActionType
SetDefault)]
case String
-> [(String, ReferenceActionType)] -> Maybe ReferenceActionType
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
x [(String, ReferenceActionType)]
vals of
Just ReferenceActionType
a -> ReferenceActionType -> Parser ReferenceActionType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReferenceActionType
a
Maybe ReferenceActionType
Nothing -> String -> Parser ReferenceActionType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ReferenceActionType)
-> String -> Parser ReferenceActionType
forall a b. (a -> b) -> a -> b
$ String
"parseJSON: UniqueType expected " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall a. Show a => a -> String
show (((String, ReferenceActionType) -> String)
-> [(String, ReferenceActionType)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, ReferenceActionType) -> String
forall a b. (a, b) -> a
fst [(String, ReferenceActionType)]
vals) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
x
instance FromJSON (PSFieldDef String) where
parseJSON :: Value -> Parser (PSFieldDef String)
parseJSON = String
-> (Object -> Parser (PSFieldDef String))
-> Value
-> Parser (PSFieldDef String)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"field" ((Object -> Parser (PSFieldDef String))
-> Value -> Parser (PSFieldDef String))
-> (Object -> Parser (PSFieldDef String))
-> Value
-> Parser (PSFieldDef String)
forall a b. (a -> b) -> a -> b
$ \Object
v ->
String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String
forall str.
str
-> Maybe str
-> Maybe str
-> Maybe str
-> Maybe [PSFieldDef str]
-> Maybe str
-> Maybe
(Maybe ((Maybe str, str), [str]), Maybe ReferenceActionType,
Maybe ReferenceActionType)
-> Maybe str
-> PSFieldDef str
PSFieldDef (String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser String
-> Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"name" Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"type" Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser (Maybe String)
-> Parser
(Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"exprName" Parser
(Maybe [PSFieldDef String]
-> Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser (Maybe [PSFieldDef String])
-> Parser
(Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSFieldDef String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"embeddedType" Parser
(Maybe String
-> Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String
-> PSFieldDef String)
-> Parser (Maybe String)
-> Parser
(Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String -> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"default" Parser
(Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe String -> PSFieldDef String)
-> Parser
(Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType))
-> Parser (Maybe String -> PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
-> Parser
(Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType))
forall a a a a a.
(FromJSON a, FromJSON a, FromJSON a, FromJSON a, FromJSON a) =>
Object
-> Parser (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
mkRefSettings Object
v Parser (Maybe String -> PSFieldDef String)
-> Parser (Maybe String) -> Parser (PSFieldDef String)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"converter"
where
mkRefSettings :: Object
-> Parser (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
mkRefSettings Object
v = do
Maybe Value
ref <- Object
v Object -> Text -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"reference"
(Maybe ((Maybe a, a), a)
parent, Maybe a
onDel, Maybe a
onUpd) <- case Maybe Value
ref of
Just (Object Object
r) -> (,,) (Maybe ((Maybe a, a), a)
-> Maybe a
-> Maybe a
-> (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
-> Parser (Maybe ((Maybe a, a), a))
-> Parser
(Maybe a -> Maybe a -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ((Maybe a, a), a) -> Parser (Maybe ((Maybe a, a), a))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ((Maybe a, a), a)
parentRef Parser
(Maybe a -> Maybe a -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
-> Parser (Maybe a)
-> Parser (Maybe a -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
r Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"onDelete" Parser (Maybe a -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
-> Parser (Maybe a)
-> Parser (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
r Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"onUpdate"
where
parentRef :: Parser ((Maybe a, a), a)
parentRef = (,) ((Maybe a, a) -> a -> ((Maybe a, a), a))
-> Parser (Maybe a, a) -> Parser (a -> ((Maybe a, a), a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (Maybe a -> a -> (Maybe a, a))
-> Parser (Maybe a) -> Parser (a -> (Maybe a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
r Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"schema" Parser (a -> (Maybe a, a)) -> Parser a -> Parser (Maybe a, a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
r Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"table") Parser (a -> ((Maybe a, a), a))
-> Parser a -> Parser ((Maybe a, a), a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
r Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"columns"
Maybe Value
_ -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
-> Parser (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ((Maybe a, a), a)
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing)
(Maybe a
onDel', Maybe a
onUpd') <- (,) (Maybe a -> Maybe a -> (Maybe a, Maybe a))
-> Parser (Maybe a) -> Parser (Maybe a -> (Maybe a, Maybe a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"onDelete" Parser (Maybe a -> (Maybe a, Maybe a))
-> Parser (Maybe a) -> Parser (Maybe a, Maybe a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"onUpdate"
Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
-> Parser (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
-> Parser (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)))
-> Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
-> Parser (Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a))
forall a b. (a -> b) -> a -> b
$ case (Maybe ((Maybe a, a), a)
parent, Maybe a
onDel Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a
onDel', Maybe a
onUpd Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a
onUpd') of
(Maybe ((Maybe a, a), a)
Nothing, Maybe a
Nothing, Maybe a
Nothing) -> Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
forall a. Maybe a
Nothing
(Maybe ((Maybe a, a), a), Maybe a, Maybe a)
refSettings -> (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
-> Maybe (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
forall a. a -> Maybe a
Just (Maybe ((Maybe a, a), a), Maybe a, Maybe a)
refSettings
instance FromJSON PSUniqueKeyDef where
parseJSON :: Value -> Parser PSUniqueKeyDef
parseJSON = String
-> (Object -> Parser PSUniqueKeyDef)
-> Value
-> Parser PSUniqueKeyDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"unique key" ((Object -> Parser PSUniqueKeyDef)
-> Value -> Parser PSUniqueKeyDef)
-> (Object -> Parser PSUniqueKeyDef)
-> Value
-> Parser PSUniqueKeyDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef
PSUniqueKeyDef (String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
-> Parser String
-> Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"name" Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"keyPhantom" Parser
(Maybe String
-> Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"constrName" Parser
(Maybe String
-> Maybe [PSFieldDef String]
-> Maybe Bool
-> Maybe Bool
-> PSUniqueKeyDef)
-> Parser (Maybe String)
-> Parser
(Maybe [PSFieldDef String]
-> Maybe Bool -> Maybe Bool -> PSUniqueKeyDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"dbName" Parser
(Maybe [PSFieldDef String]
-> Maybe Bool -> Maybe Bool -> PSUniqueKeyDef)
-> Parser (Maybe [PSFieldDef String])
-> Parser (Maybe Bool -> Maybe Bool -> PSUniqueKeyDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe [PSFieldDef String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"fields" Parser (Maybe Bool -> Maybe Bool -> PSUniqueKeyDef)
-> Parser (Maybe Bool) -> Parser (Maybe Bool -> PSUniqueKeyDef)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"mkEmbedded" Parser (Maybe Bool -> PSUniqueKeyDef)
-> Parser (Maybe Bool) -> Parser PSUniqueKeyDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"default"
instance FromJSON PSAutoKeyDef where
parseJSON :: Value -> Parser PSAutoKeyDef
parseJSON = String
-> (Object -> Parser PSAutoKeyDef) -> Value -> Parser PSAutoKeyDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"autogenerated key" ((Object -> Parser PSAutoKeyDef) -> Value -> Parser PSAutoKeyDef)
-> (Object -> Parser PSAutoKeyDef) -> Value -> Parser PSAutoKeyDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Maybe String -> Maybe Bool -> PSAutoKeyDef
PSAutoKeyDef (Maybe String -> Maybe Bool -> PSAutoKeyDef)
-> Parser (Maybe String) -> Parser (Maybe Bool -> PSAutoKeyDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser (Maybe String)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"constrName" Parser (Maybe Bool -> PSAutoKeyDef)
-> Parser (Maybe Bool) -> Parser PSAutoKeyDef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"default"
(.=?) :: ToJSON a => Text -> Maybe a -> Maybe Pair
Text
name .=? :: Text -> Maybe a -> Maybe Pair
.=? Maybe a
value = (Text
name Text -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.=) (a -> Pair) -> Maybe a -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
value
(.=:) :: ToJSON a => Text -> Maybe [a] -> Maybe Pair
Text
name .=: :: Text -> Maybe [a] -> Maybe Pair
.=: Maybe [a]
value = case Maybe [a]
value of
Just (a
_ : [a]
_) -> Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
name Text -> Maybe [a] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Maybe [a]
value
Maybe [a]
_ -> Maybe Pair
forall a. Maybe a
Nothing
instance ToJSON PSEntityDef where
toJSON :: PSEntityDef -> Value
toJSON PSEntityDef {String
Maybe String
Maybe [PSUniqueKeyDef]
Maybe [PSConstructorDef]
Maybe (Maybe PSAutoKeyDef)
psConstructors :: Maybe [PSConstructorDef]
psUniqueKeys :: Maybe [PSUniqueKeyDef]
psAutoKey :: Maybe (Maybe PSAutoKeyDef)
psEntitySchema :: Maybe String
psDbEntityName :: Maybe String
psDataName :: String
psConstructors :: PSEntityDef -> Maybe [PSConstructorDef]
psUniqueKeys :: PSEntityDef -> Maybe [PSUniqueKeyDef]
psAutoKey :: PSEntityDef -> Maybe (Maybe PSAutoKeyDef)
psEntitySchema :: PSEntityDef -> Maybe String
psDbEntityName :: PSEntityDef -> Maybe String
psDataName :: PSEntityDef -> String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"entity" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
psDataName, Text
"dbName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDbEntityName, Text
"schema" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psEntitySchema, Text
"autoKey" Text -> Maybe (Maybe PSAutoKeyDef) -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe (Maybe PSAutoKeyDef)
psAutoKey, Text
"keys" Text -> Maybe [PSUniqueKeyDef] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSUniqueKeyDef]
psUniqueKeys, Text
"constructors" Text -> Maybe [PSConstructorDef] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSConstructorDef]
psConstructors]
instance ToJSON PSConstructorDef where
toJSON :: PSConstructorDef -> Value
toJSON PSConstructorDef {String
Maybe String
Maybe [PSFieldDef String]
Maybe [PSUniqueDef]
psConstrUniques :: Maybe [PSUniqueDef]
psConstrFields :: Maybe [PSFieldDef String]
psDbAutoKeyName :: Maybe String
psDbConstrName :: Maybe String
psPhantomConstrName :: Maybe String
psConstrName :: String
psConstrUniques :: PSConstructorDef -> Maybe [PSUniqueDef]
psConstrFields :: PSConstructorDef -> Maybe [PSFieldDef String]
psDbAutoKeyName :: PSConstructorDef -> Maybe String
psDbConstrName :: PSConstructorDef -> Maybe String
psPhantomConstrName :: PSConstructorDef -> Maybe String
psConstrName :: PSConstructorDef -> String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"name" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
psConstrName, Text
"phantomName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psPhantomConstrName, Text
"dbName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDbConstrName, Text
"keyDbName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDbAutoKeyName, Text
"fields" Text -> Maybe [PSFieldDef String] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSFieldDef String]
psConstrFields, Text
"uniques" Text -> Maybe [PSUniqueDef] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSUniqueDef]
psConstrUniques]
instance ToJSON PSUniqueDef where
toJSON :: PSUniqueDef -> Value
toJSON PSUniqueDef {String
[Either String String]
Maybe UniqueType
psUniqueFields :: [Either String String]
psUniqueType :: Maybe UniqueType
psUniqueName :: String
psUniqueFields :: PSUniqueDef -> [Either String String]
psUniqueType :: PSUniqueDef -> Maybe UniqueType
psUniqueName :: PSUniqueDef -> String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"name" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
psUniqueName, Text
"type" Text -> Maybe UniqueType -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe UniqueType
psUniqueType, Text
"fields" Text -> Maybe [Value] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe [Value]
fields]
where
fields :: Maybe [Value]
fields =
if [Either String String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Either String String]
psUniqueFields
then Maybe [Value]
forall a. Maybe a
Nothing
else [Value] -> Maybe [Value]
forall a. a -> Maybe a
Just ([Value] -> Maybe [Value]) -> [Value] -> Maybe [Value]
forall a b. (a -> b) -> a -> b
$ (Either String String -> Value)
-> [Either String String] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map ((String -> Value)
-> (String -> Value) -> Either String String -> Value
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Value
forall a. ToJSON a => a -> Value
toJSON (\String
x -> [Pair] -> Value
object [Text
"expr" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
x])) [Either String String]
psUniqueFields
instance ToJSON UniqueType where
toJSON :: UniqueType -> Value
toJSON UniqueType
a = String -> Value
forall a. ToJSON a => a -> Value
toJSON (String -> Value) -> String -> Value
forall a b. (a -> b) -> a -> b
$ case UniqueType
a of
UniqueType
UniqueConstraint -> String
"constraint" :: String
UniqueType
UniqueIndex -> String
"index"
UniquePrimary Bool
_ -> String
"primary"
instance ToJSON ReferenceActionType where
toJSON :: ReferenceActionType -> Value
toJSON ReferenceActionType
a = String -> Value
forall a. ToJSON a => a -> Value
toJSON (String -> Value) -> String -> Value
forall a b. (a -> b) -> a -> b
$ case ReferenceActionType
a of
ReferenceActionType
NoAction -> String
"no action" :: String
ReferenceActionType
Restrict -> String
"restrict"
ReferenceActionType
Cascade -> String
"cascade"
ReferenceActionType
SetNull -> String
"set null"
ReferenceActionType
SetDefault -> String
"set default"
instance ToJSON (PSFieldDef String) where
toJSON :: PSFieldDef String -> Value
toJSON PSFieldDef {String
Maybe String
Maybe [PSFieldDef String]
Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
psFieldName :: forall str. PSFieldDef str -> str
psDbFieldName :: forall str. PSFieldDef str -> Maybe str
psDbTypeName :: forall str. PSFieldDef str -> Maybe str
psExprName :: forall str. PSFieldDef str -> Maybe str
psEmbeddedDef :: forall str. PSFieldDef str -> Maybe [PSFieldDef str]
psDefaultValue :: forall str. PSFieldDef str -> Maybe str
psReferenceParent :: forall str.
PSFieldDef str
-> Maybe
(Maybe ((Maybe str, str), [str]), Maybe ReferenceActionType,
Maybe ReferenceActionType)
psFieldConverter :: forall str. PSFieldDef str -> Maybe str
psFieldConverter :: Maybe String
psReferenceParent :: Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
psDefaultValue :: Maybe String
psEmbeddedDef :: Maybe [PSFieldDef String]
psExprName :: Maybe String
psDbTypeName :: Maybe String
psDbFieldName :: Maybe String
psFieldName :: String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"name" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
psFieldName, Text
"dbName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDbFieldName, Text
"type" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDbTypeName, Text
"exprName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psExprName, Text
"embeddedType" Text -> Maybe [PSFieldDef String] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSFieldDef String]
psEmbeddedDef, Text
"default" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psDefaultValue, Text
"reference" Text -> Maybe Value -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? (Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
psReferenceParent Maybe
(Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> ((Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe Value)
-> Maybe Value
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe ((Maybe String, String), [String]),
Maybe ReferenceActionType, Maybe ReferenceActionType)
-> Maybe Value
forall a v v a a.
(ToJSON a, ToJSON v, ToJSON v, ToJSON a, ToJSON a) =>
(Maybe ((Maybe a, v), v), Maybe a, Maybe a) -> Maybe Value
mkRefSettings)]
where
mkRefSettings :: (Maybe ((Maybe a, v), v), Maybe a, Maybe a) -> Maybe Value
mkRefSettings (Maybe ((Maybe a, v), v)
parent, Maybe a
onDel, Maybe a
onUpd) = if [Pair] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Pair]
fields then Maybe Value
forall a. Maybe a
Nothing else Value -> Maybe Value
forall a. a -> Maybe a
Just (Value -> Maybe Value) -> Value -> Maybe Value
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Pair]
fields
where
fields :: [Pair]
fields = [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Pair] -> [Pair]) -> [Maybe Pair] -> [Pair]
forall a b. (a -> b) -> a -> b
$ [Maybe Pair]
parent' [Maybe Pair] -> [Maybe Pair] -> [Maybe Pair]
forall a. [a] -> [a] -> [a]
++ [Text
"onDelete" Text -> Maybe a -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe a
onDel, Text
"onUpdate" Text -> Maybe a -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe a
onUpd]
parent' :: [Maybe Pair]
parent' = case Maybe ((Maybe a, v), v)
parent of
Maybe ((Maybe a, v), v)
Nothing -> []
Just ((schema, table), columns) -> [Text
"schema" Text -> Maybe a -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe a
schema, Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"table" Text -> v -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= v
table, Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"columns" Text -> v -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= v
columns]
instance ToJSON PSUniqueKeyDef where
toJSON :: PSUniqueKeyDef -> Value
toJSON PSUniqueKeyDef {String
Maybe Bool
Maybe String
Maybe [PSFieldDef String]
psUniqueKeyIsDef :: Maybe Bool
psUniqueKeyMakeEmbedded :: Maybe Bool
psUniqueKeyFields :: Maybe [PSFieldDef String]
psUniqueKeyDbName :: Maybe String
psUniqueKeyConstrName :: Maybe String
psUniqueKeyPhantomName :: Maybe String
psUniqueKeyName :: String
psUniqueKeyIsDef :: PSUniqueKeyDef -> Maybe Bool
psUniqueKeyMakeEmbedded :: PSUniqueKeyDef -> Maybe Bool
psUniqueKeyFields :: PSUniqueKeyDef -> Maybe [PSFieldDef String]
psUniqueKeyDbName :: PSUniqueKeyDef -> Maybe String
psUniqueKeyConstrName :: PSUniqueKeyDef -> Maybe String
psUniqueKeyPhantomName :: PSUniqueKeyDef -> Maybe String
psUniqueKeyName :: PSUniqueKeyDef -> String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Text
"name" Text -> String -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= String
psUniqueKeyName, Text
"keyPhantom" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psUniqueKeyPhantomName, Text
"constrName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psUniqueKeyConstrName, Text
"dbName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psUniqueKeyDbName, Text
"mkEmbedded" Text -> Maybe Bool -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe Bool
psUniqueKeyMakeEmbedded, Text
"default" Text -> Maybe Bool -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe Bool
psUniqueKeyIsDef, Text
"fields" Text -> Maybe [PSFieldDef String] -> Maybe Pair
forall a. ToJSON a => Text -> Maybe [a] -> Maybe Pair
.=: Maybe [PSFieldDef String]
psUniqueKeyFields]
instance ToJSON PSAutoKeyDef where
toJSON :: PSAutoKeyDef -> Value
toJSON PSAutoKeyDef {Maybe Bool
Maybe String
psAutoKeyIsDef :: Maybe Bool
psAutoKeyConstrName :: Maybe String
psAutoKeyIsDef :: PSAutoKeyDef -> Maybe Bool
psAutoKeyConstrName :: PSAutoKeyDef -> Maybe String
..} = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Text
"constrName" Text -> Maybe String -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe String
psAutoKeyConstrName, Text
"default" Text -> Maybe Bool -> Maybe Pair
forall a. ToJSON a => Text -> Maybe a -> Maybe Pair
.=? Maybe Bool
psAutoKeyIsDef]