psql-0.0.0: PostgreSQL client
Safe HaskellNone
LanguageHaskell2010

PostgreSQL.Statement

Description

Tools to deal with templates and statements are defined here.

Synopsis

Documentation

data Template a Source #

SQL statement template

Since: 0.0.0

Instances

Instances details
Contravariant Template Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Methods

contramap :: (a -> b) -> Template b -> Template a #

(>$) :: b -> Template b -> Template a #

(HasField n r a, Param a) => IsLabel n (Template r) Source #

OverloadedLabels helper for param

#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

Instance details

Defined in PostgreSQL.Statement

Methods

fromLabel :: Template r #

IsString (Template a) Source #

OverloadedStrings helper for code

"my code" === code "my code"

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Methods

fromString :: String -> Template a #

Semigroup (Template a) Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Methods

(<>) :: Template a -> Template a -> Template a #

sconcat :: NonEmpty (Template a) -> Template a #

stimes :: Integral b => b -> Template a -> Template a #

Monoid (Template a) Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Methods

mempty :: Template a #

mappend :: Template a -> Template a -> Template a #

mconcat :: [Template a] -> Template a #

code :: Text -> Template a Source #

Create a code-only statement.

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

param :: forall b a. Param b => (a -> b) -> Template a Source #

Reference a parameter.

Since: 0.0.0

paramWith :: Info (a -> Value) -> Template a Source #

Reference a parameter.

Since: 0.0.0

constant :: forall b a. Param b => b -> Template a Source #

Constant part of a query.

Since: 0.0.0

data Statement a Source #

Rendered SQL statement

Since: 0.0.0

Instances

Instances details
Contravariant Statement Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Methods

contramap :: (a -> b) -> Statement b -> Statement a #

(>$) :: b -> Statement b -> Statement a #

Executable Statement Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Query.Class

Methods

execute :: Query query => Statement param -> param -> query (NativeResult query) Source #

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

Instances details
Contravariant PreparedStatement Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Statement

Executable PreparedStatement Source #

Since: 0.0.0

Instance details

Defined in PostgreSQL.Query.Class

Methods

execute :: Query query => PreparedStatement param -> param -> query (NativeResult query) Source #

tpl :: QuasiQuoter Source #

Produces a Template expression.

Supports the same features as stmt.

Since: 0.0.0

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