/
Pool.purs
58 lines (49 loc) · 1.56 KB
/
Pool.purs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Droplet.Driver.Internal.Pool (Configuration, Database, Pool, defaultConfiguration, newPool) where
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, toNullable)
import Effect (Effect)
-- | PostgreSQL connection pool.
foreign import data Pool ∷ Type
type Database = String
-- | Configuration which we actually pass to FFI.
type Configuration' =
{ user ∷ Nullable String
, password ∷ Nullable String
, host ∷ Nullable String
, port ∷ Nullable Int
, database ∷ String
, max ∷ Nullable Int
, idleTimeoutMillis ∷ Nullable Int
}
-- | PostgreSQL connection pool configuration.
type Configuration =
{ database ∷ Database
, host ∷ Maybe String
, idleTimeoutMillis ∷ Maybe Int
, max ∷ Maybe Int
, password ∷ Maybe String
, port ∷ Maybe Int
, user ∷ Maybe String
}
foreign import newPool_ ∷ Configuration' → Effect Pool
defaultConfiguration ∷ Database → Configuration
defaultConfiguration database =
{ database
, host: Nothing
, idleTimeoutMillis: Nothing
, max: Nothing
, password: Nothing
, port: Nothing
, user: Nothing
}
-- | Create a new connection pool.
newPool ∷ Configuration → Effect Pool
newPool cfg = newPool_
{ user: toNullable cfg.user
, password: toNullable cfg.password
, host: toNullable cfg.host
, port: toNullable cfg.port
, database: cfg.database
, max: toNullable cfg.max
, idleTimeoutMillis: toNullable cfg.idleTimeoutMillis
}