    -- | 'query' variants returning 'V.Vector'.
    module Database.PostgreSQL.Simple.Vector where

    import           Database.PostgreSQL.Simple (Connection, formatQuery, formatMany)
    import           Database.PostgreSQL.Simple.FromRow (FromRow(..))
    import           Database.PostgreSQL.Simple.ToRow (ToRow(..))
    import           Database.PostgreSQL.Simple.Internal (RowParser, exec)
    import           Database.PostgreSQL.Simple.Internal.PQResultUtils
    import           Database.PostgreSQL.Simple.Types ( Query (..) )

    import qualified Data.Vector as V

    -- | Perform a @SELECT@ or other SQL query that is expected to return
    -- results. All results are retrieved and converted before this
    -- function returns.
    query :: (ToRow q, FromRow r) => Connection -> Query -> q -> IO (V.Vector r)
    query :: forall q r.
    (ToRow q, FromRow r) =>
    Connection -> Query -> q -> IO (Vector r)
    query = RowParser r -> Connection -> Query -> q -> IO (Vector r)
    forall q r.
    ToRow q =>
    RowParser r -> Connection -> Query -> q -> IO (Vector r)
    queryWith RowParser r
    forall a. FromRow a => RowParser a
    fromRow

    -- | A version of 'query' that does not perform query substitution.
    query_ :: (FromRow r) => Connection -> Query -> IO (V.Vector r)
    query_ :: forall r. FromRow r => Connection -> Query -> IO (Vector r)
    query_ = RowParser r -> Connection -> Query -> IO (Vector r)
    forall r. RowParser r -> Connection -> Query -> IO (Vector r)
    queryWith_ RowParser r
    forall a. FromRow a => RowParser a
    fromRow

    -- | A version of 'query' taking parser as argument
    queryWith :: ToRow q => RowParser r -> Connection -> Query -> q -> IO (V.Vector r)
    queryWith :: forall q r.
    ToRow q =>
    RowParser r -> Connection -> Query -> q -> IO (Vector r)
    queryWith RowParser r
    parser Connection
    conn Query
    template q
    qs = do
      result <- Connection -> ByteString -> IO Result
    exec Connection
    conn (ByteString -> IO Result) -> IO ByteString -> IO Result
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Connection -> Query -> q -> IO ByteString
    forall q. ToRow q => Connection -> Query -> q -> IO ByteString
    formatQuery Connection
    conn Query
    template q
    qs
      finishQueryWithV parser conn template result

    -- | A version of 'query_' taking parser as argument
    queryWith_ :: RowParser r -> Connection -> Query -> IO (V.Vector r)
    queryWith_ :: forall r. RowParser r -> Connection -> Query -> IO (Vector r)
    queryWith_ RowParser r
    parser Connection
    conn q :: Query
    q@(Query ByteString
    que) = do
      result <- Connection -> ByteString -> IO Result
    exec Connection
    conn ByteString
    que
      finishQueryWithV parser conn q result

    -- | Execute @INSERT ... RETURNING@, @UPDATE ... RETURNING@, or other SQL
    -- query that accepts multi-row input and is expected to return results.
    returning :: (ToRow q, FromRow r) => Connection -> Query -> [q] -> IO (V.Vector r)
    returning :: forall q r.
    (ToRow q, FromRow r) =>
    Connection -> Query -> [q] -> IO (Vector r)
    returning = RowParser r -> Connection -> Query -> [q] -> IO (Vector r)
    forall q r.
    ToRow q =>
    RowParser r -> Connection -> Query -> [q] -> IO (Vector r)
    returningWith RowParser r
    forall a. FromRow a => RowParser a
    fromRow

    -- | A version of 'returning' taking parser as argument
    returningWith :: (ToRow q) => RowParser r -> Connection -> Query -> [q] -> IO (V.Vector r)
    returningWith :: forall q r.
    ToRow q =>
    RowParser r -> Connection -> Query -> [q] -> IO (Vector r)
    returningWith RowParser r
    _ Connection
    _ Query
    _ [] = Vector r -> IO (Vector r)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Vector r
    forall a. Vector a
    V.empty
    returningWith RowParser r
    parser Connection
    conn Query
    q [q]
    qs = do
      result <- Connection -> ByteString -> IO Result
    exec Connection
    conn (ByteString -> IO Result) -> IO ByteString -> IO Result
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Connection -> Query -> [q] -> IO ByteString
    forall q. ToRow q => Connection -> Query -> [q] -> IO ByteString
    formatMany Connection
    conn Query
    q [q]
    qs
      finishQueryWithV parser conn q result