definition:
|
genKeyTransformFuncs :: String -> Entity -> [CFuncDecl]
genKeyTransformFuncs mName (Entity name attrs) =
case head attrs of
(Attribute "Key" _ PKey _ ) ->
[ stCmtFunc ("id-to-value function for entity `" ++ name ++ "`.")
(mName, firstLow name ++ "ID") 1 Public
(baseType (mName, name ++ "ID") ~>
applyTC ("Database.CDBI.Criteria", "Value")
[baseType (mName, name ++ "ID")])
[simpleRule [genAttrConvLeftOneTwo mName name (head attrs)]
(applyF ("Database.CDBI.Criteria", "idVal")
[cvar "key"])]
, stCmtFunc ("id-to-int function for entity `" ++ name ++ "`.")
(mName, toKeyToInt $ firstLow name) 1 Public
(baseType (mName, name ++"ID") ~> intType)
[simpleRule [genAttrConvLeftOneTwo mName name (head attrs)]
(cvar "key")]
, stCmtFunc (showKeyCmt name)
(mName, "show" ++ name ++ "Key") 1 Public
(baseType (mName, name) ~> stringType)
[simpleRule [cpvar "entry"]
(applyF (mER, "showDatabaseKey")
[ string2ac name
, constF (mName, toKeyToInt $ firstLow name)
, applyF (mName, firstLow name ++ "Key") [cvar "entry"]
])]
, stCmtFunc (readKeyCmt name)
(mName, "read" ++ name ++ "Key") 0 Public
(stringType ~> maybeType (baseType (mName, name ++ "ID")))
[simpleRule []
(applyF (mER, "readDatabaseKey")
[ string2ac name, constF (mName, name ++ "ID")])]
]
_ -> []
where
toKeyToInt s = s ++ "KeyToInt"
showKeyCmt ename =
"Shows the key of a `" ++ ename ++ "` entity as a string.\n" ++
"This is useful if a textual representation of the key is necessary\n" ++
"(e.g., as URL parameters in web pages), but it should no be used\n" ++
"to store keys in other attributes!"
readKeyCmt ename =
"Transforms a string into a key of a `" ++ ename ++ "` entity.\n" ++
"Nothing is returned if the string does not represent a meaningful key."
|