File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ module Database.Postgres
3
3
, Client ()
4
4
, DB ()
5
5
, ConnectionInfo ()
6
+ , ConnectionString ()
7
+ , mkConnectionString
6
8
, connect
7
9
, end
8
10
, execute , execute_
@@ -34,6 +36,8 @@ foreign import data Client :: *
34
36
35
37
foreign import data DB :: !
36
38
39
+ type ConnectionString = String
40
+
37
41
type ConnectionInfo =
38
42
{ host :: String
39
43
, db :: String
@@ -42,16 +46,19 @@ type ConnectionInfo =
42
46
, password :: String
43
47
}
44
48
45
- -- | Makes a connection to the database.
46
- connect :: forall eff . ConnectionInfo -> Aff (db :: DB | eff ) Client
47
- connect ci = connect'
48
- $ " postgres://"
49
+ mkConnectionString :: ConnectionInfo -> ConnectionString
50
+ mkConnectionString ci =
51
+ " postgres://"
49
52
<> ci.user <> " :"
50
53
<> ci.password <> " @"
51
54
<> ci.host <> " :"
52
55
<> show ci.port <> " /"
53
56
<> ci.db
54
57
58
+ -- | Makes a connection to the database.
59
+ connect :: forall eff . ConnectionInfo -> Aff (db :: DB | eff ) Client
60
+ connect = connect' <<< mkConnectionString
61
+
55
62
-- | Runs a query and returns nothing.
56
63
execute :: forall eff a . Query a -> [SqlValue ] -> Client -> Aff (db :: DB | eff ) Unit
57
64
execute (Query sql) params client = void $ runQuery sql params client
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Data.Foreign.Index
17
17
import Control.Monad.Aff
18
18
19
19
main = runAff (trace <<< show) (const $ trace " All ok" ) $ do
20
+ liftEff <<< trace $ " connecting to " <> mkConnectionString connectionInfo <> " ..."
20
21
exampleUsingWithConnection
21
22
exampleLowLevel
22
23
You can’t perform that action at this time.
0 commit comments