Safe Haskell | None |
---|---|
Language | Haskell98 |
- class PGQuery q a | q -> a where
- pgRunQuery :: PGConnection -> q -> IO (Int, Seq a)
- type PGSimpleQuery = QueryParser SimpleQuery
- type PGPreparedQuery = QueryParser PreparedQuery
- rawPGSimpleQuery :: String -> PGSimpleQuery PGValues
- rawPGPreparedQuery :: String -> PGValues -> PGPreparedQuery PGValues
- data QueryFlags = QueryFlags {
- flagNullable :: Bool
- flagPrepare :: Maybe [String]
- simpleFlags :: QueryFlags
- makePGQuery :: QueryFlags -> String -> ExpQ
- pgSQL :: QuasiQuoter
- pgExecute :: PGQuery q () => PGConnection -> q -> IO Int
- pgQuery :: PGQuery q a => PGConnection -> q -> IO [a]
- pgLazyQuery :: PGConnection -> PGPreparedQuery a -> Word32 -> IO [a]
Documentation
class PGQuery q a | q -> a where Source
pgRunQuery :: PGConnection -> q -> IO (Int, Seq a) Source
Execute a query and return the number of rows affected (or -1 if not known) and a list of results.
type PGSimpleQuery = QueryParser SimpleQuery Source
A simple one-shot query that simply substitutes literal representations of parameters for placeholders.
type PGPreparedQuery = QueryParser PreparedQuery Source
A prepared query that automatically is prepared in the database the first time it is run and bound with new parameters each subsequent time.
rawPGSimpleQuery :: String -> PGSimpleQuery PGValues Source
Make a simple query directly from a query string, with no type inference
rawPGPreparedQuery :: String -> PGValues -> PGPreparedQuery PGValues Source
Make a prepared query directly from a query string and bind parameters, with no type inference
data QueryFlags Source
Flags affecting how and what type of query to build with makeQuery
.
QueryFlags | |
|
simpleFlags :: QueryFlags Source
QueryFlags
for a default (simple) query.
makePGQuery :: QueryFlags -> String -> ExpQ Source
Construct a PGQuery
from a SQL string.
A quasi-quoter for PGSQL queries.
Used in expression context, it may contain any SQL statement [pgSQL|SELECT ...|]
.
The statement may contain PostgreSQL-style placeholders ($1
, $2
, ...) or in-line placeholders (${1+1}
) containing any valid Haskell expression (except {}
).
It will be replaced by a PGQuery
object that can be used to perform the SQL statement.
If there are more $N
placeholders than expressions, it will instead be a function accepting the additional parameters and returning a PGQuery
.
Note that all occurrences of $N
or ${
will be treated as placeholders, regardless of their context in the SQL (e.g., even within SQL strings or other places placeholders are disallowed by PostgreSQL), which may cause invalid SQL or other errors.
If you need to pass a literal $
through in these contexts, you may double it to escape it as $$N
or $${
.
The statement may start with one of more special flags affecting the interpretation:
?
- To disable nullability inference, treating all result values as nullable, thus returning
Maybe
values regardless of inferred nullability. $
- To create a
PGPreparedQuery
rather than aPGSimpleQuery
, by default inferring parameter types. $(type,...)
- To specify specific types to a prepared query (see http://www.postgresql.org/docs/current/static/sql-prepare.html for details).
This can also be used at the top-level to execute SQL statements at compile-time (without any parameters and ignoring results).
Here the query can only be prefixed with !
to make errors non-fatal.
pgExecute :: PGQuery q () => PGConnection -> q -> IO Int Source
Execute a query that does not return result. Return the number of rows affected (or -1 if not known).
pgQuery :: PGQuery q a => PGConnection -> q -> IO [a] Source
Run a query and return a list of row results.
:: PGConnection | |
-> PGPreparedQuery a | |
-> Word32 | Chunk size (1 is common, 0 is all-or-nothing) |
-> IO [a] |
Run a prepared query in lazy mode, where only chunk size rows are requested at a time.
If you eventually retrieve all the rows this way, it will be far less efficient than using pgQuery
, since every chunk requires an additional round-trip.
Although you may safely stop consuming rows early, currently you may not interleave any other database operation while reading rows. (This limitation could theoretically be lifted if required.)