|
1 | 1 | {-# LANGUAGE TemplateHaskell #-} |
2 | 2 |
|
3 | 3 | -- | Interpolated SQL queries |
4 | | -module Database.PostgreSQL.Simple.SqlQQ.Interpolated (isql, quoteInterpolatedSql) where |
| 4 | +module Database.PostgreSQL.Simple.SqlQQ.Interpolated |
| 5 | + ( isql |
| 6 | + , quoteInterpolatedSql |
| 7 | + , iquery |
| 8 | + , iexecute |
| 9 | + , iexecute_ |
| 10 | + ) where |
5 | 11 |
|
6 | 12 | import Language.Haskell.TH (Exp, Q, appE, listE, sigE, tupE, varE) |
7 | 13 | import Language.Haskell.TH.Quote (QuasiQuoter (..)) |
8 | 14 | import Database.PostgreSQL.Simple.ToField (Action, toField) |
9 | 15 | import Database.PostgreSQL.Simple.SqlQQ (sql) |
10 | 16 | import Text.Parsec (ParseError) |
| 17 | +import Database.PostgreSQL.Simple |
11 | 18 |
|
12 | 19 | import Database.PostgreSQL.Simple.SqlQQ.Interpolated.Parser (StringPart (..), parseInterpolated) |
13 | 20 |
|
@@ -66,8 +73,21 @@ quoteInterpolatedSql :: String -> Q Exp |
66 | 73 | quoteInterpolatedSql s = either (handleError s) applySql (parseInterpolated s) |
67 | 74 |
|
68 | 75 | handleError :: String -> ParseError -> Q Exp |
69 | | -handleError expStr parseError = error $ |
70 | | - "Failed to parse interpolated expression in string: " |
71 | | - ++ expStr |
72 | | - ++ "\n" |
73 | | - ++ show parseError |
| 76 | +handleError expStr parseError = error $ mconcat |
| 77 | + [ "Failed to parse interpolated expression in string: " |
| 78 | + , expStr |
| 79 | + , "\n" |
| 80 | + , show parseError |
| 81 | + ] |
| 82 | + |
| 83 | +-- | Invokes 'query' with arguments provided by 'isql' |
| 84 | +iquery :: QuasiQuoter |
| 85 | +iquery = isql { quoteExp = appE [| uncurry query |] . quoteInterpolatedSql } |
| 86 | + |
| 87 | +-- | Invokes 'execute' with arguments provided by 'isql' |
| 88 | +iexecute :: QuasiQuoter |
| 89 | +iexecute = isql { quoteExp = appE [| uncurry execute |] . quoteInterpolatedSql } |
| 90 | + |
| 91 | +-- | Invokes 'execute_' with arguments provided by 'isql' |
| 92 | +iexecute_ :: QuasiQuoter |
| 93 | +iexecute_ = isql { quoteExp = appE [| uncurry execute_ |] . quoteInterpolatedSql } |
0 commit comments