Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interpolated SQL queries
Synopsis
- isql :: QuasiQuoter
- quoteInterpolatedSql :: String -> Q Exp
- iquery :: QuasiQuoter
- iexecute :: QuasiQuoter
- ifold :: QuasiQuoter
Documentation
isql :: QuasiQuoter Source #
Quote a SQL statement with embedded antiquoted expressions.
The result of the quasiquoter is a tuple, containing the statement string and a list of parameters. For example:
[isql|SELECT field FROM table WHERE name = ${map toLower ELLIOT} LIMIT ${10}|]
produces
("SELECT field FROM table WHERE name = ? LIMIT ?", [toField ((map toLower) ELLIOT), toField 10])
How the parser works:
Any expression occurring between ${
and }
will be replaced with a ?
and passed as a query parameter.
Characters preceded by a backslash are treated literally. This enables the
inclusion of the literal substring ${
within your quoted text by writing
it as \${
. The literal sequence \${
may be written as \\${
.
Note: This quasiquoter is a wrapper around sql
.
This quasiquoter only works in expression contexts and will throw an error at compile time if used in any other context.
iquery :: QuasiQuoter Source #
Invokes query
with arguments provided by isql
.
The result is of type '(Connection -> IO [r])'.
iexecute :: QuasiQuoter Source #
Invokes execute
with arguments provided by isql
The result is of type '(Connection -> IO ())'.
ifold :: QuasiQuoter Source #
Invokes fold
with arguments provided by isql
.
The result is of type 'a -> (a -> row -> IO a) -> Connection -> IO a'.