{-# 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
{ iidFieldType :: EntityNameHS -> FieldType
iidFieldType = \EntityNameHS
entName ->
Maybe Text -> Text -> FieldType
FTTypeCon forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ EntityNameHS -> Text
unEntityNameHS EntityNameHS
entName 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 =
forall a. Maybe a
Nothing
, iidMaxLen :: Maybe Integer
iidMaxLen =
forall a. Maybe a
Nothing
}