mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-12 12:09:08 +03:00
Add fetch function.
This commit is contained in:
parent
38b67662eb
commit
c803dc97b8
@ -14,7 +14,7 @@ module Database.HDBC.Record.Query (
|
||||
|
||||
ExecutedStatement, executed, result, execute,
|
||||
|
||||
fetchAll, fetchAll',
|
||||
fetch, fetchAll, fetchAll',
|
||||
listToUnique, fetchUnique, fetchUnique',
|
||||
|
||||
runStatement, runStatement',
|
||||
@ -61,13 +61,17 @@ execute bs = do
|
||||
n <- HDBC.execute stmt (params bs)
|
||||
return $ ExecutedStatement stmt n
|
||||
|
||||
fetchRecordsExplicit :: (Statement -> IO [[SqlValue]])
|
||||
fetchRecordsExplicit :: Functor f
|
||||
=> (Statement -> IO (f [SqlValue]) )
|
||||
-> RecordFromSql SqlValue a
|
||||
-> ExecutedStatement a
|
||||
-> IO [a]
|
||||
fetchRecordsExplicit fetch fromSql es = do
|
||||
rows <- fetch (executed es)
|
||||
return $ map (runToRecord fromSql) rows
|
||||
-> IO (f a)
|
||||
fetchRecordsExplicit fetchs fromSql es = do
|
||||
rows <- fetchs (executed es)
|
||||
return $ fmap (runToRecord fromSql) rows
|
||||
|
||||
fetch :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a)
|
||||
fetch = fetchRecordsExplicit HDBC.fetchRow recordFromSql
|
||||
|
||||
fetchAll :: FromSql SqlValue a => ExecutedStatement a -> IO [a]
|
||||
fetchAll = fetchRecordsExplicit HDBC.fetchAllRows recordFromSql
|
||||
|
Loading…
Reference in New Issue
Block a user