Skip to content

Commit

Permalink
Alos log queries executed using sqlQuery and sqlExec
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Nov 8, 2020
1 parent ed66663 commit 44a2b24
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}


Expand All @@ -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
Expand Down

0 comments on commit 44a2b24

Please sign in to comment.