{-# LANGUAGE TemplateHaskellQuotes #-}
module Database.Persist.ImplicitIdDef
(
ImplicitIdDef
, mkImplicitIdDef
, autoIncrementingInteger
, setImplicitIdDefMaxLen
, unsafeClearDefaultImplicitId
) where
import Language.Haskell.TH
import Database.Persist.ImplicitIdDef.Internal
import Database.Persist.Types.Base
( FieldType(..)
, SqlType(..)
)
import Database.Persist.Class (BackendKey)
import Database.Persist.Names
autoIncrementingInteger :: ImplicitIdDef
autoIncrementingInteger :: ImplicitIdDef
autoIncrementingInteger =
ImplicitIdDef :: (EntityNameHS -> FieldType)
-> SqlType
-> (Bool -> Type -> Type)
-> Maybe Text
-> Maybe Integer
-> ImplicitIdDef
ImplicitIdDef
{ iidFieldType :: EntityNameHS -> FieldType
iidFieldType = \EntityNameHS
entName ->
Maybe Text -> Text -> FieldType
FTTypeCon Maybe Text
forall a. Maybe a
Nothing (Text -> FieldType) -> Text -> FieldType
forall a b. (a -> b) -> a -> b
$ EntityNameHS -> Text
unEntityNameHS EntityNameHS
entName Text -> Text -> Text
forall a. Monoid a => a -> a -> a
`mappend` Text
"Id"
, iidFieldSqlType :: SqlType
iidFieldSqlType =
SqlType
SqlInt64
, iidType :: Bool -> Type -> Type
iidType = \Bool
isMpsGeneric Type
mpsBackendType ->
Name -> Type
ConT ''BackendKey Type -> Type -> Type
`AppT`
if Bool
isMpsGeneric
then Name -> Type
VarT (String -> Name
mkName String
"backend")
else Type
mpsBackendType
, iidDefault :: Maybe Text
iidDefault =
Maybe Text
forall a. Maybe a
Nothing
, iidMaxLen :: Maybe Integer
iidMaxLen =
Maybe Integer
forall a. Maybe a
Nothing
}