-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest-hdbc-postgresql.hs
36 lines (31 loc) · 1.3 KB
/
test-hdbc-postgresql.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Database.HaskellDB.HDBC.PostgreSQL
import Database.HDBC
import System.Console.GetOpt
import System.Environment
import System.Exit
import Control.Monad
import RunTests
data Options = Host String
| Database String
| User String
| Password String
| Help
deriving Eq
opts = [Option ['h'] ["host"] (ReqArg Host "host") "Host to connect to for testing."
, Option ['d'] ["dbname"] (ReqArg Database "database") "Name of database to use for testing."
, Option ['u'] ["user"] (ReqArg User "username") "Username to login with."
, Option ['p'] ["password"] (ReqArg Password "password") "Password to use."
, Option ['?'] ["help"] (NoArg Help) "Help text." ]
toConn (Host s) = ("host", s)
toConn (Database s) = ("dbname", s)
toConn (User s) = ("user", s)
toConn (Password s) = ("password", s)
toConn Help = ("", "")
main = do
(args, _, err) <- getArgs >>= return . getOpt RequireOrder opts
when (not . null $ err) $ do { mapM_ putStrLn err;
exitWith $ ExitFailure 1 }
when (null args || Help `elem` args) $ do { putStrLn (usageInfo "" opts);
exitWith ExitSuccess }
dbTestMain $ Conn { dbLabel = "hdbc-postgresql"
, dbConn = connect driver (map toConn args) }