From: Michael Orlitzky Date: Tue, 31 Dec 2013 21:30:59 +0000 (-0500) Subject: Add the TSN.Codegen module to help Groundhog out. X-Git-Tag: 0.0.1~135 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=ca451ca0ab76d07d08bbe95a3a08aae683b9f6ea;p=dead%2Fhtsn-import.git Add the TSN.Codegen module to help Groundhog out. --- diff --git a/src/TSN/Codegen.hs b/src/TSN/Codegen.hs new file mode 100644 index 0000000..d5d9bbd --- /dev/null +++ b/src/TSN/Codegen.hs @@ -0,0 +1,27 @@ +module TSN.Codegen ( + tsn_codegen_config ) +where + +import Data.List.Utils ( join, split ) +import Database.Groundhog.TH ( + CodegenConfig ( namingStyle ), + NamingStyle ( mkDbFieldName ), + defaultCodegenConfig ) + +default_ns :: NamingStyle +default_ns = namingStyle defaultCodegenConfig + +-- | A database field name creator. It takes the field name (from a +-- record type) and drops the first component determined by +-- underscores. So, foo_bar_baz would get mapped to bar_baz in the +-- database. +tsn_db_field_namer :: String -> String -> Int -> String -> Int -> String +tsn_db_field_namer _ _ _ fieldname _ = + (join "_") . tail . (split "_") $ fieldname + +tsn_naming_style :: NamingStyle +tsn_naming_style = default_ns { mkDbFieldName = tsn_db_field_namer } + +tsn_codegen_config :: CodegenConfig +tsn_codegen_config = + defaultCodegenConfig { namingStyle = tsn_naming_style }