From: Michael Orlitzky Date: Fri, 2 Jan 2015 18:25:14 +0000 (-0500) Subject: Strip leading underscores in our Groundhog codegen. X-Git-Tag: 0.2.1~30 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=af435a7787cd791b7741a3138656a58eaf98d3f1;p=dead%2Fhtsn-import.git Strip leading underscores in our Groundhog codegen. --- diff --git a/src/TSN/Codegen.hs b/src/TSN/Codegen.hs index 0e8026d..cd8e209 100644 --- a/src/TSN/Codegen.hs +++ b/src/TSN/Codegen.hs @@ -15,6 +15,10 @@ import Database.Groundhog.TH ( lowerCaseSuffixNamingStyle ) +strip_leading_underscore :: String -> String +strip_leading_underscore ('_' : rest) = rest +strip_leading_underscore s = s + -- | The lowercase naming style for database entities, provided by -- Groundhog. Makes a better starting point than the default. -- @@ -27,14 +31,23 @@ lowercase_ns = lowerCaseSuffixNamingStyle -- underscores. So, foo_bar_baz would get mapped to bar_baz in the -- database. -- --- Examples: +-- Leading underscores are ignored, as those are used to hide unused +-- field warnings. +-- +-- ==== __Examples__ -- -- >>> tsn_db_field_namer "herp" "derp" 0 "xml_player_name" 0 -- "player_name" -- +-- >>> tsn_db_field_namer "herp" "derp" 0 "db_player_name" 0 +-- "player_name" +-- +-- >>> tsn_db_field_namer "herp" "derp" 0 "_db_player_name" 0 +-- "player_name" +-- tsn_db_field_namer :: String -> String -> Int -> String -> Int -> String tsn_db_field_namer _ _ _ fieldname _ = - (join "_") . tail . (split "_") $ fieldname + (join "_") . tail . (split "_") $ strip_leading_underscore fieldname -- | An expression field name creator. \"Expression\" in the context @@ -42,14 +55,21 @@ tsn_db_field_namer _ _ _ fieldname _ = -- and update statement. We take the field name (from a record type) -- as an argument and capitalize the first letter of each word. -- --- Examples: +-- Leading underscores are ignored, as those are used to hide unused +-- field warnings. +-- +-- ==== __Examples__ -- -- >>> tsn_expr_field_namer "herp" "derp" 0 "foo_bar" 0 -- "Foo_Bar" -- +-- >>> tsn_expr_field_namer "herp" "derp" 0 "_foo_bar" 0 +-- "Foo_Bar" +-- tsn_expr_field_namer :: String -> String -> Int -> String -> Int -> String tsn_expr_field_namer _ _ _ fieldname _ = - (join "_") . (map capitalize) . (split "_") $ fieldname + (join "_") . (map capitalize) . (split "_") $ + strip_leading_underscore fieldname where capitalize [] = [] capitalize (c:cs) = (toUpper c : cs)