Skip to content

Commit 06dd172

Browse files
author
Jamil Maqdis Anton
committed
Add optional pooling config
1 parent 0f6a4c5 commit 06dd172

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

src/Postgres.fs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,52 @@ type PostgresConfig =
77
password: string
88
database: string }
99

10+
type PoolingConfig =
11+
{ minSize: int option
12+
maxSize: int option
13+
connectionIdleLifeTime: int option
14+
connectionPruningInterval: int option }
15+
1016
module Postgres =
17+
let private storeSettings (config: PostgresConfig): string =
18+
sprintf
19+
"Host=%s;Port=%s;User Id=%s;Password=%s;Database=%s"
20+
config.host
21+
config.port
22+
config.username
23+
config.password
24+
config.database
25+
26+
let private poolingSettings (pooling: PoolingConfig): string =
27+
let minSize = pooling.minSize |> Option.defaultValue 0
28+
29+
let maxSize =
30+
pooling.maxSize |> Option.defaultValue 100
31+
32+
let connectionPruningInterval =
33+
pooling.connectionPruningInterval
34+
|> Option.defaultValue 300
35+
36+
let connectionIdleLifeTime =
37+
pooling.connectionIdleLifeTime
38+
|> Option.defaultValue 10
39+
40+
sprintf
41+
"Minimum Pool Size=%d;Maximum Pool Size=%d;Connection Idle Lifetime=%d;Connection Pruning Interval%d"
42+
minSize
43+
maxSize
44+
connectionPruningInterval
45+
connectionIdleLifeTime
46+
47+
let private storeSettingsWithPooling (config: PostgresConfig) (pooling: PoolingConfig): string =
48+
sprintf "%s;%s" (storeSettings config) (poolingSettings pooling)
49+
1150
let createStore (config: PostgresConfig): SqlStreamStore.PostgresStreamStore =
12-
let storeSettings: string =
13-
sprintf
14-
"Host=%s;Port=%s;User Id=%s;Password=%s;Database=%s"
15-
config.host
16-
config.port
17-
config.username
18-
config.password
19-
config.database
20-
21-
new SqlStreamStore.PostgresStreamStore(SqlStreamStore.PostgresStreamStoreSettings(storeSettings))
51+
new SqlStreamStore.PostgresStreamStore(SqlStreamStore.PostgresStreamStoreSettings(storeSettings config))
52+
53+
let createStoreWithPoolingConfig (config: PostgresConfig) (pooling: PoolingConfig): SqlStreamStore.PostgresStreamStore =
54+
new SqlStreamStore.PostgresStreamStore(SqlStreamStore.PostgresStreamStoreSettings
55+
(storeSettingsWithPooling config pooling))
2256

2357
let createSchema (store: SqlStreamStore.PostgresStreamStore): Async<unit> =
2458
store.CreateSchemaIfNotExists() |> Async.AwaitTask

0 commit comments

Comments
 (0)