Skip to content

Commit 7bd5261

Browse files
Anton Gushchas9gf4ult
Anton Gushcha
authored andcommitted
Merged in NCrashed/postgresql-query (pull request #4)
Support inflections-0.3
2 parents ee81093 + 963d6dc commit 7bd5261

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: postgresql-query.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ library
8181
, haskell-src-meta
8282
, hreader >= 1.0.0 && < 2.0.0
8383
, hset >= 2.0.0 && < 3.0.0
84-
, inflections >= 0.2 && < 0.3
84+
, inflections >= 0.2 && < 0.4
8585
, monad-control == 0.3.3.1 || > 1.0.0.3
8686
, monad-logger
8787
, mtl

Diff for: src/Database/PostgreSQL/Query/TH/Entity.hs

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Prelude
77

88
import Data.Default
99
import Data.String
10+
import Data.Text (pack, unpack)
1011
import Database.PostgreSQL.Query.Entity.Class
1112
import Database.PostgreSQL.Query.TH.Common
1213
import Database.PostgreSQL.Query.Types ( FN(..) )
@@ -29,6 +30,7 @@ data EntityOptions = EntityOptions
2930
, eoIdType :: Name -- ^ Base type for Id
3031
} deriving (Generic)
3132

33+
#if !MIN_VERSION_inflections(0,3,0)
3234
instance Default EntityOptions where
3335
def = EntityOptions
3436
{ eoTableName = toUnderscore
@@ -37,6 +39,21 @@ instance Default EntityOptions where
3739
, ''FromField, ''ToField ]
3840
, eoIdType = ''Integer
3941
}
42+
#else
43+
instance Default EntityOptions where
44+
def = EntityOptions
45+
{ eoTableName = toUnderscore'
46+
, eoColumnNames = toUnderscore'
47+
, eoDeriveClasses = [ ''Ord, ''Eq, ''Show
48+
, ''FromField, ''ToField ]
49+
, eoIdType = ''Integer
50+
}
51+
52+
toUnderscore' :: String -> String
53+
toUnderscore' s = case toUnderscore $ pack s of
54+
Left er -> error $ "toUnderscore: " ++ show er
55+
Right a -> unpack a
56+
#endif
4057

4158
{- | Derives instance for 'Entity' using type name and field names. Also
4259
generates type synonim for ID. E.g. code like this:

0 commit comments

Comments
 (0)