Skip to content

Commit

Permalink
Generalized types of the connection functions in the HSQL backends to…
Browse files Browse the repository at this point in the history
… use MonadIO.

darcs-hash:20051217235755-6cdb2-e9ca6acdfb005e9cd75425a925b590bbf54f60ad.gz
  • Loading branch information
bringert committed Dec 17, 2005
1 parent dbbfede commit 7664200
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/Database/HaskellDB/HSQL/Common.hs
Expand Up @@ -14,12 +14,14 @@
-----------------------------------------------------------

module Database.HaskellDB.HSQL.Common (
hsqlConnect
hsqlConnect, MonadIO
) where

import Data.Maybe
import Control.Exception (catch, throwIO)
import Control.Monad
import Control.Monad.Trans (MonadIO, liftIO)
import System.IO
import System.IO.Unsafe (unsafeInterleaveIO)
import System.Time

Expand All @@ -33,13 +35,13 @@ import Database.HaskellDB.FieldType
import Database.HSQL as HSQL

-- | Run an action on a HSQL Connection and close the connection.
hsqlConnect :: (opts -> IO Connection) -- ^ HSQL connection function, e.g.
-> opts -> (Database -> IO a) -> IO a
hsqlConnect :: MonadIO m => (opts -> IO Connection) -- ^ HSQL connection function
-> opts -> (Database -> m a) -> m a
hsqlConnect connect opts action =
do
conn <- handleSqlError (connect opts)
conn <- liftIO $ handleSqlError (connect opts)
x <- action (mkDatabase conn)
handleSqlError (disconnect conn)
liftIO $ handleSqlError (disconnect conn)
return x

handleSqlError :: IO a -> IO a
Expand Down
2 changes: 1 addition & 1 deletion src/Database/HaskellDB/HSQL/MySQL.hs
Expand Up @@ -30,7 +30,7 @@ data MySQLOptions = MySQLOptions {
pwd :: String -- ^ password
}

mysqlConnect :: MySQLOptions -> (Database -> IO a) -> IO a
mysqlConnect :: MonadIO m => MySQLOptions -> (Database -> m a) -> m a
mysqlConnect =
hsqlConnect (\opts -> MySQL.connect
(server opts) (db opts) (uid opts) (pwd opts))
Expand Down
2 changes: 1 addition & 1 deletion src/Database/HaskellDB/HSQL/ODBC.hs
Expand Up @@ -30,7 +30,7 @@ data ODBCOptions = ODBCOptions {
pwd :: String -- ^ password
}

odbcConnect :: ODBCOptions -> (Database -> IO a) -> IO a
odbcConnect :: MonadIO m => ODBCOptions -> (Database -> m a) -> m a
odbcConnect =
hsqlConnect (\opts -> ODBC.connect (dsn opts) (uid opts) (pwd opts))

Expand Down
2 changes: 1 addition & 1 deletion src/Database/HaskellDB/HSQL/PostgreSQL.hs
Expand Up @@ -30,7 +30,7 @@ data PostgreSQLOptions = PostgreSQLOptions {
pwd :: String -- ^ password
}

postgresqlConnect :: PostgreSQLOptions -> (Database -> IO a) -> IO a
postgresqlConnect :: MonadIO m => PostgreSQLOptions -> (Database -> m a) -> m a
postgresqlConnect =
hsqlConnect (\opts -> PostgreSQL.connect
(server opts) (db opts) (uid opts) (pwd opts))
Expand Down
2 changes: 1 addition & 1 deletion src/Database/HaskellDB/HSQL/SQLite.hs
Expand Up @@ -31,7 +31,7 @@ data SQLiteOptions = SQLiteOptions {
mode :: IOMode -- ^ access mode
}

sqliteConnect :: SQLiteOptions -> (Database -> IO a) -> IO a
sqliteConnect :: MonadIO m => SQLiteOptions -> (Database -> m a) -> m a
sqliteConnect =
hsqlConnect (\opts -> SQLite.connect
(filepath opts) (mode opts))
Expand Down

0 comments on commit 7664200

Please sign in to comment.