From 44a2b24c106e4024e520681f67bf73781619e04e Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Sun, 8 Nov 2020 17:55:05 +0100 Subject: [PATCH] Alos log queries executed using sqlQuery and sqlExec --- IHP/ModelSupport.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/IHP/ModelSupport.hs b/IHP/ModelSupport.hs index da4e65b86..7250175e1 100644 --- a/IHP/ModelSupport.hs +++ b/IHP/ModelSupport.hs @@ -273,8 +273,10 @@ instance Default (PrimaryKey model) => Default (Id' model) where -- > users <- sqlQuery "SELECT id, firstname, lastname FROM users" () -- -- Take a look at "IHP.QueryBuilder" for a typesafe approach on building simple queries. -sqlQuery :: (?modelContext :: ModelContext) => (PG.ToRow q, PG.FromRow r) => Query -> q -> IO [r] -sqlQuery theQuery theParameters = withDatabaseConnection \connection -> PG.query connection theQuery theParameters +sqlQuery :: (?modelContext :: ModelContext, PG.ToRow q, PG.FromRow r, Show q) => Query -> q -> IO [r] +sqlQuery theQuery theParameters = do + logQuery theQuery theParameters + withDatabaseConnection \connection -> PG.query connection theQuery theParameters {-# INLINE sqlQuery #-} @@ -283,8 +285,10 @@ sqlQuery theQuery theParameters = withDatabaseConnection \connection -> PG.query -- __Example:__ -- -- > sqlExec "CREATE TABLE users ()" () -sqlExec :: (?modelContext :: ModelContext) => (PG.ToRow q) => Query -> q -> IO Int64 -sqlExec theQuery theParameters = withDatabaseConnection \connection -> PG.execute connection theQuery theParameters +sqlExec :: (?modelContext :: ModelContext, PG.ToRow q, Show q) => Query -> q -> IO Int64 +sqlExec theQuery theParameters = do + logQuery theQuery theParameters + withDatabaseConnection \connection -> PG.execute connection theQuery theParameters {-# INLINE sqlExec #-} withDatabaseConnection :: (?modelContext :: ModelContext) => (Connection -> IO a) -> IO a