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
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
3537foreign import data DB :: !
3638
39+ type ConnectionString = String
40+
3741type 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.
5663execute :: forall eff a . Query a -> [SqlValue ] -> Client -> Aff (db :: DB | eff ) Unit
5764execute (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
1717import Control.Monad.Aff
1818
1919main = runAff (trace <<< show) (const $ trace " All ok" ) $ do
20+ liftEff <<< trace $ " connecting to " <> mkConnectionString connectionInfo <> " ..."
2021 exampleUsingWithConnection
2122 exampleLowLevel
2223
You can’t perform that action at this time.
0 commit comments