hpgsql
Safe HaskellNone
LanguageHaskell2010

Hpgsql.Query

Contents

Synopsis

Documentation

data Query Source #

Query is some SQL with values of query arguments inside and also whether it's a prepared statement. It can be concatenated to other Query objects freely, and concatenating chains of Queries with at least one prepared statement among them makes the final Query object a prepared statement, too. You can build this with the sql and sqlPrep quasiquoters, the former for unprepared statements, and you can use preparedStatement and nonPreparedStatement to convert between them.

Instances

Instances details
Semigroup Query Source # 
Instance details

Defined in Hpgsql.InternalTypes

Methods

(<>) :: Query -> Query -> Query #

sconcat :: NonEmpty Query -> Query #

stimes :: Integral b => b -> Query -> Query #

IsString Query Source # 
Instance details

Defined in Hpgsql.InternalTypes

Methods

fromString :: String -> Query #

Show Query Source # 
Instance details

Defined in Hpgsql.InternalTypes

Methods

showsPrec :: Int -> Query -> ShowS #

show :: Query -> String #

showList :: [Query] -> ShowS #

data SingleQuery Source #

A single statement, not multiple, with dollar-numbered query arguments starting from $1.

Instances

Instances details
Show SingleQuery Source # 
Instance details

Defined in Hpgsql.InternalTypes

sqlPrep :: QuasiQuoter Source #

Just like the sql quasiquoter, but every SQL statement inside is a prepared statement.

mkQuery :: ToPgRow a => ByteString -> a -> Query Source #

Takes in a query string with query arguments as dollar-numbered arguments and returns a Query you can run. Examples: - "SELECT * FROM table WHERE col1=$1 AND col2=$2" - "SELECT * FROM table WHERE (["a", "b", "c"]'::jsonb ? b) = $1" Question marks are interpreted literally, i.e. they have no special meaning. Note that if the number of arguments does not match what's in the query string, this will throw an error.

escapeIdentifier :: ByteString -> Query Source #

Escapes a database object identifier like a table name or a column name, so it can be embedded inside a [sql|...|] quasiquote using ^{expr} syntax:

[sql| SELECT ^{escapeIdentifier "çolumñ"} FROM ^{escapeIdentifier "sChEmA"}.some_table |]

vALUES :: ToPgRow a => [a] -> Query Source #

Generates a query like VALUES ($1,$2), ($3,$4) from a list of rows. Can be embedded inside a [sql|...|] quasiquote using ^{expr} syntax:

[sql| INSERT INTO emp(id,name) ^{vALUES rows} ON CONFLICT DO NOTHING |]

preparedStatement :: Query -> Query Source #

Turns a Query into a prepared Query, i.e. every SQL statement in the Query will be a prepared statement.

nonPreparedStatement :: Query -> Query Source #

Turns a Query into a non-prepared Query, i.e. every SQL statement in the Query will not be a prepared statement.

Internal

These functions are internal implementation details and are not intended for public use. They may change or be removed without notice.

breakQueryIntoStatements :: Query -> NonEmpty SingleQuery Source #

For internal usage only. Takes a Query and breaks it up into individual SQL statements that can be sent to a postgres backend.

mkQueryInternal :: ByteString -> [[Either ByteString (EncodingContext -> (Maybe Oid, BinaryField))]] -> Query Source #

Takes in a query string with query arguments as question marks (NOT dollar-numbered arguments). Example: - "SELECT * FROM table WHERE col1=? AND col2=?" You should really use mkQuery instead of this. This is here only for hpgsql-simple-compat.