Copyright | 2013 Kei Hibino |
---|---|
License | BSD3 |
Maintainer | ex8k.hibino@gmail.com |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
This module provides typed Query
running sequence
which intermediate structures are typed.
Synopsis
- type PreparedQuery p a = PreparedStatement p a
- prepare :: IConnection conn => conn -> Query p a -> IO (PreparedQuery p a)
- prepareQuery :: IConnection conn => conn -> Query p a -> IO (PreparedQuery p a)
- withPrepareQuery :: IConnection conn => conn -> Query p a -> (PreparedQuery p a -> IO b) -> IO b
- fetch :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a)
- fetchAll' :: FromSql SqlValue a => ExecutedStatement a -> IO [a]
- listToUnique :: [a] -> IO (Maybe a)
- fetchUnique :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a)
- fetchUnique' :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a)
- runStatement' :: FromSql SqlValue a => BoundStatement a -> IO [a]
- runPreparedQuery' :: (ToSql SqlValue p, FromSql SqlValue a) => PreparedQuery p a -> p -> IO [a]
- runQuery' :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a]
- foldlFetch :: FromSql SqlValue a => (b -> a -> IO b) -> b -> ExecutedStatement a -> IO b
- forFetch :: FromSql SqlValue a => ExecutedStatement a -> (a -> IO b) -> IO [b]
- fetchAll :: FromSql SqlValue a => ExecutedStatement a -> IO [a]
- runStatement :: FromSql SqlValue a => BoundStatement a -> IO [a]
- runPreparedQuery :: (ToSql SqlValue p, FromSql SqlValue a) => PreparedQuery p a -> p -> IO [a]
- runQuery :: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) => conn -> Query p a -> p -> IO [a]
Prepare
type PreparedQuery p a = PreparedStatement p a Source #
Typed prepared query type.
:: IConnection conn | |
=> conn | Database connection |
-> Query p a | Typed query |
-> IO (PreparedQuery p a) | Result typed prepared query with parameter type |
Typed prepare query operation.
:: IConnection conn | |
=> conn | Database connection |
-> Query p a | Typed query |
-> IO (PreparedQuery p a) | Result typed prepared query with parameter type |
Same as prepare
.
:: IConnection conn | |
=> conn | Database connection |
-> Query p a | Typed query |
-> (PreparedQuery p a -> IO b) | Body action to use prepared statement |
-> IO b | Result action |
Bracketed prepare operation. PreparedStatement is released on closing connection, so connection pooling cases often cause resource leaks.
Fetch strictly
fetchAll' :: FromSql SqlValue a => ExecutedStatement a -> IO [a] Source #
Strictly fetch all records.
listToUnique :: [a] -> IO (Maybe a) Source #
Fetch expecting result records is unique.
fetchUnique :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a) Source #
Fetch all records but get only first record. Expecting result records is unique.
fetchUnique' :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a) Source #
Fetch all records but get only first record. Expecting result records is unique. Error when records count is more than one.
runStatement' :: FromSql SqlValue a => BoundStatement a -> IO [a] Source #
Execute a parameter-bounded statement and strictly fetch all records.
:: (ToSql SqlValue p, FromSql SqlValue a) | |
=> PreparedQuery p a | Statement to bind to |
-> p | Parameter type |
-> IO [a] | Action to get records |
Bind parameters, execute statement and strictly fetch all records.
:: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) | |
=> conn | Database connection |
-> Query p a | Query to get record type |
-> p | Parameter type |
-> IO [a] | Action to get records |
Prepare SQL, bind parameters, execute statement and strictly fetch all records.
Fetch loop
:: FromSql SqlValue a | |
=> (b -> a -> IO b) | action executed after each fetch |
-> b | zero element of result |
-> ExecutedStatement a | statement to fetch from |
-> IO b |
Fetch fold-left loop convenient for the sequence of cursor-solid lock actions. Each action is executed after each fetch.
:: FromSql SqlValue a | |
=> ExecutedStatement a | statement to fetch from |
-> (a -> IO b) | action executed after each fetch |
-> IO [b] |
Fetch loop convenient for the sequence of cursor-solid lock actions. Each action is executed after each fetch.
Fetch with Lazy-IO
CAUTION!!
Lazy-IO APIs may be harmful in complex transaction with RDBMs interfaces which require sequential ordered calls of low-level APIs.
fetchAll :: FromSql SqlValue a => ExecutedStatement a -> IO [a] Source #
Lazy-IO version of fetchAll'
.
runStatement :: FromSql SqlValue a => BoundStatement a -> IO [a] Source #
Lazy-IO version of runStatement'
.
:: (ToSql SqlValue p, FromSql SqlValue a) | |
=> PreparedQuery p a | Statement to bind to |
-> p | Parameter type |
-> IO [a] | Action to get records |
Lazy-IO version of runPreparedQuery'
.