From: Michael Orlitzky Date: Sat, 11 Jan 2014 23:43:50 +0000 (-0500) Subject: Add some more customization to our codegen config. X-Git-Tag: 0.0.1~94 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=f6a6e5d00b4fdc8c3b9467c1154fb2256ae55179;p=dead%2Fhtsn-import.git Add some more customization to our codegen config. --- diff --git a/src/TSN/Codegen.hs b/src/TSN/Codegen.hs index cd5853c..38aede4 100644 --- a/src/TSN/Codegen.hs +++ b/src/TSN/Codegen.hs @@ -4,10 +4,11 @@ module TSN.Codegen ( ) where +import Data.Char ( toLower, toUpper ) import Data.List.Utils ( join, split ) import Database.Groundhog.TH ( CodegenConfig ( namingStyle ), - NamingStyle ( mkDbFieldName ), + NamingStyle ( mkDbConstrName, mkDbFieldName, mkExprFieldName ), defaultCodegenConfig ) default_ns :: NamingStyle @@ -21,8 +22,21 @@ tsn_db_field_namer :: String -> String -> Int -> String -> Int -> String tsn_db_field_namer _ _ _ fieldname _ = (join "_") . tail . (split "_") $ fieldname +tsn_db_constr_namer :: String -> String -> Int -> String +tsn_db_constr_namer _ constrname _ = + map toLower constrname + +tsn_expr_field_namer :: String -> String -> Int -> String -> Int -> String +tsn_expr_field_namer _ _ _ fieldname _ = + (join "_") . (map capitalize) . (split "_") $ fieldname + where + capitalize [] = [] + capitalize (c:cs) = (toUpper c : cs) + tsn_naming_style :: NamingStyle -tsn_naming_style = default_ns { mkDbFieldName = tsn_db_field_namer } +tsn_naming_style = default_ns { mkDbConstrName = tsn_db_constr_namer, + mkDbFieldName = tsn_db_field_namer, + mkExprFieldName = tsn_expr_field_namer } tsn_codegen_config :: CodegenConfig tsn_codegen_config =