postgresql-simple-interpolate-0.1.1.0: Interpolated SQL queries via quasiquotation
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Simple.SqlQQ.Interpolated

Description

Interpolated SQL queries

Synopsis

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 ?", [Escape "elliot", Plain "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 which also "minifies" the query at compile time by stripping whitespace and comments. However, there are a few "gotchas" to be aware of so please refer to the documentation of that function for a full specification.

This quasiquoter only works in expression contexts and will throw an error at compile time if used in any other context.

quoteInterpolatedSql :: String -> Q Exp Source #

The internal parser used by isql.

iquery :: QuasiQuoter Source #

Invokes query with arguments provided by isql

iexecute :: QuasiQuoter Source #

Invokes execute with arguments provided by isql

iexecute_ :: QuasiQuoter Source #

Invokes execute_ with arguments provided by isql