Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions Database/SQLite/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ module Database.SQLite.Simple (
, queryWith
, queryWith_
, queryNamed
, queryNamedWith
, lastInsertRowId
, changes
, totalChanges
-- * Queries that stream results
, fold
, foldWith
, fold_
, foldWith_
, foldNamed
, foldNamedWith
-- * Statements that do not return results
, execute
, execute_
Expand Down Expand Up @@ -379,8 +383,12 @@ queryWith_ fromRow_ conn query =
-- r \<- 'queryNamed' c \"SELECT * FROM posts WHERE id=:id AND date>=:date\" [\":id\" ':=' postId, \":date\" ':=' afterDate]
-- @
queryNamed :: (FromRow r) => Connection -> Query -> [NamedParam] -> IO [r]
queryNamed conn templ params =
withStatementNamedParams conn templ params $ \stmt -> doFoldToList fromRow stmt
queryNamed = queryNamedWith fromRow

-- | A version of 'queryNamed' that takes an explicit 'RowParser'.
queryNamedWith :: RowParser r -> Connection -> Query -> [NamedParam] -> IO [r]
queryNamedWith fromRow_ conn templ params =
withStatementNamedParams conn templ params $ \stmt -> doFoldToList fromRow_ stmt

-- | A version of 'execute' that does not perform query substitution.
execute_ :: Connection -> Query -> IO ()
Expand Down Expand Up @@ -414,9 +422,19 @@ fold :: ( FromRow row, ToRow params )
-> a
-> (a -> row -> IO a)
-> IO a
fold conn query params initalState action =
fold = foldWith fromRow

foldWith :: ( ToRow params )
=> RowParser row
-> Connection
-> Query
-> params
-> a
-> (a -> row -> IO a)
-> IO a
foldWith fromRow_ conn query params initalState action =
withStatementParams conn query params $ \stmt ->
doFold fromRow stmt initalState action
doFold fromRow_ stmt initalState action

-- | A version of 'fold' which does not perform parameter substitution.
fold_ :: ( FromRow row )
Expand All @@ -425,9 +443,18 @@ fold_ :: ( FromRow row )
-> a
-> (a -> row -> IO a)
-> IO a
fold_ conn query initalState action =
fold_ = foldWith_ fromRow

-- | A version of 'fold_' that takes an explicit 'RowParser'.
foldWith_ :: RowParser row
-> Connection
-> Query
-> a
-> (a -> row -> IO a)
-> IO a
foldWith_ fromRow_ conn query initalState action =
withStatement conn query $ \stmt ->
doFold fromRow stmt initalState action
doFold fromRow_ stmt initalState action

-- | A version of 'fold' where the query parameters (placeholders) are
-- named.
Expand All @@ -438,9 +465,19 @@ foldNamed :: ( FromRow row )
-> a
-> (a -> row -> IO a)
-> IO a
foldNamed conn query params initalState action =
foldNamed = foldNamedWith fromRow

-- | A version of 'foldNamed' that takes an explicit 'RowParser'.
foldNamedWith :: RowParser row
-> Connection
-> Query
-> [NamedParam]
-> a
-> (a -> row -> IO a)
-> IO a
foldNamedWith fromRow_ conn query params initalState action =
withStatementNamedParams conn query params $ \stmt ->
doFold fromRow stmt initalState action
doFold fromRow_ stmt initalState action

doFold :: RowParser row -> Statement -> a -> (a -> row -> IO a) -> IO a
doFold fromRow_ stmt initState action =
Expand Down