| Copyright | (c) Eitan Chatav 2019 |
|---|---|
| Maintainer | eitan@morphism.tech |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Squeal.PostgreSQL.Session.Result
Description
Get values from a Result.
Synopsis
- data Result y where
- class Monad m => MonadResult m where
- getRow :: Row -> Result y -> m y
- getRows :: Result y -> m [y]
- firstRow :: Result y -> m (Maybe y)
- ntuples :: Result y -> m Row
- nfields :: Result y -> m Column
- cmdStatus :: Result y -> m Text
- cmdTuples :: Result y -> m (Maybe Row)
- resultStatus :: Result y -> m ExecStatus
- okResult :: Result y -> m ()
- resultErrorMessage :: Result y -> m (Maybe ByteString)
- resultErrorCode :: Result y -> m (Maybe ByteString)
- liftResult :: MonadIO io => (Result -> IO x) -> Result y -> io x
- nextRow :: MonadIO io => Row -> Result y -> Row -> io (Maybe (Row, y))
Documentation
class Monad m => MonadResult m where Source #
A MonadResult operation extracts values
from the Result of a MonadPQ operation.
There is no need to define instances of MonadResult.
An instance of MonadIO implies an instance of MonadResult.
However, the constraint MonadResult
does not imply the constraint MonadIO.
Methods
getRow :: Row -> Result y -> m y Source #
Get a row corresponding to a given row number from a Result,
throwing an exception if the row number is out of bounds.
getRows :: Result y -> m [y] Source #
Get all rows from a Result.
firstRow :: Result y -> m (Maybe y) Source #
Get the first row if possible from a Result.
ntuples :: Result y -> m Row Source #
Returns the number of rows (tuples) in the query result.
nfields :: Result y -> m Column Source #
Returns the number of columns (fields) in the query result.
cmdStatus :: Result y -> m Text Source #
Returns the command status tag from the SQL command
that generated the Result.
Commonly this is just the name of the command,
but it might include additional data such as the number of rows processed.
cmdTuples :: Result y -> m (Maybe Row) Source #
Returns the number of rows affected by the SQL command.
This function returns Just the number of
rows affected by the SQL statement that generated the Result.
This function can only be used following the execution of a
SELECT, CREATE TABLE AS, INSERT, UPDATE, DELETE, MOVE, FETCH,
or COPY statement,or an EXECUTE of a prepared query that
contains an INSERT, UPDATE, or DELETE statement.
If the command that generated the PGresult was anything else,
cmdTuples returns Nothing.
resultStatus :: Result y -> m ExecStatus Source #
Returns the result status of the command.
okResult :: Result y -> m () Source #
Check if a Result's status is either CommandOk
or TuplesOk otherwise throw a SQLException.
resultErrorMessage :: Result y -> m (Maybe ByteString) Source #
Returns the error message most recently generated by an operation on the connection.
resultErrorCode :: Result y -> m (Maybe ByteString) Source #
Returns the error code most recently generated by an operation on the connection.
https://www.postgresql.org/docs/current/static/errcodes-appendix.html
Instances
| (Monad io, MonadIO io) => MonadResult io Source # | |
Defined in Squeal.PostgreSQL.Session.Result Methods getRow :: Row -> Result y -> io y Source # getRows :: Result y -> io [y] Source # firstRow :: Result y -> io (Maybe y) Source # ntuples :: Result y -> io Row Source # nfields :: Result y -> io Column Source # cmdStatus :: Result y -> io Text Source # cmdTuples :: Result y -> io (Maybe Row) Source # resultStatus :: Result y -> io ExecStatus Source # okResult :: Result y -> io () Source # resultErrorMessage :: Result y -> io (Maybe ByteString) Source # resultErrorCode :: Result y -> io (Maybe ByteString) Source # | |
liftResult :: MonadIO io => (Result -> IO x) -> Result y -> io x Source #
Lifts actions on results from LibPQ.