Skip to content

Commit b277700

Browse files
committed
Introduce .
1 parent 65d09dd commit b277700

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Database/Postgres.purs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module Database.Postgres
33
, Client()
44
, DB()
55
, ConnectionInfo()
6+
, ConnectionString()
7+
, mkConnectionString
68
, connect
79
, end
810
, execute, execute_
@@ -34,6 +36,8 @@ foreign import data Client :: *
3436

3537
foreign import data DB :: !
3638

39+
type ConnectionString = String
40+
3741
type ConnectionInfo =
3842
{ host :: String
3943
, db :: String
@@ -42,16 +46,19 @@ type ConnectionInfo =
4246
, password :: String
4347
}
4448

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://"
4952
<> ci.user <> ":"
5053
<> ci.password <> "@"
5154
<> ci.host <> ":"
5255
<> show ci.port <> "/"
5356
<> ci.db
5457

58+
-- | Makes a connection to the database.
59+
connect :: forall eff. ConnectionInfo -> Aff (db :: DB | eff) Client
60+
connect = connect' <<< mkConnectionString
61+
5562
-- | Runs a query and returns nothing.
5663
execute :: forall eff a. Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) Unit
5764
execute (Query sql) params client = void $ runQuery sql params client

test/Main.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Data.Foreign.Index
1717
import Control.Monad.Aff
1818

1919
main = runAff (trace <<< show) (const $ trace "All ok") $ do
20+
liftEff <<< trace $ "connecting to " <> mkConnectionString connectionInfo <> "..."
2021
exampleUsingWithConnection
2122
exampleLowLevel
2223

0 commit comments

Comments
 (0)