@@ -17,14 +17,18 @@ module Database.PostgreSQL.Query.TH
17
17
import Prelude
18
18
19
19
import Control.Applicative
20
+ import Control.Monad
20
21
import Data.Default
21
22
import Data.FileEmbed ( embedFile )
23
+ import Data.String
22
24
import Database.PostgreSQL.Query.Entity ( Entity (.. ) )
23
25
import Database.PostgreSQL.Query.TH.SqlExp
26
+ import Database.PostgreSQL.Query.Types ( FN (.. ) )
24
27
import Database.PostgreSQL.Simple.FromRow ( FromRow (.. ), field )
25
28
import Database.PostgreSQL.Simple.ToRow ( ToRow (.. ) )
26
29
import Database.PostgreSQL.Simple.Types ( Query (.. ) )
27
30
import Language.Haskell.TH
31
+ import Language.Haskell.TH.Syntax
28
32
29
33
-- | Return constructor name
30
34
cName :: (Monad m ) => Con -> m Name
@@ -196,12 +200,15 @@ deriveEntity opts tname = do
196
200
[(mkName unidname, NotStrict , idtype)]
197
201
iddec = NewtypeInstD [] entityIdName [ConT tname]
198
202
idcon (eoDeriveClasses opts)
199
- tblName = eoTableName opts tnames
200
- fldNames = map (eoColumnNames opts . nameBase) $ cFieldNames tcon
203
+ tblName = fromString $ eoTableName opts tnames
204
+ fldNames = map (fromString . eoColumnNames opts . nameBase)
205
+ $ cFieldNames tcon
201
206
VarE ntableName <- [e |tableName|]
202
207
VarE nfieldNames <- [e |fieldNames|]
203
- let tbldec = FunD ntableName [Clause [WildP ] (NormalB $ LitE $ stringL tblName) [] ]
204
- flddec = FunD nfieldNames [Clause [WildP ] (NormalB $ ListE $ map (LitE . stringL) fldNames) [] ]
208
+ tblExp <- lift (tblName :: FN )
209
+ fldExp <- mapM lift (fldNames :: [FN ])
210
+ let tbldec = FunD ntableName [Clause [WildP ] (NormalB tblExp) [] ]
211
+ flddec = FunD nfieldNames [Clause [WildP ] (NormalB $ ListE fldExp) [] ]
205
212
ret = InstanceD [] econt
206
213
[ iddec, tbldec, flddec ]
207
214
syndec = TySynD (mkName idname) [] (AppT (ConT entityIdName) (ConT tname))
0 commit comments