Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data EntityOptions = EntityOptions {
- eoTableName :: Text -> FN
- eoColumnNames :: Text -> FN
- eoDeriveClasses :: [Name]
- eoIdType :: Name
- deriveEntity :: EntityOptions -> Name -> Q [Dec]
Documentation
data EntityOptions Source #
Options for deriving Entity
EntityOptions | |
|
Instances
deriveEntity :: EntityOptions -> Name -> Q [Dec] Source #
Derives instance for Entity
using type name and field names. Also
generates type synonim for ID. E.g. code like this:
data Agent = Agent { aName :: !Text , aAttributes :: !HStoreMap , aLongWeirdName :: !Int } deriving (Ord, Eq, Show) $(deriveEntity def { eoIdType = ''Id , eoTableName = textFN . toUnderscore' , eoColumnNames = textFN . toUnderscore' . drop 1 , eoDeriveClasses = [''Show, ''Read, ''Ord, ''Eq , ''FromField, ''ToField, ''PathPiece] } ''Agent )
Will generate code like this:
instance Database.PostgreSQL.Query.Entity Agent where newtype EntityId Agent = AgentId {getAgentId :: Id} deriving (Show, Read, Ord, Eq, FromField, ToField, PathPiece) tableName _ = "agent" fieldNames _ = ["name", "attributes", "long_weird_name"] type AgentId = EntityId Agent
So, you dont need to write it by hands any more.
NOTE: toUnderscore
is from package inflections
here