From ba90b29562297f26ece0cefa97543fe5af400ef9 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sun, 6 Jan 2019 14:30:24 +0100 Subject: [PATCH] Create and expose`queryNamedWith` --- Database/SQLite/Simple.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Database/SQLite/Simple.hs b/Database/SQLite/Simple.hs index b7cce82..b455e49 100644 --- a/Database/SQLite/Simple.hs +++ b/Database/SQLite/Simple.hs @@ -67,6 +67,7 @@ module Database.SQLite.Simple ( , queryWith , queryWith_ , queryNamed + , queryNamedWith , lastInsertRowId , changes , totalChanges @@ -377,6 +378,18 @@ queryNamed :: (FromRow r) => Connection -> Query -> [NamedParam] -> IO [r] queryNamed conn templ params = withStatementNamedParams conn templ params $ \stmt -> doFoldToList fromRow stmt +-- | A version of 'query' where the query parameters (placeholders) +-- are named and take an explicit RowParser +-- +-- Example: +-- +-- @ +-- r \<- 'queryNamed' fromRow c \"SELECT * FROM posts WHERE id=:id AND date>=:date\" [\":id\" ':=' postId, \":date\" ':=' afterDate] +-- @ +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 () execute_ conn template =