Safe Haskell | None |
---|---|
Language | Haskell2010 |
Tools to deal with templates and statements are defined here.
Synopsis
- data Template a
- code :: Text -> Template a
- identifier :: Text -> Template a
- string :: Text -> Template a
- param :: forall b a. Param b => (a -> b) -> Template a
- paramWith :: Info (a -> Value) -> Template a
- constant :: forall b a. Param b => b -> Template a
- data Statement a = Statement {
- statement_code :: ByteString
- statement_mkParams :: a -> [PackedParam]
- statement_types :: [Oid]
- statement_name :: ByteString
- renderTemplate :: Template a -> Statement a
- data PreparedStatement a = PreparedStatement {}
- tpl :: QuasiQuoter
- stmt :: QuasiQuoter
Documentation
SQL statement template
Since: 0.0.0
Instances
Contravariant Template Source # | Since: 0.0.0 |
(HasField n r a, Param a) => IsLabel n (Template r) Source # |
#myParam === param (getField @"myParam") Use this with a database: data MyFoo = MyFoo { bar :: Int, baz :: String } myStatementTpl :: Template MyFoo myStatementTpl = "SELECT * FROM my_foo WHERE bar = " <> #bar <> " AND baz = " <> #baz Since: 0.0.0 |
Defined in PostgreSQL.Statement | |
IsString (Template a) Source # |
"my code" === code "my code" Since: 0.0.0 |
Defined in PostgreSQL.Statement fromString :: String -> Template a # | |
Semigroup (Template a) Source # | Since: 0.0.0 |
Monoid (Template a) Source # | Since: 0.0.0 |
identifier :: Text -> Template a Source #
Create a code segment that mentions the given identifier (e.g. table or column name).
Since: 0.0.0
string :: Text -> Template a Source #
Encase the given string literal in single quotes. Single quotes in the literal are automatically escaped.
Since: 0.0.0
Rendered SQL statement
Since: 0.0.0
Statement | |
|
Instances
Contravariant Statement Source # | Since: 0.0.0 |
Executable Statement Source # | Since: 0.0.0 |
Defined in PostgreSQL.Query.Class |
renderTemplate :: Template a -> Statement a Source #
Render the SQL statement.
Since: 0.0.0
data PreparedStatement a Source #
Prepared statement
Since: 0.0.0
Instances
Contravariant PreparedStatement Source # | Since: 0.0.0 |
Defined in PostgreSQL.Statement contramap :: (a -> b) -> PreparedStatement b -> PreparedStatement a # (>$) :: b -> PreparedStatement b -> PreparedStatement a # | |
Executable PreparedStatement Source # | Since: 0.0.0 |
Defined in PostgreSQL.Query.Class execute :: Query query => PreparedStatement param -> param -> query (NativeResult query) Source # |
tpl :: QuasiQuoter Source #
stmt :: QuasiQuoter Source #
Produces a Statement
expression.
[stmt| SELECT $param * 2 |]
Use $$
to render a single $
.
Parameters
Use $param
or ${param}
to reference a query parameter.
[stmt| ${x} |]
is equivalent to
.param
x
Substitutions
Use $(substr)
to embed another Template
where substr ::
.Template
a
[stmt| $(x) |]
is equivalent to x
.
Examples
data MyParams = MyParams { foo :: Int, bar :: Text } myStatement :: Statement MyParams myStatement = [stmt| SELECT baz FROM my_table WHERE foo > ${foo} AND bar = ${bar} |]
Since: 0.0.0