| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.SQLite.Simple.Interpolate
Description
Interpolated SQLite queries
Synopsis
- isql :: QuasiQuoter
- iquery :: QuasiQuoter
- iexecute :: QuasiQuoter
- ifold :: QuasiQuoter
- quoteInterpolatedSql :: String -> Q Exp
Documentation
isql :: QuasiQuoter Source #
Quote an 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:
>>>import Data.Char (toLower)>>>[isql|SELECT field FROM !{map toLower "PEOPLE"} WHERE name = {map toLower "ELLIOT"} AND access IN @{["admin", "employee"]} LIMIT {10 :: Int}|]("SELECT field FROM people WHERE name = ? AND access IN (?,?) LIMIT ?",[SQLText "elliot",SQLText "admin",SQLText "employee",SQLInteger 10])
The generated code is:
("SELECT field FROM people WHERE name = ? AND access IN (?,?) LIMIT ?", [toField (map toLower ELLIOT)] ++ toRow ["admin", "employee"] ++ [toField (10 :: Int)])How the parser works:
- Any expression occurring between
{and}will be replaced with a?and passed as a query parameter usingtoField. - Any expression occuring between
@{and}will be replaced with the right amount of?, separated by commas and surrounded by parentheses (e.g.(?,?,?)for aToRowinstance with 3 fields). The expression gets converted to query parameters usingtoRow. - Any expression occurring between
!{and}will be replaced with its value, bypassing the anti-injection mechanisms. Never use this one for user input!
Characters preceded by a backslash are treated literally. This enables the
inclusion of the literal character { within your quoted text by writing
it as \{. The literal sequence \{ may be written as \\{.
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)